addressManage.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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="#303030" @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. export default {
  39. components: {
  40. uniList,
  41. uniListItem,
  42. pickerAddress,
  43. uniPopup
  44. },
  45. data() {
  46. return {
  47. addressDetail: '',
  48. addressData: {
  49. name: '',
  50. mobile: '',
  51. address: {
  52. province: '',
  53. city: '',
  54. district: ''
  55. },
  56. area: '',
  57. default: false
  58. }
  59. };
  60. },
  61. onLoad(option) {
  62. let title = '新增收货地址';
  63. if (option.type === 'edit') {
  64. title = '编辑收货地址';
  65. let data = JSON.parse(option.data);
  66. console.log(data);
  67. this.addressData = {
  68. name: data.real_name,
  69. mobile: data.phone,
  70. address: {
  71. province: data.province,
  72. city: data.city,
  73. district: data.district
  74. },
  75. area: data.detail,
  76. default: data.is_default == 1,
  77. id: data.id
  78. };
  79. this.addressDetail = data.province + data.city + data.district;
  80. }
  81. this.manageType = option.type;
  82. uni.setNavigationBarTitle({
  83. title
  84. });
  85. },
  86. methods: {
  87. // 选中城市切换
  88. onCityClick({
  89. data
  90. }) {
  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. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  132. addressEdit({
  133. real_name: data.name,
  134. phone: data.mobile,
  135. address: {
  136. province: data.address.province,
  137. city: data.address.city,
  138. district: data.address.district
  139. },
  140. detail: data.area,
  141. is_default: data.default,
  142. id: data.id || "",
  143. type: 1
  144. }).then(function(e) {
  145. obj.$api.prePage().refreshList();
  146. uni.showToast({
  147. title: '提交成功',
  148. duration: 2000
  149. });
  150. setTimeout(function() {
  151. uni.navigateBack();
  152. }, 800);
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss">
  159. page {
  160. background: $page-color-base;
  161. padding-top: 16rpx;
  162. }
  163. .row {
  164. display: flex;
  165. align-items: center;
  166. position: relative;
  167. padding: 0 30rpx;
  168. height: 110rpx;
  169. background: #fff;
  170. .tit {
  171. flex-shrink: 0;
  172. width: 120rpx;
  173. font-size: 30rpx;
  174. color: $font-color-dark;
  175. }
  176. .input {
  177. flex: 1;
  178. font-size: 30rpx;
  179. color: $font-color-dark;
  180. }
  181. .iconlocation {
  182. font-size: 36rpx;
  183. color: $font-color-light;
  184. }
  185. }
  186. .default-row {
  187. margin-top: 16rpx;
  188. .tit {
  189. flex: 1;
  190. }
  191. switch {
  192. transform: translateX(16rpx) scale(0.9);
  193. }
  194. }
  195. .add-btn {
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. width: 690rpx;
  200. height: 80rpx;
  201. margin: 60rpx auto;
  202. font-size: $font-lg;
  203. color: #F8DABA;
  204. background-color: #303030;
  205. border-radius: 10rpx;
  206. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  207. }
  208. .alert-box {
  209. background-color: #ffffff;
  210. }
  211. </style>