addressManage.vue 5.5 KB

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