addressManage.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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="收货人姓名"
  6. placeholder-class="placeholder" />
  7. </view>
  8. <view class="row b-b">
  9. <text class="tit">手机号</text>
  10. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码"
  11. placeholder-class="placeholder" />
  12. </view>
  13. <view class="row b-b">
  14. <text class="tit">地址</text>
  15. <pickerAddress class="input" @change="onCityClick">{{addressDetail||'请选择地址'}}</pickerAddress>
  16. <text class="iconfont iconlocation"></text>
  17. </view>
  18. <view class="row b-b">
  19. <text class="tit">门牌号</text>
  20. <input class="input" type="text" v-model="addressData.area" placeholder="楼号、门牌"
  21. placeholder-class="placeholder" />
  22. </view>
  23. <uni-list class="margin-t-20">
  24. <uni-list-item title="设为默认" :switch-checked="addressData.default" :show-switch="true" :show-arrow="false"
  25. switch-color="#5dbc7c" @switchChange="switchChange"></uni-list-item>
  26. </uni-list>
  27. <button class="add-btn" @click="confirm">提交</button>
  28. </view>
  29. </template>
  30. <script>
  31. import uniList from '@/components/uni-list/uni-list.vue';
  32. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  33. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  34. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  35. import {
  36. addressEdit
  37. } from '@/api/user.js';
  38. // #ifdef H5
  39. import weichatObj from '@/plugin/jweixin-module/index.js';
  40. // #endif
  41. export default {
  42. components: {
  43. uniList,
  44. uniListItem,
  45. pickerAddress,
  46. uniPopup
  47. },
  48. data() {
  49. return {
  50. addressDetail: '',
  51. addressData: {
  52. name: '',
  53. mobile: '',
  54. address: {
  55. province: '',
  56. city: '',
  57. district: ''
  58. },
  59. area: '',
  60. default: false
  61. }
  62. };
  63. },
  64. onLoad(option) {
  65. let title = '新增收货地址';
  66. // #ifdef H5
  67. this.wxaddress();
  68. // #endif
  69. if (option.type === 'edit') {
  70. title = '编辑收货地址';
  71. let data = JSON.parse(option.data);
  72. console.log(data);
  73. this.addressData = {
  74. name: data.real_name,
  75. mobile: data.phone,
  76. address: {
  77. province: data.province,
  78. city: data.city,
  79. district: data.district
  80. },
  81. area: data.detail,
  82. default: data.is_default == 1,
  83. id: data.id
  84. };
  85. this.addressDetail = data.province + data.city + data.district;
  86. }
  87. this.manageType = option.type;
  88. uni.setNavigationBarTitle({
  89. title
  90. });
  91. },
  92. methods: {
  93. wxaddress() {
  94. console.log(this.weichatObj, '123456');
  95. console.log(weichatObj, 'weichatObj');
  96. console.log(wx, '654321');
  97. },
  98. // 选中城市切换
  99. onCityClick({
  100. data
  101. }) {
  102. let address = this.addressData.address;
  103. address.province = data[0];
  104. address.city = data[1];
  105. address.district = data[2];
  106. this.addressDetail = data.join('');
  107. },
  108. //地图选择地址
  109. chooseLocation() {
  110. uni.chooseLocation({
  111. success: data => {
  112. console.log(data);
  113. this.addressData.addressName = data.name;
  114. this.addressData.address = data.name;
  115. }
  116. });
  117. },
  118. // 设置是否为默认地址
  119. switchChange(e) {
  120. this.addressData.default = e.value;
  121. },
  122. //提交
  123. confirm() {
  124. let obj = this;
  125. let data = this.addressData;
  126. if (!data.name) {
  127. this.$api.msg('请填写收货人姓名');
  128. return;
  129. }
  130. if (!/(^1[2|3|4|5|6|7|8|9][0-9]{9}$)/.test(data.mobile)) {
  131. this.$api.msg('请输入正确的手机号码');
  132. return;
  133. }
  134. if (!data.address) {
  135. this.$api.msg('请在地图选择所在位置');
  136. return;
  137. }
  138. if (!data.area) {
  139. this.$api.msg('请填写门牌号信息');
  140. return;
  141. }
  142. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  143. addressEdit({
  144. real_name: data.name,
  145. phone: data.mobile,
  146. address: {
  147. province: data.address.province,
  148. city: data.address.city,
  149. district: data.address.district
  150. },
  151. detail: data.area,
  152. is_default: data.default,
  153. 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. .add-btn {
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. width: 690rpx;
  211. height: 80rpx;
  212. margin: 60rpx auto;
  213. font-size: $font-lg;
  214. color: #fff;
  215. background-color: $base-color;
  216. border-radius: 10rpx;
  217. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  218. }
  219. .alert-box {
  220. background-color: #ffffff;
  221. }
  222. </style>