addressManage.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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
  7. class="input"
  8. type="text"
  9. v-model="addressData.shouHuoRen"
  10. @input="onShouHuoRen"
  11. placeholder="请输入收货人姓名"
  12. placeholder-class="placeholder"
  13. />
  14. </view>
  15. <view class="input-row b-b">
  16. <view class="label">联系方式</view>
  17. <input
  18. class="input"
  19. type="number"
  20. maxlength="11"
  21. v-model="addressData.mobile"
  22. @input="onMobile"
  23. placeholder="请输入联系方式"
  24. placeholder-class="placeholder"
  25. />
  26. </view>
  27. <view class="input-row b-b" @click="showMulLinkageThreePicker">
  28. <view class="label">收货地址</view> <text class="input"> {{ addressData.allAddress }} </text>
  29. <text class="iconfont icon-chakangengduo"></text>
  30. </view>
  31. <view class="text-textarea b-b">
  32. <view class="textarea show" v-if="isShowInput">{{
  33. addressData.address ? addressData.address : '详细地址:如道路、门牌号、小区、楼房号、单元室等'
  34. }}</view>
  35. <textarea
  36. v-else
  37. class="textarea"
  38. type="text"
  39. v-model="addressData.address"
  40. placeholder="详细地址:如道路、门牌号、小区、楼房号、单元室等"
  41. placeholder-class="placeholder"
  42. maxlength="50"
  43. @input="onTextareaInput"
  44. :class="isShowInput ? '' : ''"
  45. />
  46. </view>
  47. <view class="text-input default-row">
  48. <text class="tit">设为默认地址</text>
  49. <switch :checked="switchDefault" color="#ff457b" @change="switchChange" style="transform:scale(0.6)" />
  50. </view>
  51. <button
  52. class="add-btn"
  53. :disabled="isConfirm"
  54. :class="[isConfirm == true ? 'disabled' : '']"
  55. @click="confirm"
  56. >
  57. {{ buttonText }}
  58. </button>
  59. </view>
  60. <city-picker
  61. :themeColor="themeColor"
  62. ref="mpvueCityPicker"
  63. :pickerValueDefault="cityPickerValueDefault"
  64. @onCancel="onCancel"
  65. @onConfirm="onConfirm"
  66. >
  67. </city-picker>
  68. </view>
  69. </template>
  70. <script>
  71. import CityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue'
  72. export default {
  73. components:{
  74. CityPicker
  75. },
  76. data() {
  77. return {
  78. buttonText: '保存',
  79. addType: 1, //记录添加地址的类型
  80. isConfirm: true,
  81. isShowInput: false,
  82. switchDefault: false,
  83. addressData: {
  84. addressId: '',
  85. allAddress: '请选择所在地区',
  86. userId: '', //用户id ,只在新增收货地址时传
  87. shouHuoRen: '', //收货人
  88. mobile: '', //收货人手机
  89. townId: '', //区ID
  90. address: '', //地址
  91. defaultFlag: 0 //是否默认收货地址(0 不是默认,1 默认)
  92. },
  93. params: {} //参数
  94. }
  95. },
  96. onLoad(option) {
  97. let title = '添加新地址'
  98. if (option.type === 'edit') {
  99. title = '编辑收货地址'
  100. this.isConfirm = false
  101. this.addType = 2
  102. let optionData = JSON.parse(option.data)
  103. console.log(optionData)
  104. // 设置默认值
  105. this.addressData.allAddress = `${optionData.provinceName}-${optionData.cityName}-${optionData.townName}`
  106. this.addressData.address = optionData.address
  107. this.addressData.defaultFlag = optionData.defaultFlag
  108. this.addressData.userId = optionData.userId
  109. this.addressData.mobile = optionData.mobile
  110. this.addressData.townId = optionData.townId
  111. this.addressData.addressId = optionData.addressId
  112. this.addressData.shouHuoRen = optionData.shouHuoRen
  113. this.addressData.addressId = optionData.addressId
  114. if (optionData.defaultFlag == 1) {
  115. this.switchDefault = true
  116. } else {
  117. this.switchDefault = false
  118. }
  119. }
  120. uni.setNavigationBarTitle({
  121. title
  122. })
  123. },
  124. methods: {
  125. switchChange(e) {
  126. if (e.detail.value == true) {
  127. this.addressData.defaultFlag = 1
  128. } else {
  129. this.addressData.defaultFlag = 0
  130. }
  131. },
  132. // 三级联动选择
  133. showMulLinkageThreePicker() {
  134. this.isShowInput = true
  135. this.$refs.mpvueCityPicker.show()
  136. },
  137. onConfirm(e) {
  138. this.addressData.allAddress = e.name
  139. this.addressData.townId = e.townCode
  140. console.log(e)
  141. this.initInput()
  142. },
  143. //提交
  144. confirm() {
  145. if (!this.addressData.shouHuoRen) {
  146. this.$util.msg('请填写收货人')
  147. }
  148. if (this.addressData.address == '请选择所在地区') {
  149. this.$util.msg('请选择所在地区')
  150. }
  151. if (!/(^1[0-9][0-9]{9}$)/.test(this.addressData.mobile)) {
  152. this.$util.msg('请输入正确的手机号码')
  153. return
  154. }
  155. if (this.addType == 1) {
  156. this.params = {
  157. // 测试id
  158. userId: this.addressData.userId, //用户id ,只在新增收货地址时传
  159. shouHuoRen: this.addressData.shouHuoRen, //收货人
  160. townId: this.addressData.townId, //区ID
  161. address: this.addressData.address, //地址
  162. mobile: this.addressData.mobile, //手机
  163. defaultFlag: this.addressData.defaultFlag //是否默认收货地址(0 不是默认,1 默认)
  164. }
  165. this.postAddressData(this.params)
  166. } else {
  167. this.params = this.addressData
  168. this.postAddressData(this.params)
  169. }
  170. },
  171. postAddressData(params) {
  172. this.btnText(true)
  173. // 保存地址
  174. this.UserService.AddOtherSaveAddress(params)
  175. .then(response => {
  176. this.$util.msg('保存成功', 2000, true, 'success')
  177. this.btnText(false)
  178. setTimeout(() => {
  179. uni.navigateBack()
  180. }, 2000)
  181. })
  182. .catch(error => {
  183. this.$util.msg(error.msg, 2000)
  184. setTimeout(function() {
  185. uni.switchTab({
  186. url: '/seller/pages/index/index'
  187. })
  188. }, 1000)
  189. })
  190. },
  191. btnText(flg) {
  192. if (flg) {
  193. this.isConfirm = true
  194. this.buttonText = '保存中...'
  195. } else {
  196. this.isConfirm = false
  197. this.buttonText = '保存'
  198. }
  199. },
  200. onShouHuoRen(e) {
  201. this.addressData.shouHuoRen = e.detail.value
  202. this.initInput()
  203. },
  204. onMobile(e) {
  205. this.addressData.mobile = e.detail.value
  206. this.initInput()
  207. },
  208. onTextareaInput(e) {
  209. this.addressData.address = e.detail.value
  210. this.initInput()
  211. },
  212. initInput() {
  213. if (
  214. this.addressData.shouHuoRen !== '' &&
  215. this.addressData.mobile !== '' &&
  216. this.addressData.address !== '' &&
  217. this.addressData.townId !== ''
  218. ) {
  219. this.isConfirm = false
  220. } else {
  221. this.isConfirm = true
  222. }
  223. }
  224. },
  225. onShow() {
  226. this.$api.getComStorage('userInfo').then(resolve => {
  227. this.addressData.userId = resolve.userId ? resolve.userId : 0
  228. })
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. page {
  234. height: auto;
  235. background: $bg-color;
  236. }
  237. .add-content {
  238. width: 702rpx;
  239. padding: 0 24rpx;
  240. .input-row {
  241. display: flex;
  242. align-items: center;
  243. position: relative;
  244. width: 702rpx;
  245. height: 88rpx;
  246. margin: 0 auto;
  247. border-bottom: 2rpx solid #e1e1e1;
  248. .label {
  249. font-size: $font-size-28;
  250. color: #666666;
  251. line-height: 88rpx;
  252. flex: 2;
  253. }
  254. .input {
  255. height: 100%;
  256. font-size: $font-size-28;
  257. line-height: 88rpx;
  258. color: #333333;
  259. flex: 7;
  260. box-sizing: border-box;
  261. padding-left: 20rpx;
  262. }
  263. &.b-b {
  264. margin: 20rpx 0;
  265. }
  266. }
  267. }
  268. .icon-chakangengduo {
  269. font-size: 36rpx;
  270. color: #b2b2b2;
  271. position: absolute;
  272. right: 0;
  273. }
  274. .text-textarea {
  275. width: 100%;
  276. height: 146rpx;
  277. border-bottom: 2rpx solid #e1e1e1;
  278. .textarea {
  279. width: 100%;
  280. height: 100%;
  281. font-size: $font-size-28;
  282. color: $text-color;
  283. z-index: 1;
  284. line-height: 32rpx;
  285. }
  286. .textarea.hide {
  287. opacity: 0;
  288. }
  289. .textarea.show {
  290. color: #999999;
  291. }
  292. }
  293. .default-row {
  294. background: #ffffff;
  295. margin-top: 16upx;
  296. padding: 24rpx 24rpx 24rpx 0;
  297. .tit {
  298. font-size: $font-size-28;
  299. line-height: 40rpx;
  300. color: #666666;
  301. flex: 1;
  302. }
  303. switch {
  304. transform: translateX(16upx) scale(0.9);
  305. }
  306. }
  307. .add-btn {
  308. width: 600rpx;
  309. height: 90rpx;
  310. font-size: $font-size-28;
  311. line-height: 90rpx;
  312. color: #ffffff;
  313. margin: 0 auto;
  314. text-align: center;
  315. background: $btn-confirm;
  316. border-radius: 45rpx;
  317. margin-top: 80rpx;
  318. }
  319. .add-btn.disabled {
  320. background: #e1e1e1;
  321. border-radius: 45rpx;
  322. }
  323. </style>