addressManage.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="container clearfix">
  3. <view class="add-content">
  4. <view class="input-row b-b">
  5. <view class="label">收货人:</view>
  6. <input class="input" type="text" v-model="addressData.receiver" @input="onShouHuoRen" placeholder="请输入收货人姓名" placeholder-class="placeholder" />
  7. </view>
  8. <view class="input-row b-b">
  9. <view class="label">手机号:</view>
  10. <input class="input" type="number" maxlength="11" v-model="addressData.mobile" @input="onMobile" placeholder="请输入手机号码" placeholder-class="placeholder" />
  11. </view>
  12. <view class="input-row b-b" @click="showMulLinkageThreePicker">
  13. <view class="label address">所在地区:</view>
  14. <text class="input" :style="addressData.allAddress=='请选择收货地区'?'color:#b2b2b2':''">
  15. {{addressData.allAddress}}
  16. </text>
  17. <text class="iconfont icon-xiayibu"></text>
  18. </view>
  19. <view class="text-textarea b-b">
  20. <view class="textarea show" v-if="isShowInput">
  21. {{addressData.address ? addressData.address :'详细地址:如道路、门牌号、小区、楼房号、单元室等'}}
  22. </view>
  23. <textarea v-else
  24. class="textarea"
  25. type="text"
  26. v-model="addressData.address"
  27. placeholder="详细地址:如道路、门牌号、小区、楼房号、单元室等"
  28. placeholder-class="placeholder"
  29. maxlength="50"
  30. @input="onTextareaInput"
  31. :class="isShowInput ? '':''"
  32. />
  33. </view>
  34. <view class="text-input default-row">
  35. <text class="tit">设为默认地址</text>
  36. <switch :checked="switchDefault" color="#5FB00A" @change="switchChange" style="transform:scale(0.8)" />
  37. </view>
  38. <button class="add-btn" :disabled="isConfirm" :class="[isConfirm == true ? 'disabled':'']" @click="confirm">{{buttonText}}</button>
  39. </view>
  40. <mpvue-city-picker :themeColor="themeColor"
  41. ref="mpvueCityPicker"
  42. :pickerValueDefault="cityPickerValueDefault"
  43. @onCancel="onCancel"
  44. @onConfirm="onConfirm">
  45. </mpvue-city-picker>
  46. </view>
  47. </template>
  48. <script>
  49. import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue'
  50. import authorize from '@/common/config/authorize.js'
  51. export default {
  52. components:{
  53. mpvueCityPicker
  54. },
  55. data() {
  56. return {
  57. buttonText:'保存',
  58. addType:1, //记录添加地址的类型
  59. isConfirm:true,
  60. isShowInput:false,
  61. switchDefault:false,
  62. addressData:{
  63. addressId:'',
  64. allAddress:'请选择收货地区',
  65. userId: '', //用户id ,只在新增收货地址时传
  66. receiver: '', //收货人
  67. mobile:'', //收货人手机
  68. townId:'', //区ID
  69. address: '', //地址
  70. defaultFlag:0, //是否默认收货地址(0 不是默认,1 默认)
  71. },
  72. params:{},//参数
  73. isSelect:false
  74. }
  75. },
  76. onLoad(option){
  77. let title = '添加新地址'
  78. if(option.type==='edit'){
  79. title = '编辑收货地址'
  80. this.isConfirm = false
  81. this.addType = 2
  82. let optionData = JSON.parse(option.data)
  83. this.addressData.allAddress = `${optionData.province}-${optionData.city}-${optionData.town}`
  84. this.addressData.address = optionData.address?optionData.address:''
  85. this.addressData.defaultFlag = optionData.defaultFlag
  86. this.addressData.userId = optionData.userId
  87. this.addressData.mobile = optionData.mobile
  88. this.addressData.townId = optionData.townId
  89. this.addressData.addressId = optionData.addressId
  90. this.addressData.receiver = optionData.receiver
  91. if(this.addressData.defaultFlag == 1){
  92. this.switchDefault = true
  93. }else{
  94. this.switchDefault = false
  95. }
  96. }
  97. if (option.type == 'select') {
  98. this.isSelect = true
  99. }
  100. uni.setNavigationBarTitle({
  101. title
  102. })
  103. },
  104. methods: {
  105. switchChange(e){
  106. if(e.detail.value== true){
  107. this.addressData.defaultFlag = '1'
  108. }else{
  109. this.addressData.defaultFlag = '0'
  110. }
  111. },
  112. // 三级联动选择
  113. showMulLinkageThreePicker() {
  114. this.isShowInput = true
  115. this.$refs.mpvueCityPicker.show()
  116. },
  117. onConfirm(e) {
  118. console.log(e)
  119. this.addressData.allAddress = e.name
  120. this.addressData.townId = e.townCode
  121. this.initInput()
  122. },
  123. //提交
  124. confirm(){
  125. let data = this.addressData
  126. if(!data.receiver){
  127. this.$util.msg('请填写收货人')
  128. }
  129. if(data.address =='所在地区'){
  130. this.$util.msg('请选择所在地区')
  131. }
  132. if(!/(^1[0-9][0-9]{9}$)/.test(data.mobile)){
  133. this.$util.msg('请输入正确的手机号码')
  134. return
  135. }
  136. if(this.addType ==1){
  137. this.params ={
  138. userId:data.userId , //用户id ,只在新增收货地址时传
  139. receiver:data.receiver ,//收货人
  140. townId:data.townId, //区ID
  141. address:data.address,//地址
  142. mobile:data.mobile, //手机
  143. defaultFlag:data.defaultFlag//是否默认收货地址(0 不是默认,1 默认)
  144. }
  145. this.postAddressData(this.params)
  146. }else{
  147. this.params = this.addressData
  148. this.postAddressData(this.params)
  149. }
  150. },
  151. async postAddressData(params) {
  152. try{
  153. this.btnText(true)
  154. const res = await this.UserService.AddressSave(params)
  155. const data = res.data
  156. this.$util.msg('保存成功', 1500, true, 'success')
  157. this.btnText(false)
  158. if(this.isSelect){
  159. console.log('222222222222')
  160. uni.setStorageSync('selectAddress', data)
  161. let pages = getCurrentPages()
  162. let prevPage = pages[pages.length - 2] //上一个页面
  163. prevPage.setData({ select: 'select' })
  164. }
  165. uni.navigateBack()
  166. }catch(error){
  167. this.$util.msg(error.msg, 2000)
  168. this.btnText(false)
  169. }
  170. },
  171. btnText(flg){
  172. if(flg){
  173. this.isConfirm = true
  174. this.buttonText = '保存中...'
  175. }else{
  176. this.isConfirm = false
  177. this.buttonText = '保存'
  178. }
  179. },
  180. onShouHuoRen(e){
  181. this.addressData.receiver = e.detail.value
  182. this.initInput()
  183. },
  184. onMobile(e){
  185. this.addressData.mobile = e.detail.value
  186. this.initInput()
  187. },
  188. onTextareaInput(e){
  189. this.addressData.address = e.detail.value
  190. this.initInput()
  191. },
  192. initInput(){
  193. if(this.addressData.receiver !== '' && this.addressData.mobile !=='' && this.addressData.address !=='' && this.addressData.townId!==''){
  194. this.isConfirm =false
  195. }else{
  196. this.isConfirm =true
  197. }
  198. }
  199. },
  200. onShow() {
  201. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  202. this.addressData.userId = resolve.userId ? resolve.userId : 0
  203. console.log('userId',this.addressData.userId)
  204. })
  205. }
  206. }
  207. </script>
  208. <style lang="scss">
  209. page{
  210. height: auto;
  211. background: $bg-color;
  212. // border-top: 1px solid #EBEBEB;
  213. }
  214. .placeholder{color: #b2b2b2;}
  215. .add-content{
  216. width: 702rpx;
  217. padding:0 24rpx;
  218. .input-row{
  219. align-items: center;
  220. position: relative;
  221. width: 702rpx;
  222. height: 88rpx;
  223. margin: 0 auto;
  224. border-bottom: 2rpx solid #e1e1e1;
  225. .label{
  226. width:100rpx ;
  227. line-height: 88rpx;
  228. color: #666666;
  229. font-size: $font-size-28;
  230. float: left;
  231. &.address{
  232. width: 120rpx;
  233. }
  234. }
  235. .input{
  236. width: 500rpx;
  237. height: 100%;
  238. font-size: $font-size-28;
  239. line-height: 88rpx;
  240. display: inline-block;
  241. color: #333333;
  242. float: left;
  243. padding-left: 20rpx;
  244. }
  245. &.b-b{
  246. margin: 20rpx 0;
  247. }
  248. }
  249. }
  250. .icon-xiayibu{
  251. font-size: 36rpx;
  252. color: #b2b2b2;
  253. position: absolute;
  254. right: 0;
  255. top: 10rpx;
  256. }
  257. .text-textarea{
  258. width: 654rpx;
  259. height: 147rpx;
  260. padding: 24rpx;
  261. // background: #F7F7F7;
  262. border-bottom: 2rpx solid #e1e1e1;
  263. .textarea{
  264. width: 100%;
  265. height: 100%;
  266. font-size: $font-size-28;
  267. color: $text-color;
  268. z-index: 1;
  269. }
  270. .textarea.hide{
  271. opacity: 0;
  272. }
  273. .textarea.show{
  274. color: #999999;
  275. }
  276. }
  277. .default-row{
  278. background: #FFFFFF;
  279. margin-top: 16upx;
  280. .tit{
  281. font-size: $font-size-28;
  282. line-height: 40rpx;
  283. color: #333333;
  284. flex: 1;
  285. }
  286. switch{
  287. transform: translateX(16upx) scale(.9);
  288. }
  289. }
  290. .add-btn{
  291. width: 702rpx;
  292. height:90rpx;
  293. font-size: $font-size-30;
  294. line-height: 90rpx;
  295. color: #FFFFFF;
  296. margin: 0 auto;
  297. text-align: center;
  298. background: $btn-confirm;
  299. border-radius: 45rpx;
  300. border-radius: 44rpx;
  301. margin-top: 80rpx;
  302. }
  303. .add-btn.disabled{
  304. background: #F8F8F8;
  305. border-radius: 44rpx;
  306. }
  307. </style>