addSite.vue 5.4 KB

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