addressManage.vue 5.0 KB

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