爱简收旧衣按件回收前端代码仓库
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.

210 lines
4.3 KiB

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