addressManage.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view :class="[AppTheme]" 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="getPhoneNumber" v-model="addressData.mobile" placeholder="收货人手机号码"
  11. placeholder-class="placeholder" />
  12. </view>
  13. <view class="row b-b">
  14. <text class="tit">地址</text>
  15. <view style="width: 70%;">
  16. <u--input border="none" v-model="addressData.address" placeholder="收货地址"
  17. suffixIconStyle="color: #909399"></u--input>
  18. </view>
  19. <view v-if='config.app.position==1' @click="chooseLocation"
  20. style="width: 14%;display: flex;justify-content: flex-end;">
  21. <u-icon name="map-fill" size="20"></u-icon>
  22. </view>
  23. </view>
  24. <view class="row b-b">
  25. <text class="tit">小区</text>
  26. <input class="input" type="text" v-model="addressData.community" placeholder="收货人小区"
  27. placeholder-class="placeholder" />
  28. </view>
  29. <view class="row default-row">
  30. <text class="tit">设为默认</text>
  31. <u-switch v-model="addressData.is_default" size="20" :activeColor="primary" asyncChange
  32. @change="switchChange" />
  33. </u-switch>
  34. </view>
  35. <button class="add-btn bg-linear-gradient" @click="confirm">提交</button>
  36. </view>
  37. </template>
  38. <script>
  39. import api from "../../../api/address/address.js"
  40. export default {
  41. data() {
  42. return {
  43. primary: this.$theme.primary,
  44. addressData: {
  45. id: '',
  46. name: '',
  47. mobile: '',
  48. address: '',
  49. community: '',
  50. is_default: false,
  51. },
  52. type: 0,
  53. settingFile: getApp().globalData.siteinfo,
  54. config: null,
  55. }
  56. },
  57. onLoad(option) {
  58. let title = '新增收货地址';
  59. this.config = this.$config;
  60. if (option.type == 1) {
  61. title = '编辑收货地址'
  62. let data = JSON.parse(option.data)
  63. this.addressData = data
  64. this.addressData.is_default = !!(data.is_default * 1)
  65. }
  66. this.type = option.type;
  67. uni.setNavigationBarTitle({
  68. title
  69. })
  70. },
  71. methods: {
  72. switchChange(e) {
  73. if (e) {
  74. this.addressData.is_default = true;
  75. } else {
  76. this.addressData.is_default = false;
  77. }
  78. },
  79. //地图选择地址
  80. chooseLocation() {
  81. let that = this
  82. // #ifdef MP-WEIXIN || APP-PLUS
  83. that.$until.chooseLocation(function(res) {
  84. that.addressData.address = res.address;
  85. });
  86. // #endif
  87. },
  88. //提交
  89. confirm() {
  90. let that = this;
  91. let data = that.addressData;
  92. if (!data.name) {
  93. that.$api.msg('请填写收货人姓名');
  94. return;
  95. }
  96. var isPhone = /^1[3456789]\d{9}$/;
  97. var isMob = /^((0\d{2,3})-)?(\d{7,8})$/;
  98. if (!isMob.test(data.mobile) && !isPhone.test(data.mobile)) {
  99. that.$api.msg('请输入正确的联系电话');
  100. return;
  101. }
  102. if (!data.address) {
  103. that.$api.msg('请填写收货地址');
  104. return;
  105. }
  106. const obj = {
  107. id: that.addressData.id,
  108. address: that.addressData.address,
  109. name: that.addressData.name,
  110. mobile: that.addressData.mobile,
  111. community: (that.addressData.community == '' || that.addressData.community == null) ? '' : that
  112. .addressData.community,
  113. type: that.type,
  114. is_default: +that.addressData.is_default
  115. }
  116. api.addressSet(obj).then(res => {
  117. console.log(res)
  118. if (res.status == 200) {
  119. that.$api.msg(`地址${that.type==1 ? '修改': '添加'}成功`);
  120. setTimeout(() => {
  121. uni.navigateBack()
  122. }, 800)
  123. }
  124. })
  125. },
  126. }
  127. }
  128. </script>
  129. <style lang="scss">
  130. page {
  131. background: $page-color-base;
  132. }
  133. .row {
  134. display: flex;
  135. align-items: center;
  136. position: relative;
  137. padding: 0 30upx;
  138. height: 110upx;
  139. background: #fff;
  140. .tit {
  141. flex-shrink: 0;
  142. width: 120upx;
  143. font-size: 30upx;
  144. color: $font-color-dark;
  145. }
  146. .input {
  147. flex: 1;
  148. font-size: 30upx;
  149. color: $font-color-dark;
  150. }
  151. .icon-shouhuodizhi {
  152. font-size: 36upx;
  153. color: $font-color-light;
  154. }
  155. }
  156. .default-row {
  157. margin-bottom: 16upx;
  158. .tit {
  159. flex: 1;
  160. }
  161. switch {
  162. transform: translateX(16upx) scale(.9);
  163. }
  164. }
  165. .add-btn {
  166. display: flex;
  167. align-items: center;
  168. justify-content: center;
  169. width: 690upx;
  170. height: 80upx;
  171. margin: 60upx auto;
  172. font-size: $font-lg;
  173. color: #fff;
  174. border-radius: 10upx;
  175. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  176. }
  177. </style>