addressManage.vue 7.6 KB

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