addressManage.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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">收货地址</view>
  14. <text class="input">
  15. {{addressData.allAddress}}
  16. </text>
  17. <text class="iconfont icon-chakangengduo"></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="#333333" @change="switchChange" style="transform:scale(0.6)" />
  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
  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(optionData.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. this.addressData.allAddress = e.name;
  114. this.addressData.townID = e.townCode;
  115. this.initInput();
  116. },
  117. //提交
  118. confirm(){
  119. if(!this.addressData.shouHuoRen){
  120. this.$util.msg('请填写收货人');
  121. }
  122. if(this.addressData.address =='请选择所在地区'){
  123. this.$util.msg('请选择所在地区');
  124. }
  125. if(!/(^1[0-9][0-9]{9}$)/.test(this.addressData.mobile)){
  126. this.$util.msg('请输入正确的手机号码');
  127. return;
  128. }
  129. if(this.addType ==1){
  130. this.params ={
  131. userID:this.addressData.userID, //用户id ,只在新增收货地址时传
  132. shouHuoRen:this.addressData.shouHuoRen ,//收货人
  133. townID:this.addressData.townID, //区ID
  134. address:this.addressData.address, //地址
  135. mobile:this.addressData.mobile, //手机
  136. defaultFlag:this.addressData.defaultFlag//是否默认收货地址(0 不是默认,1 默认)
  137. }
  138. this.postAddressData(this.params)
  139. }else{
  140. this.params = this.addressData;
  141. this.postAddressData(this.params)
  142. }
  143. },
  144. postAddressData(res){
  145. this.btnText(true)
  146. this.UserService.AddNewAddress(res).then( response=>{
  147. this.$util.msg('保存成功',2000,true,'success')
  148. this.btnText(false)
  149. setTimeout(()=>{
  150. uni.navigateBack();
  151. },2000)
  152. }).catch(error =>{
  153. this.$util.msg(error.msg,2000);
  154. setTimeout(function(){
  155. uni.switchTab({
  156. url:'/seller/pages/index/index'
  157. })
  158. },1000)
  159. })
  160. },
  161. btnText(flg){
  162. if(flg){
  163. this.isConfirm = true;
  164. this.buttonText = '保存中...'
  165. }else{
  166. this.isConfirm = false;
  167. this.buttonText = '保存'
  168. }
  169. },
  170. onShouHuoRen(e){
  171. this.addressData.shouHuoRen = e.detail.value;
  172. this.initInput();
  173. },
  174. onMobile(e){
  175. this.addressData.mobile = e.detail.value;
  176. this.initInput();
  177. },
  178. onTextareaInput(e){
  179. this.addressData.address = e.detail.value;
  180. this.initInput();
  181. },
  182. initInput(){
  183. if(this.addressData.shouHuoRen !== "" && this.addressData.mobile !=="" && this.addressData.address !=="" && this.addressData.townID!==""){
  184. this.isConfirm =false;
  185. }else{
  186. this.isConfirm =true;
  187. }
  188. }
  189. },
  190. onShow() {
  191. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  192. this.addressData.userID = resolve.userID
  193. })
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. page{
  199. height: auto;
  200. background: $bg-color;
  201. }
  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. margin: 0 auto;
  212. border-bottom: 2rpx solid #e1e1e1;
  213. .label{
  214. font-size: $font-size-28;
  215. color: #666666;
  216. line-height: 88rpx;
  217. flex: 2;
  218. }
  219. .input{
  220. height: 100%;
  221. font-size: $font-size-28;
  222. line-height: 88rpx;
  223. color: #333333;
  224. flex:7;
  225. box-sizing: border-box;
  226. padding-left: 20rpx;
  227. }
  228. &.b-b{
  229. margin: 20rpx 0;
  230. }
  231. }
  232. }
  233. .icon-chakangengduo{
  234. font-size: 36rpx;
  235. color: #b2b2b2;
  236. position: absolute;
  237. right: 0;
  238. }
  239. .text-textarea{
  240. width: 100%;
  241. height: 146rpx;
  242. border-bottom: 2rpx solid #e1e1e1;
  243. .textarea{
  244. width: 100%;
  245. height: 100%;
  246. font-size: $font-size-28;
  247. color: $text-color;
  248. z-index: 1;
  249. }
  250. .textarea.hide{
  251. opacity: 0;
  252. }
  253. .textarea.show{
  254. color: #999999;
  255. }
  256. }
  257. .default-row{
  258. background: #FFFFFF;
  259. margin-top: 16upx;
  260. padding: 24rpx 24rpx 24rpx 0;
  261. .tit{
  262. font-size: $font-size-28;
  263. line-height: 40rpx;
  264. color: #666666;
  265. flex: 1;
  266. }
  267. switch{
  268. transform: translateX(16upx) scale(.9);
  269. }
  270. }
  271. .add-btn{
  272. width: 600rpx;
  273. height: 90rpx;
  274. font-size: $font-size-28;
  275. line-height: 90rpx;
  276. color: #FFFFFF;
  277. margin: 0 auto;
  278. text-align: center;
  279. background: $btn-confirm;
  280. border-radius: 45rpx;
  281. margin-top: 80rpx;
  282. }
  283. .add-btn.disabled{
  284. background: #e1e1e1;
  285. border-radius: 45rpx;
  286. }
  287. </style>