addressManage.vue 7.8 KB

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