addressManage.vue 7.9 KB

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