addSite.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="address">
  3. <view class="address-top flex">
  4. <!-- <image src="/static/image/publice/fanhui@2x.png" mode="" @click="retutnTop"></image> -->
  5. <image src="" mode="" @click="retutnTop"></image>
  6. <text>{{ type == 0 ? '添加收货地址' : '修改收货地址' }}</text>
  7. <image :src="type == 0 ? '' : '/static/image/me/shanchu@2x.png'" mode="" @click="delAddress"></image>
  8. </view>
  9. <view class="address-info">
  10. <view class="address-item">
  11. <view class="address-font">收货人</view>
  12. <view class="ainput flex"><input type="text" maxlength="10" v-model="user.username" placeholder="请输入收货人姓名" placeholder-style="color:#999999" /></view>
  13. </view>
  14. <view class="address-item">
  15. <view class="address-font">手机号</view>
  16. <view class="ainput flex"><input type="number" maxlength="11" v-model="user.mobile" placeholder="请输入收货人手机号" placeholder-style="color:#999999" /></view>
  17. </view>
  18. <pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
  19. <view class="address-item">
  20. <view class="address-font">所在地区</view>
  21. <view class="ainput flex">
  22. <input type="text" v-model="address" placeholder="请选择地区" disabled placeholder-style="color:#999999" />
  23. <image src="/static/image/publice/jinruer@2x.png" mode=""></image>
  24. </view>
  25. </view>
  26. </pick-regions>
  27. <view class="address-item">
  28. <view class="address-font">详细地址</view>
  29. <view class="ainput ainputs flex">
  30. <textarea placeholder="如:街道、楼牌号等" v-model="user.detail" placeholder-style="color:#999999" maxlength="-1"></textarea>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="address-switch flex">
  35. <text>设置为默认地址</text>
  36. <switch color="#DEBB81" @change="changeSwitch" :checked="user.is_default == 1"></switch>
  37. </view>
  38. <button class="btn" hover-class="hover-view" @click="submit">保存收货地址</button>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. user: {
  46. username: '',
  47. mobile: '',
  48. province: '',
  49. city: '',
  50. area: '',
  51. detail: '',
  52. is_default: 0,
  53. address_id: ''
  54. },
  55. type: 0, //添加还是编辑
  56. flag: true, //
  57. address: '',
  58. defaultRegionCode: ['河南省', '郑州市', '中原区']
  59. };
  60. },
  61. methods: {
  62. //删除地址
  63. delAddress() {
  64. uni.showModal({
  65. content: '是否删除地址?',
  66. success: res => {
  67. if (res.confirm) {
  68. this.$api.deleteAddress({ address_id: this.user.address_id }).then(res => {
  69. if (res.code === 1) {
  70. uni.showToast({ title: res.msg });
  71. setTimeout(() => {
  72. uni.navigateBack();
  73. }, 800);
  74. }
  75. });
  76. }
  77. }
  78. });
  79. },
  80. //返回上一级
  81. retutnTop() {
  82. uni.navigateBack();
  83. },
  84. //选择地区
  85. handleGetRegion(e) {
  86. this.user.province = e[0].name;
  87. this.user.city = e[1].name;
  88. this.user.area = e[2].name;
  89. this.address = e[0].name + e[1].name + e[2].name;
  90. },
  91. changeSwitch(e) {
  92. this.user.is_default = e.detail.value ? 1 : 0;
  93. },
  94. submit() {
  95. if (!this.user.username) return uni.showToast({ title: '请输入收货人姓名', icon: 'none' });
  96. if (!this.user.mobile.match(/^(0|86|17951)?1[3456789]\d{9}$/)) return uni.showToast({ title: '请输入正确的手机号', icon: 'none' });
  97. if (!this.address) return uni.showToast({ title: '请选择地区', icon: 'none' });
  98. if (!this.user.detail) return uni.showToast({ title: '请输入详细地址', icon: 'none' });
  99. if (!this.flag) return;
  100. this.flag = false;
  101. uni.showLoading({ title: '数据提交中' });
  102. this.$api[this.type == 0 ? 'addAddress' : 'editAddress']({ ...this.user }).then(res => {
  103. uni.hideLoading();
  104. if (res.code === 1) {
  105. uni.showToast({ title: res.msg });
  106. setTimeout(() => {
  107. uni.navigateBack();
  108. }, 800);
  109. this.type == 1 ? uni.removeStorageSync('editAddress') : '';
  110. } else {
  111. this.flag = true;
  112. }
  113. });
  114. }
  115. },
  116. onLoad({ type }) {
  117. this.type = type;
  118. },
  119. onShow() {
  120. if (uni.getStorageSync('editAddress')) {
  121. this.user = JSON.parse(uni.getStorageSync('editAddress'));
  122. this.address =
  123. JSON.parse(uni.getStorageSync('editAddress')).province + JSON.parse(uni.getStorageSync('editAddress')).city + JSON.parse(uni.getStorageSync('editAddress')).area;
  124. this.user.is_default = JSON.parse(uni.getStorageSync('editAddress')).is_default ? 1 : 0;
  125. }
  126. }
  127. };
  128. </script>
  129. <style lang="scss">
  130. .address-top {
  131. width: 100%;
  132. height: 88rpx;
  133. padding: 0 30rpx;
  134. background: #ffffff;
  135. image {
  136. width: 44rpx;
  137. height: 44rpx;
  138. }
  139. text {
  140. font-size: 36rpx;
  141. font-weight: bold;
  142. }
  143. }
  144. .address-info {
  145. padding: 20rpx 30rpx 0 30rpx;
  146. .address-item {
  147. .address-font {
  148. font-size: 30rpx;
  149. font-weight: bold;
  150. padding: 30rpx 0;
  151. }
  152. .ainput {
  153. height: 80rpx;
  154. padding: 0 30rpx;
  155. background: #ffffff;
  156. border-radius: 10rpx;
  157. input {
  158. font-size: 28rpx;
  159. }
  160. image {
  161. width: 22rpx;
  162. height: 22rpx;
  163. }
  164. }
  165. .ainputs {
  166. padding: 30rpx;
  167. height: 160rpx;
  168. textarea {
  169. font-size: 28rpx;
  170. }
  171. }
  172. }
  173. }
  174. .address-switch {
  175. height: 88rpx;
  176. margin: 30rpx 0 84rpx 0;
  177. padding: 0 30rpx;
  178. background: #ffffff;
  179. text {
  180. font-size: 30rpx;
  181. font-weight: bold;
  182. }
  183. }
  184. .btn {
  185. width: 690rpx;
  186. height: 98rpx;
  187. color: #333333;
  188. margin: 0 auto;
  189. font-size: 30rpx;
  190. font-weight: bold;
  191. background: #ffffff;
  192. box-shadow: 0rpx 0rpx 121rpx 0rpx rgba(63, 52, 2, 0.12);
  193. border-radius: 10rpx;
  194. }
  195. </style>