addressManage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="content">
  3. <view class="row b-b">
  4. <text class="tit">联系人</text>
  5. <input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">手机号</text>
  9. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b">
  12. <text class="tit">地址</text>
  13. <pickerAddress class="input" @change="onCityClick">{{ addressDetail || '请选择地址' }}</pickerAddress>
  14. <text class="iconfont iconlocation"></text>
  15. </view>
  16. <view class="row b-b">
  17. <text class="tit">门牌号</text>
  18. <input class="input" type="text" v-model="addressData.area" placeholder="楼号、门牌" placeholder-class="placeholder" />
  19. </view>
  20. <uni-list class="margin-t-20">
  21. <uni-list-item
  22. title="设为默认"
  23. :switch-checked="addressData.default"
  24. :show-switch="true"
  25. :show-arrow="false"
  26. switch-color="#921a23"
  27. @switchChange="switchChange"
  28. ></uni-list-item>
  29. </uni-list>
  30. <view class="del-btn" v-if="showDel"><text @click="delAddr">删除地址</text></view>
  31. <button class="add-btn" @click="confirm">提交</button>
  32. </view>
  33. </template>
  34. <script>
  35. import uniList from '@/components/uni-list/uni-list.vue';
  36. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  37. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  38. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  39. import { addressEdit, addressDel } from '@/api/user.js';
  40. export default {
  41. components: {
  42. uniList,
  43. uniListItem,
  44. pickerAddress,
  45. uniPopup
  46. },
  47. data() {
  48. return {
  49. addressDetail: '',
  50. addressData: {
  51. name: '',
  52. mobile: '',
  53. address: {
  54. province: '',
  55. city: '',
  56. district: ''
  57. },
  58. area: '',
  59. default: false,
  60. showDel: false
  61. }
  62. };
  63. },
  64. onLoad(option) {
  65. this.showDel = false;
  66. let title = '新增收货地址';
  67. if (option.type === 'edit') {
  68. title = '编辑收货地址';
  69. let data = JSON.parse(option.data);
  70. console.log(data);
  71. this.showDel = true;
  72. this.addressData = {
  73. name: data.real_name,
  74. mobile: data.phone,
  75. address: {
  76. province: data.province,
  77. city: data.city,
  78. district: data.district
  79. },
  80. area: data.detail,
  81. default: data.is_default == 1,
  82. id: data.address_id
  83. };
  84. this.addressDetail = data.province + data.city + data.district;
  85. }
  86. this.manageType = option.type;
  87. uni.setNavigationBarTitle({
  88. title
  89. });
  90. },
  91. methods: {
  92. // 选中城市切换
  93. onCityClick({ data }) {
  94. let address = this.addressData.address;
  95. address.province = data[0];
  96. address.city = data[1];
  97. address.district = data[2];
  98. this.addressDetail = data.join('');
  99. },
  100. //地图选择地址
  101. chooseLocation() {
  102. uni.chooseLocation({
  103. success: data => {
  104. console.log(data);
  105. this.addressData.addressName = data.name;
  106. this.addressData.address = data.name;
  107. }
  108. });
  109. },
  110. // 设置是否为默认地址
  111. switchChange(e) {
  112. this.addressData.default = e.value;
  113. },
  114. //删除地址
  115. delAddr() {
  116. addressDel({},this.addressData.id).then(({ data }) => {
  117. this.$api.msg('删除成功');
  118. setTimeout(() => {
  119. uni.redirectTo({ url: '/pages/set/address' });
  120. }, 1000);
  121. });
  122. console.log('删除');
  123. },
  124. //提交
  125. confirm() {
  126. let obj = this;
  127. let data = this.addressData;
  128. if (!data.name) {
  129. this.$api.msg('请填写收货人姓名');
  130. return;
  131. }
  132. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  133. this.$api.msg('请输入正确的手机号码');
  134. return;
  135. }
  136. if (!data.address) {
  137. this.$api.msg('请在地图选择所在位置');
  138. return;
  139. }
  140. if (!data.area) {
  141. this.$api.msg('请填写门牌号信息');
  142. return;
  143. }
  144. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  145. addressEdit({
  146. real_name: data.name,
  147. phone: data.mobile,
  148. province: data.address.province,
  149. city: data.address.city,
  150. district: data.address.district,
  151. detail: data.area,
  152. is_default: data.default,
  153. address_id: data.id || '',
  154. type: 1
  155. }).then(function(e) {
  156. obj.$api.prePage().refreshList();
  157. uni.showToast({
  158. title: '提交成功',
  159. duration: 2000
  160. });
  161. setTimeout(function() {
  162. uni.navigateBack();
  163. }, 800);
  164. });
  165. }
  166. }
  167. };
  168. </script>
  169. <style lang="scss">
  170. page {
  171. background: $page-color-base;
  172. padding-top: 16rpx;
  173. }
  174. .row {
  175. display: flex;
  176. align-items: center;
  177. position: relative;
  178. padding: 0 30rpx;
  179. height: 110rpx;
  180. background: #fff;
  181. .tit {
  182. flex-shrink: 0;
  183. width: 120rpx;
  184. font-size: 30rpx;
  185. color: $font-color-dark;
  186. }
  187. .input {
  188. flex: 1;
  189. font-size: 30rpx;
  190. color: $font-color-dark;
  191. }
  192. .iconlocation {
  193. font-size: 36rpx;
  194. color: $font-color-light;
  195. }
  196. }
  197. .default-row {
  198. margin-top: 16rpx;
  199. .tit {
  200. flex: 1;
  201. }
  202. switch {
  203. transform: translateX(16rpx) scale(0.9);
  204. }
  205. }
  206. .del-btn {
  207. width: 750rpx;
  208. height: 99rpx;
  209. margin-top: 28rpx;
  210. font-size: 30rpx;
  211. font-weight: 500;
  212. color: #901b21;
  213. background-color: #fff;
  214. line-height: 99rpx;
  215. padding-left: 42rpx;
  216. }
  217. .add-btn {
  218. display: flex;
  219. align-items: center;
  220. justify-content: center;
  221. width: 690rpx;
  222. height: 80rpx;
  223. margin: 60rpx auto;
  224. font-size: $font-lg;
  225. color: #fff;
  226. background-color: $base-color;
  227. border-radius: 10rpx;
  228. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  229. }
  230. .alert-box {
  231. background-color: #ffffff;
  232. }
  233. </style>