addAddress.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <!-- 编辑/添加地址 -->
  3. <view class="container flex-center flex-column">
  4. <global-loading />
  5. <!-- #ifdef MP-WEIXIN -->
  6. <!-- <view class="wxAddress flex-items flex-end" v-if="type == 1"> -->
  7. <!-- <view class="wxBtnBox flex-items" @click="addAddressWx"> -->
  8. <!-- <image class="" src="../../static/images/origin/withdraw.png"></image> -->
  9. <!-- </view> -->
  10. <!-- </view> -->
  11. <!-- #endif -->
  12. <view class="addressBack-box">
  13. <view class="consignee-box bor-line-F7F7F7">
  14. <input v-model="addressData.username" maxlength="20" class="fs28" placeholder-class="consignee" placeholder="收货人" />
  15. </view>
  16. <view class="iphoneNum-box bor-line-F7F7F7">
  17. <input v-model="addressData.phone" type="number" maxlength="11" class="fs28" placeholder-class="iphoneNum" placeholder="手机号码" />
  18. </view>
  19. <view class="location-box bor-line-F7F7F7 flex-row-plus flex-sp-between flex-items" @click="locationClick">
  20. <view class="fs28 location">所在地</view>
  21. <view class="locationBox">
  22. <!-- <city-select v-model="locationShowFalg" @city-change="cityChange"></city-select> -->
  23. <u-picker-shop v-model="locationShowFalg" mode="region" :default-region="addressData.defaultRegion" title="所在地" @confirm="cityChange"></u-picker-shop>
  24. <text v-model="addressData.ssqText">{{ addressData.ssqText }}</text>
  25. <image class="arrow mar-left-20" src="../../static/images/origin/greyArrow.png"></image>
  26. </view>
  27. </view>
  28. <view class="detailAddress-box">
  29. <input v-model="addressData.address" class="fs28" maxlength="60" placeholder-class="detailAddress" placeholder="详细地址:如道路、门牌号、小区、楼栋号、单元等" />
  30. </view>
  31. </view>
  32. <view class="addressTagBack-box">
  33. <view class="addressTag-box bor-line-F7F7F7 flex-row-plus flex-sp-between flex-items" @click="addressTagClick">
  34. <view class="fs28 addressTag">地址标签</view>
  35. <view class="flex-items">
  36. <text v-model="tag">{{ tag }}</text>
  37. <image class="arrow mar-left-20" src="../../static/images/origin/greyArrow.png"></image>
  38. </view>
  39. </view>
  40. <view class="defaultState-box flex-row-plus flex-sp-between flex-items">
  41. <view class="fs28 defaultState">设为默认地址</view>
  42. <u-switch v-model="ifDefault" active-color="#C5AA7B" inactive-color="#eee"></u-switch>
  43. </view>
  44. </view>
  45. <view v-if="type == 2" class="deleteAddress-box" @click="delAddress">
  46. <text class="font-color-C5AA7B">删除收货地址</text>
  47. </view>
  48. <view class="saveAddress-box">
  49. <view v-if="type == 1 || type == 3" class="saveAddress" @click="addAddressClick">保存</view>
  50. <view v-else class="saveAddress" @click="saveAddressClick">保存</view>
  51. </view>
  52. <!-- 所在地弹窗 -->
  53. <!-- <u-select v-model="locationShowFalg" safe-area-inset-bottom="true" mode="mutil-column-auto" :list="locationList" @confirm="locationConfirm" title="所在地"></u-select> -->
  54. <!-- 所在地弹窗 -->
  55. <!-- <u-select v-model="addressTagShowFalg" mode="single-column" :list="addressTagList" @confirm="addressTagconfirm" title="地址标签"></u-select> -->
  56. <u-picker-shop v-model="addressTagShowFalg" mode="selector" :range="addressTagList" range-key="label" title="地址标签" :default-selector="[ addressTagIndex ]" @confirm="addressTagconfirm"></u-picker-shop>
  57. </view>
  58. </template>
  59. <script>
  60. // import citySelect from './u-city-select.vue';
  61. const NET = require('../../utils/request')
  62. const API = require('../../config/api')
  63. export default {
  64. // components: {
  65. // citySelect
  66. // },
  67. data() {
  68. return {
  69. show: false,
  70. type: 1, // 1.添加新地址 2.编辑收货地址
  71. locationShowFalg: false,
  72. locationList: [],
  73. locationName: '',
  74. provinceName: '',
  75. cityName: '',
  76. districtName: '',
  77. addressTagList: [
  78. {
  79. value: '1',
  80. label: '家'
  81. },
  82. {
  83. value: '2',
  84. label: '公司'
  85. },
  86. {
  87. value: '3',
  88. label: '学校'
  89. }
  90. ],
  91. addressTagShowFalg: false,
  92. areaList: [],
  93. username: '',
  94. phone: '',
  95. ssqText: '',
  96. address: '',
  97. tag: '',
  98. ifDefault: 0,
  99. province: '',
  100. city: '',
  101. area: '',
  102. id: '',
  103. ordertype: 0,
  104. editAddress: {},
  105. addressTagIndex: 0,
  106. // defaultRegion: [],
  107. addressData: {
  108. username: '',
  109. phone: '',
  110. ssqText: '',
  111. address: '',
  112. defaultRegion: [],
  113. city: '',
  114. province: ''
  115. }
  116. }
  117. },
  118. onLoad(options) {
  119. this.type = options.type
  120. if (options.ordertype == 1) {
  121. this.ordertype = 1
  122. }
  123. const receiveId = options.receiveId
  124. this.id = receiveId
  125. if (this.type == 2) {
  126. // uni.showLoading({
  127. // mask: true,
  128. // title: '请稍后...',
  129. // })
  130. NET.request(API.receiveGetInfo, { receiveId }, 'GET').then((res) => {
  131. this.editAddress = res.data
  132. this.addressData.username = this.editAddress.receiveName
  133. this.addressData.phone = this.editAddress.receivePhone
  134. this.addressData.ssqText = this.editAddress.receiveAdress
  135. this.addressData.address = this.editAddress.address
  136. this.tag = this.editAddress.label
  137. for (let i = 0; i < this.addressTagList.length; i++) {
  138. if (this.addressTagList[i].label === this.tag) {
  139. this.addressTagIndex = i
  140. }
  141. }
  142. this.ifDefault = this.editAddress.ifDefault
  143. this.addressData.defaultRegion = this.addressData.ssqText.split('-')
  144. this.addressData.province = this.addressData.defaultRegion[0]
  145. this.addressData.city = this.addressData.defaultRegion[1]
  146. this.addressData.area = this.addressData.defaultRegion[2]
  147. this.addressData.id = this.editAddress.receiveId
  148. uni.hideLoading()
  149. })
  150. .catch((res) => {
  151. })
  152. }
  153. if (this.type == 3) {
  154. const obj = JSON.parse(options.wxAddressData)
  155. this.addressData = obj
  156. // this.username = obj.username
  157. // this.phone = obj.phone
  158. // this.ssqText = obj.ssqText
  159. // this.defaultRegion = obj.defaultRegion
  160. // this.address = obj.address
  161. // this.province = obj.provinceName
  162. // this.city = obj.cityName
  163. }
  164. if (this.editAddress != '') {
  165. uni.removeStorageSync('editAddress')
  166. }
  167. },
  168. methods: {
  169. cityChange(e) {
  170. this.addressData.ssqText = e.province.label + '-' + e.city.label + '-' + e.area.label
  171. this.addressData.province = e.province.label
  172. this.addressData.city = e.city.label
  173. this.addressData.area = e.area.label
  174. },
  175. locationClick() {
  176. this.locationShowFalg = true
  177. },
  178. locationConfirm(e) {
  179. this.provinceName = e[0].label
  180. this.cityName = e[1].label
  181. this.districtName = e[2].label
  182. this.locationDot = '·'
  183. },
  184. addressTagClick() {
  185. this.addressTagShowFalg = true
  186. },
  187. addressTagconfirm(index) {
  188. this.tag = this.addressTagList[index].label
  189. },
  190. // 编辑地址
  191. saveAddressClick() {
  192. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  193. if (this.addressData.username == '') {
  194. uni.showToast({
  195. title: '请输入收货人!',
  196. duration: 2000,
  197. icon: 'none'
  198. })
  199. } else if (this.addressData.phone == '') {
  200. uni.showToast({
  201. title: '请输入手机号!',
  202. duration: 2000,
  203. icon: 'none'
  204. })
  205. } else if (!phoneCodeVerification.test(this.addressData.phone)) {
  206. uni.showToast({
  207. title: '请输入正确的手机号!',
  208. duration: 2000,
  209. icon: 'none'
  210. })
  211. } else if (this.addressData.province == '' || this.addressData.city == '') {
  212. uni.showToast({
  213. title: '所在地不能为空!',
  214. duration: 2000,
  215. icon: 'none'
  216. })
  217. } else if (this.addressData.address == '') {
  218. uni.showToast({
  219. title: '请输入详细地址!',
  220. duration: 2000,
  221. icon: 'none'
  222. })
  223. } else {
  224. NET.request(API.AddresUpdate, {
  225. receiveId: this.id,
  226. receiveName: this.addressData.username,
  227. receivePhone: this.addressData.phone,
  228. receiveAdress: this.addressData.ssqText,
  229. address: this.addressData.address,
  230. label: this.tag,
  231. ifDefault: this.ifDefault ? 1 : 0
  232. }, 'POST').then((res) => {
  233. uni.navigateBack({
  234. delta: 1
  235. })
  236. uni.removeStorageSync('editAddress')
  237. })
  238. .catch((res) => {
  239. })
  240. }
  241. },
  242. // 新增地址
  243. addAddressClick() {
  244. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  245. if (this.addressData.username == '') {
  246. uni.showToast({
  247. title: '请输入收货人!',
  248. duration: 2000,
  249. icon: 'none'
  250. })
  251. } else if (this.addressData.phone == '') {
  252. uni.showToast({
  253. title: '请输入手机号!',
  254. duration: 2000,
  255. icon: 'none'
  256. })
  257. } else if (!phoneCodeVerification.test(this.addressData.phone)) {
  258. uni.showToast({
  259. title: '请输入正确的手机号!',
  260. duration: 2000,
  261. icon: 'none'
  262. })
  263. } else if (this.addressData.province == '' || this.addressData.city == '') {
  264. uni.showToast({
  265. title: '所在地不能为空!',
  266. duration: 2000,
  267. icon: 'none'
  268. })
  269. } else if (this.addressData.address == '') {
  270. uni.showToast({
  271. title: '请输入详细地址!',
  272. duration: 2000,
  273. icon: 'none'
  274. })
  275. } else {
  276. NET.request(
  277. API.AddresAdd,
  278. {
  279. receiveName: this.addressData.username,
  280. receivePhone: this.addressData.phone,
  281. receiveAdress: this.addressData.ssqText,
  282. address: this.addressData.address,
  283. label: this.tag,
  284. ifDefault: this.ifDefault ? 1 : 0
  285. }, 'POST'
  286. ).then((res) => {
  287. if (this.ordertype == 1) {
  288. uni.setStorageSync('receiveItem', res.data)
  289. uni.navigateBack({
  290. delta: 2
  291. })
  292. } else {
  293. uni.navigateBack({
  294. delta: 1
  295. })
  296. }
  297. })
  298. .catch((res) => {
  299. })
  300. }
  301. },
  302. // addAddressWx() {
  303. // let self = this
  304. // uni.chooseAddress({
  305. // success(res){
  306. // self.username = res.userName
  307. // self.phone = res.telNumber
  308. // self.ssqText = `${res.provinceName}-${res.cityName}-${res.countyName}`
  309. // self.defaultRegion = self.ssqText.split("-")
  310. // self.address = res.detailInfo
  311. // self.province = res.provinceName
  312. // self.city = res.cityName
  313. // }
  314. // })
  315. // },
  316. // 删除地址
  317. delAddress() {
  318. uni.showModal({
  319. title: '温馨提示',
  320. content: '是否删除此地址?',
  321. confirmText: '确定',
  322. cancelText: '取消',
  323. success: (res) => {
  324. if (res.confirm) {
  325. this.subm()
  326. } else if (res.cancel) {
  327. }
  328. }
  329. })
  330. },
  331. subm() {
  332. NET.request(API.AddresDelete, {
  333. receiveId: this.id
  334. }, 'POST').then((res) => {
  335. if (res.code === '200') {
  336. uni.navigateBack({
  337. delta: 1
  338. })
  339. }
  340. })
  341. .catch((res) => {
  342. })
  343. }
  344. }
  345. }
  346. </script>
  347. <style lang="scss">
  348. page{
  349. background-color: #F7F7F7;
  350. }
  351. .container{
  352. .addressBack-box{
  353. background-color: #FFFFFF;
  354. padding: 30upx 30upx;
  355. .consignee-box{
  356. padding-bottom: 36upx;
  357. width: 690upx;
  358. margin-top: 20upx;
  359. .consignee{
  360. color: #999999;
  361. font-size: 28upx;
  362. }
  363. }
  364. .iphoneNum-box{
  365. padding-bottom: 36upx;
  366. width: 690upx;
  367. margin-top: 36upx;
  368. .iphoneNum{
  369. color: #999999;
  370. font-size: 28upx;
  371. }
  372. }
  373. .location-box{
  374. padding-bottom: 36upx;
  375. width: 690upx;
  376. margin-top: 36upx;
  377. .location{
  378. color: #999999;
  379. font-size: 28upx;
  380. }
  381. .locationBox {
  382. display: flex;
  383. align-items: center;
  384. }
  385. }
  386. .detailAddress-box{
  387. padding-bottom: 36upx;
  388. width: 690upx;
  389. margin-top: 36upx;
  390. input{
  391. width: 100%;
  392. }
  393. .detailAddress{
  394. color: #999999;
  395. font-size: 28upx;
  396. }
  397. }
  398. }
  399. .addressTagBack-box{
  400. background-color: #FFFFFF;
  401. padding: 30upx 30upx;
  402. margin-top: 20upx;
  403. .addressTag-box{
  404. padding-bottom: 36upx;
  405. width: 690upx;
  406. .addressTag{
  407. color: #999999;
  408. font-size: 28upx;
  409. }
  410. }
  411. .defaultState-box{
  412. padding-bottom: 10upx;
  413. width: 690upx;
  414. margin-top: 36upx;
  415. .defaultState{
  416. color: #999999;
  417. font-size: 28upx;
  418. }
  419. }
  420. }
  421. .arrow{
  422. width: 62upx;
  423. height: 62upx;
  424. }
  425. .saveAddress-box{
  426. position: fixed;
  427. bottom: 50upx;
  428. left: 30upx;
  429. .saveAddress{
  430. width: 690upx;
  431. height: 100upx;
  432. text-align: center;
  433. line-height: 100upx;
  434. background: #333333;
  435. color: #FFEBC4;
  436. }
  437. }
  438. .wxAddress {
  439. height: 80rpx;
  440. text-align: center;
  441. line-height: 80rpx;
  442. color: #999999;
  443. .wxBtnBox {
  444. width: 100rpx;
  445. height: 80rpx;
  446. image {
  447. width: 80rpx;
  448. height: 80rpx;
  449. }
  450. }
  451. }
  452. }
  453. .deleteAddress-box{
  454. background-color: #FFFFFF;
  455. padding: 30upx 30upx;
  456. margin-top: 20upx;
  457. }
  458. .content{
  459. font-size: 35rpx;
  460. width: 500rpx;
  461. .btn{
  462. margin-bottom: 20rpx;
  463. width: 200rpx;
  464. background-image: linear-gradient( 135deg, #FFA100 10%, #FF7911 100%);
  465. }
  466. }
  467. </style>
  468. <style scoped>
  469. .addressBack-box /deep/ .u-tab-item{
  470. color: #C5AA7B !important;
  471. font-weight: 400 !important;
  472. }
  473. .addressBack-box /deep/ .u-tab-bar {
  474. background-color: #C5AA7B !important;
  475. }
  476. </style>