addressManage.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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:'13914',
  166. userId: this.addressData.userId, //用户id ,只在新增收货地址时传
  167. shouHuoRen: this.addressData.shouHuoRen, //收货人
  168. townId: this.addressData.townId, //区ID
  169. address: this.addressData.address, //地址
  170. mobile: this.addressData.mobile, //手机
  171. defaultFlag: this.addressData.defaultFlag //是否默认收货地址(0 不是默认,1 默认)
  172. }
  173. this.postAddressData(this.params)
  174. } else {
  175. this.params = this.addressData
  176. this.postAddressData(this.params)
  177. }
  178. },
  179. postAddressData(res) {
  180. this.btnText(true)
  181. // 保存地址
  182. this.UserService.AddNewAddress(res)
  183. .then(response => {
  184. this.$util.msg('保存成功', 2000, true, 'success')
  185. this.btnText(false)
  186. setTimeout(() => {
  187. uni.navigateBack()
  188. }, 2000)
  189. })
  190. .catch(error => {
  191. this.$util.msg(error.msg, 2000)
  192. setTimeout(function() {
  193. uni.switchTab({
  194. url: '/seller/pages/index/index'
  195. })
  196. }, 1000)
  197. })
  198. },
  199. btnText(flg) {
  200. if (flg) {
  201. this.isConfirm = true
  202. this.buttonText = '保存中...'
  203. } else {
  204. this.isConfirm = false
  205. this.buttonText = '保存'
  206. }
  207. },
  208. onShouHuoRen(e) {
  209. this.addressData.shouHuoRen = e.detail.value
  210. this.initInput()
  211. },
  212. onMobile(e) {
  213. this.addressData.mobile = e.detail.value
  214. this.initInput()
  215. },
  216. onTextareaInput(e) {
  217. this.addressData.address = e.detail.value
  218. this.initInput()
  219. },
  220. initInput() {
  221. if (
  222. this.addressData.shouHuoRen !== '' &&
  223. this.addressData.mobile !== '' &&
  224. this.addressData.address !== '' &&
  225. this.addressData.townId !== ''
  226. ) {
  227. this.isConfirm = false
  228. } else {
  229. this.isConfirm = true
  230. }
  231. }
  232. },
  233. onShow() {
  234. this.$api.getComStorage('clubInfo').then(resolve => {
  235. this.addressData.userId = resolve.userId
  236. })
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. page {
  242. height: auto;
  243. background: $bg-color;
  244. }
  245. .add-content {
  246. width: 702rpx;
  247. padding: 0 24rpx;
  248. .input-row {
  249. display: flex;
  250. align-items: center;
  251. position: relative;
  252. width: 702rpx;
  253. height: 88rpx;
  254. margin: 0 auto;
  255. border-bottom: 2rpx solid #e1e1e1;
  256. .label {
  257. font-size: $font-size-28;
  258. color: #666666;
  259. line-height: 88rpx;
  260. flex: 2;
  261. }
  262. .input {
  263. height: 100%;
  264. font-size: $font-size-28;
  265. line-height: 88rpx;
  266. color: #333333;
  267. flex: 7;
  268. box-sizing: border-box;
  269. padding-left: 20rpx;
  270. }
  271. &.b-b {
  272. margin: 20rpx 0;
  273. }
  274. }
  275. }
  276. .icon-chakangengduo {
  277. font-size: 36rpx;
  278. color: #b2b2b2;
  279. position: absolute;
  280. right: 0;
  281. }
  282. .text-textarea {
  283. width: 100%;
  284. height: 146rpx;
  285. border-bottom: 2rpx solid #e1e1e1;
  286. .textarea {
  287. width: 100%;
  288. height: 100%;
  289. font-size: $font-size-28;
  290. color: $text-color;
  291. z-index: 1;
  292. line-height: 32rpx;
  293. }
  294. .textarea.hide {
  295. opacity: 0;
  296. }
  297. .textarea.show {
  298. color: #999999;
  299. }
  300. }
  301. .default-row {
  302. background: #ffffff;
  303. margin-top: 16upx;
  304. padding: 24rpx 24rpx 24rpx 0;
  305. .tit {
  306. font-size: $font-size-28;
  307. line-height: 40rpx;
  308. color: #666666;
  309. flex: 1;
  310. }
  311. switch {
  312. transform: translateX(16upx) scale(0.9);
  313. }
  314. }
  315. .add-btn {
  316. width: 600rpx;
  317. height: 90rpx;
  318. font-size: $font-size-28;
  319. line-height: 90rpx;
  320. color: #ffffff;
  321. margin: 0 auto;
  322. text-align: center;
  323. background: $btn-confirm;
  324. border-radius: 45rpx;
  325. margin-top: 80rpx;
  326. }
  327. .add-btn.disabled {
  328. background: #e1e1e1;
  329. border-radius: 45rpx;
  330. }
  331. </style>