addressManage.vue 7.8 KB

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