addressManage.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view class="content">
  3. <view class="listBox">
  4. <view class="list">
  5. <view class="flex listItem" >
  6. <view class="flex titleBox">
  7. <text class="title">联系人</text>
  8. </view>
  9. <view class="right flex">
  10. <input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名"
  11. placeholder-class="placeholder" />
  12. </view>
  13. </view>
  14. <view class="flex listItem" >
  15. <view class="flex titleBox">
  16. <text class="title">手机号</text>
  17. </view>
  18. <view class="right flex">
  19. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码"
  20. placeholder-class="placeholder" />
  21. </view>
  22. </view>
  23. <view class="flex listItem" >
  24. <view class="flex titleBox">
  25. <text class="title">地址</text>
  26. </view>
  27. <view class="right flex">
  28. <pickerAddress class="input" @change="onCityClick">{{addressDetail||'请选择地址'}}</pickerAddress>
  29. </view>
  30. </view>
  31. <view class="flex listItem" >
  32. <view class="flex titleBox">
  33. <text class="title">门牌号</text>
  34. </view>
  35. <view class="right flex">
  36. <input class="input" type="text" v-model="addressData.area" placeholder="楼号、门牌"
  37. placeholder-class="placeholder" />
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <uni-list class="margin-t-20 margin-l-30 margin-r-30" style="border-radius: 20rpx;">
  43. <uni-list-item
  44. title="设为默认"
  45. :switch-checked="addressData.default"
  46. :show-switch="true"
  47. :show-arrow="false"
  48. switch-color="#5dbc7c"
  49. @switchChange="switchChange"
  50. ></uni-list-item>
  51. </uni-list>
  52. <view class="base-buttom" @click="confirm">提交</view>
  53. </view>
  54. </template>
  55. <script>
  56. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  57. import {
  58. addressEdit
  59. } from '@/api/user.js';
  60. import {
  61. prePage
  62. } from '@/utils/rocessor.js';
  63. export default {
  64. components: {
  65. pickerAddress,
  66. },
  67. data() {
  68. return {
  69. code: '',
  70. addressDetail: '',
  71. addressData: {
  72. name: '',
  73. mobile: '',
  74. address: {
  75. province: '',
  76. city: '',
  77. district: ''
  78. },
  79. area: '',
  80. default: false
  81. },
  82. };
  83. },
  84. onLoad(option) {
  85. let title = '新增收货地址';
  86. if (option.type === 'edit') {
  87. title = '编辑收货地址';
  88. let data = JSON.parse(option.data);
  89. console.log(data);
  90. this.addressData = {
  91. name: data.real_name,
  92. mobile: data.phone,
  93. address: {
  94. province: data.province,
  95. city: data.city,
  96. district: data.district
  97. },
  98. area: data.detail,
  99. default: data.is_default == 1,
  100. id: data.id
  101. };
  102. this.addressDetail = data.province + data.city + data.district;
  103. }
  104. this.manageType = option.type;
  105. uni.setNavigationBarTitle({
  106. title
  107. });
  108. },
  109. methods: {
  110. // 选中城市切换
  111. onCityClick({
  112. data
  113. }) {
  114. let address = this.addressData.address;
  115. address.province = data[0];
  116. address.city = data[1];
  117. address.district = data[2];
  118. this.addressDetail = data.join('');
  119. },
  120. //地图选择地址
  121. chooseLocation() {
  122. uni.chooseLocation({
  123. success: data => {
  124. console.log(data);
  125. this.addressData.addressName = data.name;
  126. this.addressData.address = data.name;
  127. }
  128. });
  129. },
  130. // 设置是否为默认地址
  131. switchChange(e) {
  132. this.addressData.default = e.value;
  133. },
  134. //提交
  135. confirm() {
  136. let obj = this;
  137. let data = this.addressData;
  138. if (!data.name) {
  139. uni.showToast({
  140. title:"请填写收货人姓名",
  141. icon:"none"
  142. })
  143. return;
  144. }
  145. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  146. uni.showToast({
  147. title:"请输入正确的手机号码",
  148. icon:"none"
  149. })
  150. return;
  151. }
  152. if (!data.address) {
  153. uni.showToast({
  154. title:"请在地图选择所在位置",
  155. icon:"none"
  156. })
  157. return;
  158. }
  159. if (!data.area) {
  160. uni.showToast({
  161. title:"请填写门牌号信息",
  162. icon:"none"
  163. })
  164. return;
  165. }
  166. //prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  167. addressEdit({
  168. real_name: data.name,
  169. phone: data.mobile,
  170. address: {
  171. province: data.address.province,
  172. city: data.address.city,
  173. district: data.address.district
  174. },
  175. detail: data.area,
  176. is_default: data.default,
  177. id: data.id || "",
  178. type: 1
  179. }).then(function(e) {
  180. prePage().refreshList();
  181. uni.showToast({
  182. title: '提交成功',
  183. duration: 2000
  184. });
  185. setTimeout(function() {
  186. uni.navigateBack();
  187. }, 800);
  188. });
  189. }
  190. }
  191. };
  192. </script>
  193. <style lang="scss">
  194. page {
  195. background: $page-color-base;
  196. }
  197. .content{
  198. padding-top: 30rpx;
  199. }
  200. .listBox {
  201. margin: 0 $page-row-spacing;
  202. border-radius: 20rpx;
  203. overflow: hidden;
  204. background-color: #FFFFFF;
  205. }
  206. .list {
  207. .input {
  208. text-align: right;
  209. font-size: $font-base;
  210. color: $color-gray;
  211. width: 100%;
  212. flex-grow: 1;
  213. }
  214. .listItem {
  215. padding: 35rpx 40rpx;
  216. border-bottom: 1px solid $page-color-light;
  217. }
  218. .listIconImg {
  219. width: 36rpx;
  220. }
  221. .right {
  222. color: $font-color-light;
  223. font-size: $font-base;
  224. flex-grow: 1;
  225. .img {
  226. width: 26rpx;
  227. }
  228. .code {}
  229. }
  230. .titleBox {
  231. .title {
  232. color: $font-color-base;
  233. font-size: $font-base;
  234. }
  235. }
  236. }
  237. </style>