addressManage.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="container clearfix">
  3. <view class="add-content">
  4. <view class="text-input b-b">
  5. <input class="input" type="text" v-model="addressData.shouHuoRen" @input="onShouHuoRen" placeholder="收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="text-input 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="text-input b-b" @click="showMulLinkageThreePicker">
  11. <text class="input">
  12. {{addressData.address}}
  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.addressDetail ?addressData.addressDetail :'详细地址:如道路、门牌号、小区、楼房号、单元室等'}}</view>
  18. <textarea v-else
  19. class="textarea"
  20. type="text"
  21. v-model="addressData.addressDetail"
  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. address:'所在地区',
  60. userID: '', //用户id ,只在新增收货地址时传
  61. shouHuoRen: '', //收货人
  62. mobile:'', //收货人手机
  63. townID:'', //区ID
  64. addressDetail: '', //地址
  65. defaultFlag:0, //是否默认收货地址(0 不是默认,1 默认)
  66. },
  67. params:{} //参数
  68. }
  69. },
  70. onLoad(option){
  71. // console.log(option.data)
  72. let title = '添加新地址'
  73. if(option.type==='edit'){
  74. title = '编辑收货地址'
  75. this.isConfirm = false;
  76. this.addType = 2;
  77. this.addressData = JSON.parse(option.data)
  78. this.addressData.address = `${this.addressData.province}-${this.addressData.city}-${this.addressData.town}`
  79. this.addressData.userOrganizeID = this.userOrganizeID;
  80. this.addressData.defaultFlag = this.addressData.defaultFlag;
  81. if(this.addressData.defaultFlag == 1){
  82. this.switchDefault = true
  83. }else{
  84. this.switchDefault = false
  85. }
  86. }
  87. uni.setNavigationBarTitle({
  88. title
  89. })
  90. },
  91. methods: {
  92. switchChange(e){
  93. // console.log('==========',e.detail.value);
  94. if(e.detail.value== true){
  95. this.addressData.defaultFlag = 1;
  96. }else{
  97. this.addressData.defaultFlag = 0;
  98. }
  99. },
  100. // 三级联动选择
  101. showMulLinkageThreePicker() {
  102. this.isShowInput = true
  103. this.$refs.mpvueCityPicker.show()
  104. },
  105. onConfirm(e) {
  106. // console.log('地址',e);
  107. this.addressData.address = e.name;
  108. this.addressData.townID = e.cityCode;
  109. },
  110. //提交
  111. confirm(){
  112. let data = this.addressData;
  113. if(!data.shouHuoRen){
  114. this.$util.msg('请填写收货人');
  115. }
  116. if(data.address =='所在地区'){
  117. this.$util.msg('请选择所在地区');
  118. }
  119. if(!/(^1[0-9][0-9]{9}$)/.test(data.mobile)){
  120. this.$util.msg('请输入正确的手机号码');
  121. return;
  122. }
  123. if(this.addType ==1){
  124. this.params ={
  125. userID:data.userID ,//用户id ,只在新增收货地址时传
  126. shouHuoRen:data.shouHuoRen ,//收货人
  127. townID:data.townID,//区ID
  128. addressDetail:data.addressDetail,//地址
  129. mobile:data.mobile,//手机
  130. userOrganizeID:this.userOrganizeID,//组织ID
  131. defaultFlag:data.defaultFlag//是否默认收货地址(0 不是默认,1 默认)
  132. }
  133. this.postAddressData(this.params)
  134. }else{
  135. this.params = this.addressData;
  136. this.postAddressData(this.params)
  137. }
  138. },
  139. postAddressData(res){
  140. let self = this;
  141. self.btnText(true)
  142. authorize.getCode('weixin').then(wechatcode =>{
  143. self.$api.post('/personal/save?code='+`${wechatcode}`,JSON.stringify(res),
  144. response => {
  145. if(response.code==1){
  146. self.$util.msg(response.msg,3000);
  147. self.btnText(false)
  148. uni.navigateBack();
  149. }else{
  150. self.$util.msg(response.msg,3000);
  151. setTimeout(function(){
  152. uni.switchTab({
  153. url:'/pages/tabBar/home/home'
  154. })
  155. },1000)
  156. }
  157. }
  158. )
  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. // console.log(this.addressData.shouHuoRen)
  173. this.initInput();
  174. },
  175. onMobile(e){
  176. this.addressData.mobile = e.detail.value;
  177. // console.log(this.addressData.mobile)
  178. this.initInput();
  179. },
  180. onTextareaInput(e){
  181. this.addressData.addressDetail = e.detail.value;
  182. // console.log(this.addressData.addressDetail)
  183. this.initInput();
  184. },
  185. initInput(){
  186. if(this.addressData.shouHuoRen !== "" && this.addressData.mobile !=="" && this.addressData.addressDetail !==""){
  187. this.isConfirm =false;
  188. }else{
  189. this.isConfirm =true;
  190. }
  191. }
  192. },
  193. onShow() {
  194. this.$api.getStorage().then((resolve) =>{
  195. this.addressData.userID = resolve.userID
  196. })
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. page{
  202. height: auto;
  203. background: $bg-color;
  204. border-top: 1px solid #EBEBEB;
  205. }
  206. .add-content{
  207. width: 702rpx;
  208. padding:0 24rpx;
  209. }
  210. .icon-xiayibu{
  211. font-size: 36rpx;
  212. color: $text-color;
  213. }
  214. .text-textarea{
  215. width: 654rpx;
  216. height: 216rpx;
  217. padding: 24rpx;
  218. background: #F7F7F7;
  219. .textarea{
  220. width: 100%;
  221. height: 100%;
  222. font-size: $font-size-28;
  223. color: $text-color;
  224. z-index: 1;
  225. }
  226. .textarea.hide{
  227. opacity: 0;
  228. }
  229. .textarea.show{
  230. color: #999999;
  231. }
  232. }
  233. .default-row{
  234. background: #FFFFFF;
  235. margin-top: 16upx;
  236. .tit{
  237. font-size: $font-size-28;
  238. line-height: 40rpx;
  239. color: #333333;
  240. flex: 1;
  241. }
  242. switch{
  243. transform: translateX(16upx) scale(.9);
  244. }
  245. }
  246. .add-btn{
  247. width: 702rpx;
  248. height: 88rpx;
  249. font-size: $font-size-28;
  250. line-height: 88rpx;
  251. color: #FFFFFF;
  252. margin: 0 auto;
  253. text-align: center;
  254. background: $btn-confirm;
  255. border-radius: 14rpx;
  256. margin-top: 80rpx;
  257. }
  258. .add-btn.disabled{
  259. background: #F8F8F8;
  260. border-radius: 14rpx;
  261. }
  262. </style>