addressManage.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="page">
  3. <view class="row b-b">
  4. <text class="tit">收货人</text>
  5. <input class="input" type="text" v-model="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="mobile" placeholder="联系电话" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b" v-on:click="chooseLoc()">
  12. <text class="tit">收货地址</text>
  13. <view class="input clamp2" :class="{placeholder: !addr}">
  14. {{addr ? addr :'定位地址'}}
  15. </view>
  16. <image src="/static/r-arrow.png" mode="aspectFill" class="ic"></image>
  17. </view>
  18. <view class="row b-b">
  19. <text class="tit">详细地址</text>
  20. <input class="input clamp2" type="text" v-model="desc" placeholder="详细地址,楼号" placeholder-class="placeholder" />
  21. </view>
  22. <view class="row default-row">
  23. <div class="l flex-col justify-center">
  24. <text class="tit">设为默认</text>
  25. <text class="tips">每次下单会默认推荐使用该地址</text>
  26. </div>
  27. <switch :checked="is_default" color="#92B99C" @change="switchChange" />
  28. </view>
  29. <button class="add-btn" @click="confirm">提交</button>
  30. </view>
  31. </template>
  32. <script>
  33. import {chooseLoc} from '@/common/loc.js';
  34. export default {
  35. data() {
  36. return {
  37. name: '',
  38. mobile: '',
  39. addr:'',
  40. desc:'',
  41. is_default:'',
  42. }
  43. },
  44. onLoad(option) {
  45. let title = '新增收货地址';
  46. if (option.type === 'edit') {
  47. // this.getInfo(option.id);
  48. title = '编辑收货地址'
  49. } else {
  50. // this.$refs.mpvueCityPicker.creat(this.pickerValueDefault);
  51. }
  52. this.manageType = option.type;
  53. uni.setNavigationBarTitle({
  54. title
  55. })
  56. },
  57. methods: {
  58. // 获取地址详情
  59. async getInfo(id){
  60. let res= await this.$api.request(`/addons/unishop/address/info?id=${id}`);
  61. let addressData = res.data;
  62. if (addressData) {
  63. console.log(addressData);
  64. this.addressData = addressData;
  65. let pickerValueDefault = [];
  66. pickerValueDefault.push(addressData.province_id);
  67. pickerValueDefault.push(addressData.city_id);
  68. pickerValueDefault.push(addressData.area_id);
  69. this.pickerValueDefault = pickerValueDefault;
  70. this.$refs.mpvueCityPicker.creat(pickerValueDefault);
  71. }
  72. },
  73. // 城市选择器
  74. async chooseLoc() {
  75. let {
  76. province,
  77. city,
  78. area,
  79. address,
  80. latitude,
  81. longitude,
  82. } =await chooseLoc();
  83. this.addr = `${province}${city} ${area}`;
  84. this.desc = address;
  85. },
  86. //默认地址
  87. switchChange(e) {
  88. this.is_default = e.detail.value;
  89. },
  90. //提交
  91. async confirm() {
  92. //Deep Clone
  93. if(this.$api.inAction('confirm',this)){
  94. return;
  95. }
  96. let data = JSON.parse(JSON.stringify(this.addressData));
  97. if (!data.name) {
  98. this.$api.msg('请填写收货人姓名');
  99. return;
  100. }
  101. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  102. this.$api.msg('请输入正确的手机号码');
  103. return;
  104. }
  105. if (!data.address) {
  106. this.$api.msg('请填详细地址信息');
  107. return;
  108. }
  109. console.log(data.is_default);
  110. data.is_default = data.is_default == true ? 1 : 0;
  111. let action = this.manageType == 'edit' ? 'edit' : 'add';
  112. let result = await this.$api.request('/addons/unishop/address/' + action, 'POST', data);
  113. if (result) {
  114. this.$api.prePage().refreshList(data, this.manageType);
  115. setTimeout(() => {
  116. uni.navigateBack()
  117. }, 800)
  118. }
  119. },
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. page {
  125. background: #fff;
  126. }
  127. .page{
  128. padding: 16rpx 30rpx 0;
  129. min-height: 100vh;
  130. padding-bottom: calc(var(--safe-area-inset-bottom) / 2);
  131. }
  132. .row {
  133. display: flex;
  134. align-items: center;
  135. position: relative;
  136. height: 110upx;
  137. background: #fff;
  138. border-bottom: 2rpx solid #eee;
  139. .tit {
  140. flex-shrink: 0;
  141. margin-right: 30rpx;
  142. font-size: 28upx;
  143. color: #333;
  144. }
  145. .tips{
  146. margin-top: 20rpx;
  147. font-size: 20rpx;
  148. font-family: PingFang SC;
  149. font-weight: 500;
  150. color: #999999;
  151. }
  152. .input {
  153. flex: 1;
  154. font-size: 28upx;
  155. color: #333;
  156. line-height: 36rpx;
  157. }
  158. .ic{
  159. flex-shrink: 0;
  160. width: 24rpx;
  161. height: 24rpx;
  162. margin-left: auto;
  163. }
  164. }
  165. .default-row {
  166. margin-top: 16upx;
  167. .tit {
  168. flex: 1;
  169. }
  170. switch {
  171. margin-left: auto;
  172. transform: translateX(16upx) scale(.9);
  173. }
  174. }
  175. .add-btn {
  176. display: flex;
  177. align-items: center;
  178. justify-content: center;
  179. width: 690upx;
  180. height: 80upx;
  181. margin: 120upx auto 10rpx;
  182. font-size: 30rpx;
  183. color: #fff;
  184. background-color: $base-color;
  185. border-radius: 38upx;
  186. }
  187. </style>