addressManage.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="container clearfix">
  3. <view class="add-content">
  4. <view class="input-row b-b">
  5. <input class="input" type="text" v-model="addressData.shouHuoRen" @input="onShouHuoRen" placeholder="收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="input-row b-b">
  8. <input class="input" type="number" maxlength="11" v-model="addressData.mobile" @input="onMobile" placeholder="手机号码" placeholder-class="placeholder" />
  9. </view>
  10. <view class="input-row b-b" @click="showMulLinkageThreePicker">
  11. <text class="input">
  12. {{addressData.allAddress}}
  13. </text>
  14. <text class="iconfont icon-xiayibu"></text>
  15. </view>
  16. <view class="text-textarea b-b">
  17. <view class="textarea show" v-if="isShowInput">{{addressData.address ?addressData.address :'详细地址:如道路、门牌号、小区、楼房号、单元室等'}}</view>
  18. <textarea v-else
  19. class="textarea"
  20. type="text"
  21. v-model="addressData.address"
  22. placeholder="详细地址:如道路、门牌号、小区、楼房号、单元室等"
  23. placeholder-class="placeholder"
  24. maxlength="50"
  25. @input="onTextareaInput"
  26. :class="isShowInput ? '':''"
  27. />
  28. </view>
  29. <view class="text-input default-row">
  30. <text class="tit">设为默认地址</text>
  31. <switch :checked="switchDefault" color="#5FB00A" @change="switchChange" style="transform:scale(0.8)" />
  32. </view>
  33. <button class="add-btn" :disabled="isConfirm" :class="[isConfirm == true ? 'disabled':'']" @click="confirm">{{buttonText}}</button>
  34. </view>
  35. <mpvue-city-picker :themeColor="themeColor"
  36. ref="mpvueCityPicker"
  37. :pickerValueDefault="cityPickerValueDefault"
  38. @onCancel="onCancel"
  39. @onConfirm="onConfirm">
  40. </mpvue-city-picker>
  41. </view>
  42. </template>
  43. <script>
  44. import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue'
  45. import authorize from '@/common/config/authorize.js'
  46. import { addNewAddress,updateAddress } from '@/api/cart.js'
  47. export default {
  48. components:{
  49. mpvueCityPicker
  50. },
  51. data() {
  52. return {
  53. buttonText:'保存',
  54. addType:1, //记录添加地址的类型
  55. isConfirm:true,
  56. isShowInput:false,
  57. switchDefault:false,
  58. addressData:{
  59. addressID:'',
  60. allAddress:'所在地区',
  61. userID: '', //用户id ,只在新增收货地址时传
  62. shouHuoRen: '', //收货人
  63. mobile:'', //收货人手机
  64. townID:'', //区ID
  65. address: '', //地址
  66. defaultFlag:0, //是否默认收货地址(0 不是默认,1 默认)
  67. },
  68. params:{} //参数
  69. }
  70. },
  71. onLoad(option){
  72. let title = '添加新地址'
  73. if(option.type==='edit'){
  74. title = '编辑收货地址'
  75. this.isConfirm = false;
  76. this.addType = 2;
  77. let optionData = JSON.parse(option.data)
  78. this.addressData.allAddress = `${optionData.province}-${optionData.city}-${optionData.town}`
  79. this.addressData.address = optionData.address
  80. this.addressData.defaultFlag = optionData.defaultFlag;
  81. this.addressData.userID = optionData.userID;
  82. this.addressData.mobile = optionData.mobile;
  83. this.addressData.townID = optionData.townID;
  84. this.addressData.addressID = optionData.addressID;
  85. this.addressData.shouHuoRen = optionData.shouHuoRen;
  86. this.addressData.addressID = optionData.addressID;
  87. if(optionData.defaultFlag == 1){
  88. this.switchDefault = true
  89. }else{
  90. this.switchDefault = false
  91. }
  92. }
  93. uni.setNavigationBarTitle({
  94. title
  95. })
  96. },
  97. methods: {
  98. switchChange(e){
  99. if(e.detail.value== true){
  100. this.addressData.defaultFlag = 1;
  101. }else{
  102. this.addressData.defaultFlag = 0;
  103. }
  104. },
  105. // 三级联动选择
  106. showMulLinkageThreePicker() {
  107. this.isShowInput = true
  108. this.$refs.mpvueCityPicker.show()
  109. },
  110. onConfirm(e) {
  111. this.addressData.allAddress = e.name;
  112. this.addressData.townID = e.townCode;
  113. this.initInput();
  114. },
  115. //提交
  116. confirm(){
  117. if(!this.addressData.shouHuoRen){
  118. this.$util.msg('请填写收货人');
  119. }
  120. if(this.addressData.address =='所在地区'){
  121. this.$util.msg('请选择所在地区');
  122. }
  123. if(!/(^1[0-9][0-9]{9}$)/.test(this.addressData.mobile)){
  124. this.$util.msg('请输入正确的手机号码');
  125. return;
  126. }
  127. if(this.addType ==1){
  128. this.params ={
  129. userID:this.addressData.userID, //用户id ,只在新增收货地址时传
  130. shouHuoRen:this.addressData.shouHuoRen ,//收货人
  131. townID:this.addressData.townID, //区ID
  132. address:this.addressData.address, //地址
  133. mobile:this.addressData.mobile, //手机
  134. defaultFlag:this.addressData.defaultFlag//是否默认收货地址(0 不是默认,1 默认)
  135. }
  136. this.postAddressData(this.params)
  137. }else{
  138. this.params = this.addressData;
  139. this.postAddressData(this.params)
  140. }
  141. },
  142. postAddressData(res){
  143. this.btnText(true)
  144. addNewAddress(res).then( response=>{
  145. this.$util.msg('保存成功',2000,true,'success')
  146. this.btnText(false)
  147. setTimeout(()=>{
  148. uni.navigateBack();
  149. },2000)
  150. }).catch(error =>{
  151. this.$util.msg(error.msg,2000);
  152. setTimeout(function(){
  153. uni.switchTab({
  154. url:'/seller/pages/index/index'
  155. })
  156. },1000)
  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.getComStorage('orderUserInfo').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. .add-content{
  202. width: 702rpx;
  203. padding:0 24rpx;
  204. .input-row{
  205. display: flex;
  206. align-items: center;
  207. position: relative;
  208. width: 654rpx;
  209. height: 88rpx;
  210. padding:0 24rpx;
  211. margin: 0 auto;
  212. background: #F7F7F7;
  213. border-radius: 14rpx;
  214. .input{
  215. width: 100%;
  216. height: 100%;
  217. background: #F7F7F7;
  218. font-size: $font-size-28;
  219. line-height: 88rpx;
  220. color: #333333;
  221. }
  222. &.b-b{
  223. margin: 32rpx 0;
  224. }
  225. }
  226. }
  227. .icon-xiayibu{
  228. font-size: 36rpx;
  229. color: $text-color;
  230. }
  231. .text-textarea{
  232. width: 654rpx;
  233. height: 216rpx;
  234. padding: 24rpx;
  235. background: #F7F7F7;
  236. .textarea{
  237. width: 100%;
  238. height: 100%;
  239. font-size: $font-size-28;
  240. color: $text-color;
  241. z-index: 1;
  242. }
  243. .textarea.hide{
  244. opacity: 0;
  245. }
  246. .textarea.show{
  247. color: #999999;
  248. }
  249. }
  250. .default-row{
  251. background: #FFFFFF;
  252. margin-top: 16upx;
  253. .tit{
  254. font-size: $font-size-28;
  255. line-height: 40rpx;
  256. color: #333333;
  257. flex: 1;
  258. }
  259. switch{
  260. transform: translateX(16upx) scale(.9);
  261. }
  262. }
  263. .add-btn{
  264. width: 702rpx;
  265. height: 88rpx;
  266. font-size: $font-size-28;
  267. line-height: 88rpx;
  268. color: #FFFFFF;
  269. margin: 0 auto;
  270. text-align: center;
  271. background: $btn-confirm;
  272. border-radius: 14rpx;
  273. margin-top: 80rpx;
  274. }
  275. .add-btn.disabled{
  276. background: #F8F8F8;
  277. border-radius: 14rpx;
  278. }
  279. </style>