addressManage.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. }
  74. },
  75. onLoad(option){
  76. let title = '添加新地址'
  77. if(option.type==='edit'){
  78. title = '编辑收货地址'
  79. this.isConfirm = false
  80. this.addType = 2
  81. let optionData = JSON.parse(option.data)
  82. this.addressData.allAddress = `${optionData.province}-${optionData.city}-${optionData.town}`
  83. this.addressData.address = optionData.address?optionData.address:''
  84. this.addressData.defaultFlag = optionData.defaultFlag
  85. this.addressData.userId = optionData.userId
  86. this.addressData.mobile = optionData.mobile
  87. this.addressData.townId = optionData.townId
  88. this.addressData.addressId = optionData.addressId
  89. this.addressData.receiver = optionData.receiver
  90. if(this.addressData.defaultFlag == 1){
  91. this.switchDefault = true
  92. }else{
  93. this.switchDefault = false
  94. }
  95. }
  96. uni.setNavigationBarTitle({
  97. title
  98. })
  99. },
  100. methods: {
  101. switchChange(e){
  102. if(e.detail.value== true){
  103. this.addressData.defaultFlag = '1'
  104. }else{
  105. this.addressData.defaultFlag = '0'
  106. }
  107. },
  108. // 三级联动选择
  109. showMulLinkageThreePicker() {
  110. this.isShowInput = true
  111. this.$refs.mpvueCityPicker.show()
  112. },
  113. onConfirm(e) {
  114. console.log(e)
  115. this.addressData.allAddress = e.name
  116. this.addressData.townId = e.townCode
  117. this.initInput()
  118. },
  119. //提交
  120. confirm(){
  121. let data = this.addressData
  122. if(!data.receiver){
  123. this.$util.msg('请填写收货人')
  124. }
  125. if(data.address =='所在地区'){
  126. this.$util.msg('请选择所在地区')
  127. }
  128. if(!/(^1[0-9][0-9]{9}$)/.test(data.mobile)){
  129. this.$util.msg('请输入正确的手机号码')
  130. return
  131. }
  132. if(this.addType ==1){
  133. this.params ={
  134. userId:data.userId , //用户id ,只在新增收货地址时传
  135. receiver:data.receiver ,//收货人
  136. townId:data.townId, //区ID
  137. address:data.address,//地址
  138. mobile:data.mobile, //手机
  139. defaultFlag:data.defaultFlag//是否默认收货地址(0 不是默认,1 默认)
  140. }
  141. this.postAddressData(this.params)
  142. }else{
  143. this.params = this.addressData
  144. this.postAddressData(this.params)
  145. }
  146. },
  147. postAddressData(params){
  148. this.btnText(true)
  149. this.UserService.AddressSave(params).then( response=>{
  150. this.$util.msg('保存成功',1500,true,'success')
  151. this.btnText(false)
  152. setTimeout(()=>{
  153. uni.navigateBack()
  154. },2000)
  155. }).catch(error =>{
  156. this.$util.msg(error.msg,2000)
  157. this.btnText(false)
  158. })
  159. },
  160. btnText(flg){
  161. if(flg){
  162. this.isConfirm = true
  163. this.buttonText = '保存中...'
  164. }else{
  165. this.isConfirm = false
  166. this.buttonText = '保存'
  167. }
  168. },
  169. onShouHuoRen(e){
  170. this.addressData.receiver = e.detail.value
  171. this.initInput()
  172. },
  173. onMobile(e){
  174. this.addressData.mobile = e.detail.value
  175. this.initInput()
  176. },
  177. onTextareaInput(e){
  178. this.addressData.address = e.detail.value
  179. this.initInput()
  180. },
  181. initInput(){
  182. if(this.addressData.receiver !== '' && this.addressData.mobile !=='' && this.addressData.address !=='' && this.addressData.townId!==''){
  183. this.isConfirm =false
  184. }else{
  185. this.isConfirm =true
  186. }
  187. }
  188. },
  189. onShow() {
  190. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  191. this.addressData.userId = resolve.userID ? resolve.userID : 0
  192. console.log('userID',this.addressData.userId)
  193. })
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. page{
  199. height: auto;
  200. background: $bg-color;
  201. // border-top: 1px solid #EBEBEB;
  202. }
  203. .placeholder{color: #b2b2b2;}
  204. .add-content{
  205. width: 702rpx;
  206. padding:0 24rpx;
  207. .input-row{
  208. align-items: center;
  209. position: relative;
  210. width: 702rpx;
  211. height: 88rpx;
  212. margin: 0 auto;
  213. border-bottom: 2rpx solid #e1e1e1;
  214. .label{
  215. width:100rpx ;
  216. line-height: 88rpx;
  217. color: #666666;
  218. font-size: $font-size-28;
  219. float: left;
  220. &.address{
  221. width: 120rpx;
  222. }
  223. }
  224. .input{
  225. width: 500rpx;
  226. height: 100%;
  227. font-size: $font-size-28;
  228. line-height: 88rpx;
  229. display: inline-block;
  230. color: #333333;
  231. float: left;
  232. padding-left: 20rpx;
  233. }
  234. &.b-b{
  235. margin: 20rpx 0;
  236. }
  237. }
  238. }
  239. .icon-xiayibu{
  240. font-size: 36rpx;
  241. color: #b2b2b2;
  242. position: absolute;
  243. right: 0;
  244. top: 10rpx;
  245. }
  246. .text-textarea{
  247. width: 654rpx;
  248. height: 147rpx;
  249. padding: 24rpx;
  250. // background: #F7F7F7;
  251. border-bottom: 2rpx solid #e1e1e1;
  252. .textarea{
  253. width: 100%;
  254. height: 100%;
  255. font-size: $font-size-28;
  256. color: $text-color;
  257. z-index: 1;
  258. }
  259. .textarea.hide{
  260. opacity: 0;
  261. }
  262. .textarea.show{
  263. color: #999999;
  264. }
  265. }
  266. .default-row{
  267. background: #FFFFFF;
  268. margin-top: 16upx;
  269. .tit{
  270. font-size: $font-size-28;
  271. line-height: 40rpx;
  272. color: #333333;
  273. flex: 1;
  274. }
  275. switch{
  276. transform: translateX(16upx) scale(.9);
  277. }
  278. }
  279. .add-btn{
  280. width: 702rpx;
  281. height:90rpx;
  282. font-size: $font-size-30;
  283. line-height: 90rpx;
  284. color: #FFFFFF;
  285. margin: 0 auto;
  286. text-align: center;
  287. background: $btn-confirm;
  288. border-radius: 45rpx;
  289. border-radius: 44rpx;
  290. margin-top: 80rpx;
  291. }
  292. .add-btn.disabled{
  293. background: #F8F8F8;
  294. border-radius: 44rpx;
  295. }
  296. </style>