addressManage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="page">
  3. <view class="row b-b">
  4. <text class="tit">收货人</text>
  5. <input class="input" type="text" placeholder="收货人姓名" placeholder-class="placeholder" v-model="consignee" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">联系电话</text>
  9. <input class="input" type="number" placeholder="联系电话" placeholder-class="placeholder" v-model="mobile" />
  10. </view>
  11. <view class="row b-b" v-on:click="chooseLoc()">
  12. <text class="tit">收货地址</text>
  13. <view class="input clamp2" :class="{placeholder: !addrTop}">
  14. {{addrTop ? addrTop :'定位地址'}}
  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" placeholder="详细地址,楼号" placeholder-class="placeholder" v-model="address" />
  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=='1' ? true :false" color="#92B99C" @change="switchChange" />
  28. </view>
  29. <submit-btn @submit="submit" ref="submitRef">
  30. <template v-slot:btns="{isSubmitted}">
  31. <view class="add-btn" :class="{'disabled':isSubmitted}" >提交</view>
  32. </template>
  33. </submit-btn>
  34. </view>
  35. </template>
  36. <script>
  37. import {chooseLoc} from '@/common/loc.js';
  38. export default {
  39. data() {
  40. return {
  41. sourcePage: '', //mang
  42. consignee: '',
  43. mobile: '',
  44. addrTop:'',
  45. is_default:1,
  46. province:'',
  47. city:'',
  48. district:'',
  49. address:'',
  50. address_lng:'',
  51. address_lat:'',
  52. }
  53. },
  54. onLoad(option) {
  55. this.sourcePage = option.sourcePage;
  56. let title = '新增收货地址';
  57. if (+option.id) {
  58. this.id = option.id;
  59. this.getInfo(option.id);
  60. title = '编辑收货地址'
  61. } else {
  62. // this.$refs.mpvueCityPicker.creat(this.pickerValueDefault);
  63. }
  64. uni.setNavigationBarTitle({
  65. title
  66. })
  67. },
  68. methods: {
  69. // 获取地址详情
  70. async getInfo(id){
  71. let res= await this.$request(`addr.info`,{id});
  72. let data = res.data || {};
  73. this.consignee = data.consignee;
  74. this.mobile = data.mobile;
  75. this.province = data.province;
  76. this.city = data.city;
  77. this.district = data.district;
  78. this.address = data.address;
  79. this.is_default = data.is_default;
  80. this.address_lng = data.address_lng;
  81. this.address_lat = data.address_lat;
  82. this.addrTop = `${data.province}${data.city}${data.district}`;
  83. },
  84. // 城市选择器
  85. async chooseLoc() {
  86. let {
  87. province,
  88. city,
  89. district,
  90. desc,
  91. latitude,
  92. longitude,
  93. } =await chooseLoc();
  94. this.addrTop = `${province}${city}${district}`;
  95. this.province = province;
  96. this.city = city;
  97. this.district = district;
  98. this.address = desc;
  99. this.address_lng = longitude;
  100. this.address_lat = latitude;
  101. },
  102. //默认地址
  103. switchChange(e) {
  104. this.is_default = e.detail.value ? 1 : 0;
  105. },
  106. //提交
  107. async submit() {
  108. if (!this.consignee) {
  109. this.$tools.msg('请填写收货人姓名');
  110. return;
  111. }
  112. if (!this.$tools.match(this.mobile,'mobile')) {
  113. return;
  114. }
  115. if (!this.addrTop) {
  116. this.$tools.msg('请选择地址');
  117. return;
  118. }
  119. if (!this.address) {
  120. this.$tools.msg('请填详细地址信息');
  121. return;
  122. }
  123. let sendData = {
  124. consignee :this.consignee,
  125. mobile :this.mobile,
  126. province :this.province,
  127. city :this.city,
  128. district :this.district,
  129. address :this.address,
  130. is_default :this.is_default,
  131. address_lng :this.address_lng,
  132. address_lat :this.address_lat,
  133. };
  134. if(this.id){
  135. sendData = {...sendData,id:this.id}
  136. }
  137. let res = await this.$request('addr.save' , sendData);
  138. if(!this.id){
  139. sendData = {...sendData,id:res.data.id}
  140. }
  141. this.$refs.submitRef.chgeStatus();
  142. // 无默认地址直接添加情况
  143. // if(this.$tools.prePage().setDefaultAddr){
  144. // this.$tools.prePage().setDefaultAddr(sendData)
  145. // }
  146. //盲盒页进
  147. if(this.sourcePage === 'mang'){
  148. this.$store.commit('userInfo/ADDR_INFO',sendData)
  149. }
  150. setTimeout(() => {
  151. uni.navigateBack()
  152. }, 800)
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. page {
  159. background: #fff;
  160. }
  161. .page{
  162. padding: 16rpx 30rpx 0;
  163. min-height: 100vh;
  164. padding-bottom: calc(var(--safe-area-inset-bottom) / 2);
  165. }
  166. .row {
  167. display: flex;
  168. align-items: center;
  169. position: relative;
  170. height: 110upx;
  171. background: #fff;
  172. border-bottom: 2rpx solid #eee;
  173. .tit {
  174. flex-shrink: 0;
  175. margin-right: 30rpx;
  176. font-size: 28upx;
  177. color: #333;
  178. }
  179. .tips{
  180. margin-top: 20rpx;
  181. font-size: 20rpx;
  182. font-family: PingFang SC;
  183. font-weight: 500;
  184. color: #999999;
  185. }
  186. .input {
  187. flex: 1;
  188. font-size: 28upx;
  189. color: #333;
  190. line-height: 36rpx;
  191. }
  192. .ic{
  193. flex-shrink: 0;
  194. width: 24rpx;
  195. height: 24rpx;
  196. margin-left: auto;
  197. }
  198. }
  199. .default-row {
  200. margin-top: 16upx;
  201. .tit {
  202. flex: 1;
  203. }
  204. switch {
  205. margin-left: auto;
  206. transform: translateX(16upx) scale(.9);
  207. }
  208. }
  209. .add-btn {
  210. display: flex;
  211. align-items: center;
  212. justify-content: center;
  213. width: 690upx;
  214. height: 80upx;
  215. margin: 120upx auto 10rpx;
  216. font-size: 30rpx;
  217. color: #fff;
  218. background-color: $base-color;
  219. border-radius: 38upx;
  220. &.disabled{
  221. background-color: #eee;
  222. }
  223. }
  224. </style>