addressManage.vue 5.9 KB

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