addressManage.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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="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/user.js';
  39. export default {
  40. components: {
  41. uniList,
  42. uniListItem,
  43. pickerAddress,
  44. uniPopup
  45. },
  46. data() {
  47. return {
  48. addressDetail: '',
  49. loadingType: 1,
  50. addressData: {
  51. name: '',
  52. mobile: '',
  53. address: {
  54. province: '',
  55. city: '',
  56. district: ''
  57. },
  58. area: '',
  59. default: false
  60. }
  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. let obj = this;
  114. let data = this.addressData;
  115. if (!data.name) {
  116. this.$api.msg('请填写收货人姓名');
  117. return;
  118. }
  119. if (!/(^1[2|3|4|5|6|7|8|9][0-9]{9}$)/.test(data.mobile)) {
  120. this.$api.msg('请输入正确的手机号码');
  121. return;
  122. }
  123. if (!data.address) {
  124. this.$api.msg('请在地图选择所在位置');
  125. return;
  126. }
  127. if (!data.area) {
  128. this.$api.msg('请填写门牌号信息');
  129. return;
  130. }
  131. if (obj.loadingType == 2) {
  132. console.log('1111');
  133. return;
  134. }
  135. obj.loadingType = 2;
  136. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  137. addressEdit({
  138. real_name: data.name,
  139. phone: data.mobile,
  140. address: {
  141. province: data.address.province,
  142. city: data.address.city,
  143. district: data.address.district
  144. },
  145. detail: data.area,
  146. is_default: data.default,
  147. id: data.id || '',
  148. type: 1
  149. })
  150. .then(function(e) {
  151. obj.$api.prePage().refreshList();
  152. uni.showToast({
  153. title: '提交成功',
  154. duration: 2000
  155. });
  156. setTimeout(function() {
  157. uni.navigateBack();
  158. }, 800);
  159. })
  160. .catch(err => {
  161. obj.loadingType = 1;
  162. });
  163. }
  164. }
  165. };
  166. </script>
  167. <style lang="scss">
  168. page {
  169. background: $page-color-base;
  170. padding-top: 16rpx;
  171. }
  172. .row {
  173. display: flex;
  174. align-items: center;
  175. position: relative;
  176. padding: 0 30rpx;
  177. height: 110rpx;
  178. background: #fff;
  179. .tit {
  180. flex-shrink: 0;
  181. width: 120rpx;
  182. font-size: 30rpx;
  183. color: $font-color-dark;
  184. }
  185. .input {
  186. flex: 1;
  187. font-size: 30rpx;
  188. color: $font-color-dark;
  189. }
  190. .iconlocation {
  191. font-size: 36rpx;
  192. color: $font-color-light;
  193. }
  194. }
  195. .default-row {
  196. margin-top: 16rpx;
  197. .tit {
  198. flex: 1;
  199. }
  200. switch {
  201. transform: translateX(16rpx) scale(0.9);
  202. }
  203. }
  204. .add-btn {
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. width: 690rpx;
  209. height: 80rpx;
  210. margin: 60rpx auto;
  211. font-size: $font-lg;
  212. color: #fff;
  213. background-color: $base-color;
  214. border-radius: 10rpx;
  215. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  216. }
  217. .alert-box {
  218. background-color: #ffffff;
  219. }
  220. </style>