addressManage.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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-xiangyou"></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="#F3B574" @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.getStorage().then((resolve) =>{
  191. this.addressData.userId = resolve.userId ? resolve.userId : 0
  192. })
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. page{
  198. height: auto;
  199. background: $bg-color;
  200. // border-top: 1px solid #EBEBEB;
  201. }
  202. .placeholder{color: #b2b2b2;}
  203. .add-content{
  204. width: 702rpx;
  205. padding:0 24rpx;
  206. .input-row{
  207. align-items: center;
  208. position: relative;
  209. width: 702rpx;
  210. height: 88rpx;
  211. margin: 0 auto;
  212. border-bottom: 2rpx solid #e1e1e1;
  213. .label{
  214. width:100rpx ;
  215. line-height: 88rpx;
  216. color: #666666;
  217. font-size: $font-size-28;
  218. float: left;
  219. &.address{
  220. width: 120rpx;
  221. }
  222. }
  223. .input{
  224. width: 500rpx;
  225. height: 100%;
  226. font-size: $font-size-28;
  227. line-height: 88rpx;
  228. display: inline-block;
  229. color: #333333;
  230. float: left;
  231. padding-left: 20rpx;
  232. }
  233. &.b-b{
  234. margin: 20rpx 0;
  235. }
  236. }
  237. }
  238. .icon-xiangyou{
  239. font-size: 36rpx;
  240. color: #b2b2b2;
  241. position: absolute;
  242. right: 0;
  243. top: 10rpx;
  244. }
  245. .text-textarea{
  246. width: 654rpx;
  247. height: 147rpx;
  248. padding: 24rpx;
  249. // background: #F7F7F7;
  250. border-bottom: 2rpx solid #e1e1e1;
  251. .textarea{
  252. width: 100%;
  253. height: 100%;
  254. font-size: $font-size-28;
  255. color: $text-color;
  256. z-index: 1;
  257. }
  258. .textarea.hide{
  259. opacity: 0;
  260. }
  261. .textarea.show{
  262. color: #999999;
  263. }
  264. }
  265. .default-row{
  266. background: #FFFFFF;
  267. margin-top: 16upx;
  268. .tit{
  269. font-size: $font-size-28;
  270. line-height: 40rpx;
  271. color: #333333;
  272. flex: 1;
  273. }
  274. switch{
  275. transform: translateX(16upx) scale(.9);
  276. }
  277. }
  278. .add-btn{
  279. width: 702rpx;
  280. height:90rpx;
  281. font-size: $font-size-30;
  282. line-height: 90rpx;
  283. color: #FFFFFF;
  284. margin: 0 auto;
  285. text-align: center;
  286. background: $btn-confirm;
  287. border-radius: 45rpx;
  288. border-radius: 44rpx;
  289. margin-top: 80rpx;
  290. }
  291. .add-btn.disabled{
  292. background: #F8F8F8;
  293. border-radius: 44rpx;
  294. }
  295. </style>