addressManage.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. import weichatObj from '@/plugin/jweixin-module/index.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. };
  61. },
  62. onLoad(option) {
  63. let title = '新增收货地址';
  64. // #ifdef H5
  65. this.wxaddress();
  66. // #endif
  67. if (option.type === 'edit') {
  68. title = '编辑收货地址';
  69. let data = JSON.parse(option.data);
  70. console.log(data);
  71. this.addressData = {
  72. name: data.real_name,
  73. mobile: data.phone,
  74. address: {
  75. province: data.province,
  76. city: data.city,
  77. district: data.district
  78. },
  79. area: data.detail,
  80. default: data.is_default == 1,
  81. id: data.id
  82. };
  83. this.addressDetail = data.province + data.city + data.district;
  84. }
  85. this.manageType = option.type;
  86. uni.setNavigationBarTitle({
  87. title
  88. });
  89. },
  90. methods: {
  91. wxaddress() {
  92. console.log(this.weichatObj, '123456');
  93. console.log(weichatObj, 'weichatObj');
  94. console.log(wx, '654321');
  95. },
  96. // 选中城市切换
  97. onCityClick({
  98. data
  99. }) {
  100. let address = this.addressData.address;
  101. address.province = data[0];
  102. address.city = data[1];
  103. address.district = data[2];
  104. this.addressDetail = data.join('');
  105. },
  106. //地图选择地址
  107. chooseLocation() {
  108. uni.chooseLocation({
  109. success: data => {
  110. console.log(data);
  111. this.addressData.addressName = data.name;
  112. this.addressData.address = data.name;
  113. }
  114. });
  115. },
  116. // 设置是否为默认地址
  117. switchChange(e) {
  118. this.addressData.default = e.value;
  119. },
  120. //提交
  121. confirm() {
  122. let obj = this;
  123. let data = this.addressData;
  124. if (!data.name) {
  125. this.$api.msg('请填写收货人姓名');
  126. return;
  127. }
  128. if (!/(^1[2|3|4|5|6|7|8|9][0-9]{9}$)/.test(data.mobile)) {
  129. this.$api.msg('请输入正确的手机号码');
  130. return;
  131. }
  132. if (!data.address) {
  133. this.$api.msg('请在地图选择所在位置');
  134. return;
  135. }
  136. if (!data.area) {
  137. this.$api.msg('请填写门牌号信息');
  138. return;
  139. }
  140. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  141. addressEdit({
  142. real_name: data.name,
  143. phone: data.mobile,
  144. address: {
  145. province: data.address.province,
  146. city: data.address.city,
  147. district: data.address.district
  148. },
  149. detail: data.area,
  150. is_default: data.default,
  151. id: data.id || "",
  152. type: 1
  153. }).then(function(e) {
  154. obj.$api.prePage().refreshList();
  155. uni.showToast({
  156. title: '提交成功',
  157. duration: 2000
  158. });
  159. setTimeout(function() {
  160. uni.navigateBack();
  161. }, 800);
  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>