爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
4.6 KiB

1 week ago
5 days ago
1 week ago
1 week ago
1 week ago
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar">
  5. <view class="back" @tap="goBack">
  6. <uni-icons type="left" size="20"></uni-icons>
  7. </view>
  8. <text class="title">修改地址</text>
  9. </view>
  10. <!-- 表单内容 -->
  11. <view class="form-content">
  12. <!-- 寄件人信息卡片 -->
  13. <view class="form-card">
  14. <view class="card-title">寄件人信息</view>
  15. <view class="form-item">
  16. <text class="label">寄件人姓名</text>
  17. <input
  18. class="input"
  19. type="text"
  20. v-model="formData.name"
  21. placeholder="请输入姓名"
  22. />
  23. </view>
  24. <view class="form-item">
  25. <text class="label">寄件人电话</text>
  26. <input
  27. class="input"
  28. type="number"
  29. v-model="formData.phone"
  30. placeholder="请输入手机号"
  31. />
  32. </view>
  33. </view>
  34. <!-- 寄件人地址卡片 -->
  35. <view class="form-card">
  36. <view class="card-title">寄件地址</view>
  37. <view class="form-item">
  38. <text class="label">寄件地址</text>
  39. <input
  40. class="input"
  41. type="text"
  42. v-model="formData.address"
  43. placeholder="请输入详细地址"
  44. />
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 底部确认按钮 -->
  49. <view class="bottom-btn" @tap="confirmEdit">确认</view>
  50. </view>
  51. </template>
  52. <script>
  53. import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'
  54. export default {
  55. mixins: [pullRefreshMixin],
  56. data() {
  57. return {
  58. formData: {
  59. name: '',
  60. phone: '',
  61. address: ''
  62. }
  63. }
  64. },
  65. onLoad(options) {
  66. // 如果是编辑模式,填充表单数据
  67. if (options.mode === 'edit') {
  68. this.formData = {
  69. name: decodeURIComponent(options.name || ''),
  70. phone: options.phone || '',
  71. address: decodeURIComponent(options.address || '')
  72. }
  73. }
  74. },
  75. methods: {
  76. async onRefresh() {
  77. // 模拟刷新数据
  78. await new Promise(resolve => setTimeout(resolve, 1000))
  79. this.stopPullRefresh()
  80. },
  81. goBack() {
  82. uni.navigateBack()
  83. },
  84. confirmEdit() {
  85. // 表单验证
  86. if (!this.formData.name.trim()) {
  87. return uni.showToast({
  88. title: '请输入姓名',
  89. icon: 'none'
  90. })
  91. }
  92. if (!/^1\d{10}$/.test(this.formData.phone)) {
  93. return uni.showToast({
  94. title: '请输入正确的手机号',
  95. icon: 'none'
  96. })
  97. }
  98. if (!this.formData.address.trim()) {
  99. return uni.showToast({
  100. title: '请输入地址',
  101. icon: 'none'
  102. })
  103. }
  104. // 获取上一页实例并更新数据
  105. const pages = getCurrentPages()
  106. const prevPage = pages[pages.length - 2]
  107. if (prevPage) {
  108. // 更新地址列表中的对应项
  109. const addressList = prevPage.$vm.addressList
  110. const index = addressList.findIndex(item =>
  111. item.phone === this.formData.phone &&
  112. item.address === this.formData.address
  113. )
  114. if (index > -1) {
  115. addressList[index] = { ...this.formData }
  116. }
  117. }
  118. uni.navigateBack()
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .container {
  125. min-height: 100vh;
  126. background: #f5f5f5;
  127. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  128. }
  129. .nav-bar {
  130. display: flex;
  131. align-items: center;
  132. height: 88rpx;
  133. background: #fff;
  134. padding: 0 30rpx;
  135. .back {
  136. padding: 20rpx;
  137. margin-left: -20rpx;
  138. }
  139. .title {
  140. flex: 1;
  141. text-align: center;
  142. font-size: 34rpx;
  143. font-weight: 500;
  144. }
  145. .right-btns {
  146. display: flex;
  147. align-items: center;
  148. gap: 30rpx;
  149. .more, .target {
  150. font-size: 40rpx;
  151. color: #333;
  152. }
  153. }
  154. }
  155. .form-content {
  156. padding: 20rpx;
  157. }
  158. .form-card {
  159. background: #fff;
  160. border-radius: 20rpx;
  161. margin-bottom: 20rpx;
  162. overflow: hidden;
  163. .card-title {
  164. font-size: 32rpx;
  165. font-weight: bold;
  166. color: #333;
  167. padding: 30rpx;
  168. }
  169. .form-item {
  170. padding: 20rpx 30rpx;
  171. border-top: 1rpx solid #f5f5f5;
  172. .label {
  173. font-size: 28rpx;
  174. color: #333;
  175. margin-bottom: 20rpx;
  176. display: block;
  177. }
  178. .input {
  179. font-size: 28rpx;
  180. color: #333;
  181. width: 100%;
  182. }
  183. }
  184. }
  185. .bottom-btn {
  186. position: fixed;
  187. bottom: 0;
  188. left: 0;
  189. right: 0;
  190. height: 100rpx;
  191. background: #FFB74D;
  192. color: #fff;
  193. font-size: 32rpx;
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. padding-bottom: env(safe-area-inset-bottom);
  198. }
  199. </style>