addressManage.vue 7.5 KB

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