addressManage.vue 4.9 KB

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