addressManage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.town" placeholder="请输入乡镇"
  21. placeholder-class="placeholder" />
  22. </view> -->
  23. <view class="row b-b">
  24. <text class="tit">详细地址</text>
  25. <input class="input" type="text" v-model="addressData.area" placeholder="请输入详细地址"
  26. placeholder-class="placeholder" />
  27. </view>
  28. <uni-list class="margin-t-20">
  29. <uni-list-item title="设为默认" :switch-checked="addressData.default" :show-switch="true" :show-arrow="false"
  30. switch-color="#418c78" @switchChange="switchChange"></uni-list-item>
  31. </uni-list>
  32. <button class="add-btn" @click="confirm">提交</button>
  33. </view>
  34. </template>
  35. <script>
  36. import uniList from '@/components/uni-list/uni-list.vue';
  37. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  38. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  39. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  40. import {
  41. addressEdit
  42. } from '@/api/user.js';
  43. export default {
  44. components: {
  45. uniList,
  46. uniListItem,
  47. pickerAddress,
  48. uniPopup
  49. },
  50. data() {
  51. return {
  52. addressDetail: '',
  53. addressData: {
  54. name: '',
  55. mobile: '',
  56. address: {
  57. province: '',
  58. city: '',
  59. district: ''
  60. },
  61. town: '',
  62. area: '',
  63. default: false
  64. }
  65. };
  66. },
  67. onLoad(option) {
  68. let title = '新增收货地址';
  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. town: data.town,
  83. default: data.is_default == 1,
  84. id: data.id
  85. };
  86. this.addressDetail = data.province + data.city + data.district;
  87. }
  88. this.manageType = option.type;
  89. uni.setNavigationBarTitle({
  90. title
  91. });
  92. },
  93. methods: {
  94. // 选中城市切换
  95. onCityClick({
  96. data
  97. }) {
  98. let address = this.addressData.address;
  99. address.province = data[0];
  100. address.city = data[1];
  101. address.district = data[2];
  102. this.addressDetail = data.join('');
  103. },
  104. //地图选择地址
  105. chooseLocation() {
  106. uni.chooseLocation({
  107. success: data => {
  108. console.log(data);
  109. this.addressData.addressName = data.name;
  110. this.addressData.address = data.name;
  111. }
  112. });
  113. },
  114. // 设置是否为默认地址
  115. switchChange(e) {
  116. this.addressData.default = e.value;
  117. },
  118. //提交
  119. confirm() {
  120. let obj = this;
  121. let data = this.addressData;
  122. if (!data.name) {
  123. this.$api.msg('请填写收货人姓名');
  124. return;
  125. }
  126. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  127. this.$api.msg('请输入正确的手机号码');
  128. return;
  129. }
  130. if (!data.address) {
  131. this.$api.msg('请在地图选择所在位置');
  132. return;
  133. }
  134. // if (!data.town) {
  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. town: data.town,
  152. detail: data.area,
  153. is_default: data.default,
  154. id: data.id || "",
  155. type: 1
  156. }).then(function(e) {
  157. obj.$api.prePage().refreshList();
  158. uni.showToast({
  159. title: '提交成功',
  160. duration: 2000
  161. });
  162. setTimeout(function() {
  163. uni.navigateBack();
  164. }, 800);
  165. });
  166. }
  167. }
  168. };
  169. </script>
  170. <style lang="scss">
  171. page {
  172. background: $page-color-base;
  173. padding-top: 16rpx;
  174. }
  175. .row {
  176. display: flex;
  177. align-items: center;
  178. position: relative;
  179. padding: 0 30rpx;
  180. height: 110rpx;
  181. background: #fff;
  182. .tit {
  183. flex-shrink: 0;
  184. width: 140rpx;
  185. font-size: 30rpx;
  186. color: $font-color-dark;
  187. }
  188. .input {
  189. flex: 1;
  190. font-size: 30rpx;
  191. color: $font-color-dark;
  192. }
  193. .iconlocation {
  194. font-size: 36rpx;
  195. color: $font-color-light;
  196. }
  197. }
  198. .default-row {
  199. margin-top: 16rpx;
  200. .tit {
  201. flex: 1;
  202. }
  203. switch {
  204. transform: translateX(16rpx) scale(0.9);
  205. }
  206. }
  207. .add-btn {
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. width: 690rpx;
  212. height: 80rpx;
  213. margin: 60rpx auto;
  214. font-size: $font-lg;
  215. color: #fff;
  216. background-color: $base-color;
  217. border-radius: 10rpx;
  218. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  219. }
  220. .alert-box {
  221. background-color: #ffffff;
  222. }
  223. </style>