addSite.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="address">
  3. <view class="address_head flex">
  4. <image src="/static/image/publice/fanhui@2x.png" mode="" @click="retutnTop"></image>
  5. <text>{{ type == 0 ? '添加收货地址' : '修改收货地址' }}</text>
  6. <image :src="type== 0 ? '' : '/static/image/me/shanchu@2x.png' " mode="" @click="delAddress"></image>
  7. </view>
  8. <view class="address_ul">
  9. <view class="address_li">
  10. <view class="address_name">收货人</view>
  11. <view class="address_ipt flex">
  12. <input type="text" maxlength="10" v-model="user.username" placeholder="请输入收货人姓名" placeholder-style="color:#999999" />
  13. </view>
  14. </view>
  15. <view class="address_li">
  16. <view class="address_name">手机号</view>
  17. <view class="address_ipt flex">
  18. <input type="number" maxlength="11" v-model="user.mobile" placeholder="请输入收货人手机号" placeholder-style="color:#999999" />
  19. </view>
  20. </view>
  21. <pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
  22. <view class="address_li">
  23. <view class="address_name">所在地区</view>
  24. <view class="address_ipt flex">
  25. <input type="text" v-model="address" placeholder="请选择地区" disabled placeholder-style="color:#999999" />
  26. <image src="/static/image/publice/jinruer@2x.png" mode=""></image>
  27. </view>
  28. </view>
  29. </pick-regions>
  30. <view class="address_li">
  31. <view class="address_name">详细地址</view>
  32. <view class="address_ipt address_ipts flex">
  33. <textarea placeholder="如:街道、楼牌号等" v-model="user.detail" placeholder-style="color:#999999" maxlength="-1"></textarea>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="address_switch flex">
  38. <text>设置为默认地址</text>
  39. <switch color="#DEBB81" @change="changeSwitch" :checked="user.is_default == 1"></switch>
  40. </view>
  41. <button class="address_btn" hover-class="hover-view" @click="submit">保存收货地址</button>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. user:{
  49. username:'',
  50. mobile:'',
  51. province:'',
  52. city:'',
  53. area:'',
  54. detail:'',
  55. is_default:0,
  56. address_id:''
  57. },
  58. type:0,//添加还是编辑
  59. flag:true,//
  60. address:'',
  61. defaultRegionCode:['河南省','郑州市','中原区']
  62. };
  63. },
  64. methods:{
  65. //删除地址
  66. delAddress () {
  67. uni.showModal({
  68. content: '是否删除地址?',
  69. success: (res)=> {
  70. if (res.confirm) {
  71. this.$api.deleteAddress({address_id:this.user.address_id}).then(res=>{
  72. if (res.code === 1) {
  73. uni.showToast({title:res.msg})
  74. setTimeout(()=>{
  75. uni.navigateBack()
  76. },800)
  77. }
  78. })
  79. }
  80. }
  81. });
  82. },
  83. //返回上一级
  84. retutnTop () {
  85. uni.navigateBack()
  86. },
  87. //选择地区
  88. handleGetRegion (e) {
  89. this.user.province = e[0].name
  90. this.user.city = e[1].name
  91. this.user.area = e[2].name
  92. this.address = e[0].name + e[1].name + e[2].name
  93. },
  94. changeSwitch (e) {
  95. this.user.is_default = e.detail.value ? 1 : 0
  96. },
  97. submit () {
  98. if (!this.user.username) return uni.showToast({title:'请输入收货人姓名',icon:'none'})
  99. if (!this.user.mobile.match(/^(0|86|17951)?1[3456789]\d{9}$/)) return uni.showToast({title:'请输入正确的手机号',icon:'none'})
  100. if (!this.address) return uni.showToast({title:'请选择地区',icon:'none'})
  101. if (!this.user.detail) return uni.showToast({title:'请输入详细地址',icon:'none'})
  102. if (!this.flag) return
  103. this.flag = false
  104. uni.showLoading({title:'数据提交中'})
  105. this.$api[this.type == 0 ? 'addAddress' : 'editAddress']({...this.user}).then(res=>{
  106. uni.hideLoading()
  107. if (res.code === 1) {
  108. uni.showToast({title:res.msg})
  109. setTimeout(()=>{
  110. uni.navigateBack()
  111. },800)
  112. this.type == 1 ? uni.removeStorageSync('editAddress') : ''
  113. } else {
  114. this.flag = true
  115. }
  116. })
  117. }
  118. },
  119. onLoad ({type}) {
  120. this.type = type
  121. },
  122. onShow() {
  123. if (uni.getStorageSync('editAddress')) {
  124. this.user = JSON.parse(uni.getStorageSync('editAddress'))
  125. this.address = JSON.parse(uni.getStorageSync('editAddress')).province + JSON.parse(uni.getStorageSync('editAddress')).city + JSON.parse(uni.getStorageSync('editAddress')).area
  126. this.user.is_default = JSON.parse(uni.getStorageSync('editAddress')).is_default ? 1 : 0
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. .address_head {
  133. width: 100%;
  134. height: 88rpx;
  135. padding: 0 30rpx;
  136. background: #FFFFFF;
  137. image {
  138. width: 44rpx;
  139. height: 44rpx;
  140. }
  141. text {
  142. font-size: 36rpx;
  143. font-weight: bold;
  144. }
  145. }
  146. .address_ul {
  147. padding: 20rpx 30rpx 0 30rpx;
  148. .address_li {
  149. .address_name {
  150. font-size: 30rpx;
  151. font-weight: bold;
  152. padding: 30rpx 0;
  153. }
  154. .address_ipt {
  155. height: 80rpx;
  156. padding: 0 30rpx;
  157. background: #FFFFFF;
  158. border-radius: 10rpx;
  159. input {
  160. font-size: 28rpx;
  161. }
  162. image {
  163. width: 22rpx;
  164. height: 22rpx;
  165. }
  166. }
  167. .address_ipts {
  168. padding: 30rpx;
  169. height: 160rpx;
  170. textarea {
  171. font-size: 28rpx;
  172. }
  173. }
  174. }
  175. }
  176. .address_switch {
  177. height: 88rpx;
  178. margin: 30rpx 0 84rpx 0;
  179. padding: 0 30rpx;
  180. background: #FFFFFF;
  181. text {
  182. font-size: 30rpx;
  183. font-weight: bold;
  184. }
  185. }
  186. .address_btn {
  187. width: 690rpx;
  188. height: 98rpx;
  189. color: #333333;
  190. margin: 0 auto;
  191. font-size: 30rpx;
  192. font-weight: bold;
  193. background: #FFFFFF;
  194. box-shadow: 0rpx 0rpx 121rpx 0rpx rgba(63, 52, 2, 0.12);
  195. border-radius: 10rpx;
  196. }
  197. </style>