addressManage.vue 10 KB

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