address-manage.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <template>
  2. <view class="address-manage">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" title=" " />
  4. <view class="AddressTop">
  5. <view class="AddressTop-left">
  6. <image src="../../static/icon/search.png" class="AddressTop-left-search" />
  7. <input v-model="search_name" type="text" class="AddressTop-left-input" placeholder="请输入姓名或者手机号后四位" />
  8. <image v-if="search_name" src="../../static/icon/cha.png" class="AddressTop-left-clear"
  9. @click="search_name = '';toSearchAddress()" />
  10. </view>
  11. <view class="AddressTop-right" @click="toSearchAddress">查询</view>
  12. </view>
  13. <scroll-view v-if="list.length" class="AddressList" scroll-y="true">
  14. <view v-for="(item, index) in list" :key="index" class="AddressList-item"
  15. :class="address_index === index ? 'active' : ''" @click="address_index = index">
  16. <view class="AddressList-item-title">
  17. <text class="color spec">{{ item.con_name.slice(0,4) }}</text>
  18. <text class="color">{{ item.con_mobile }}</text>
  19. </view>
  20. <!-- <view v-if="item.nickname" class="AddressList-item-desc color">
  21. 昵称:{{ item.nickname.slice(0, 6) }}/{{ item.phone }}
  22. </view> -->
  23. <view class="AddressList-item-info">
  24. <view class="info-text color">{{ item | getAddressString }}</view>
  25. <image src="../../static/icon/arrow.png" class="info-arrow"></image>
  26. </view>
  27. <view class="AddressList-item-set">
  28. <view class="set-control" @tap.stop="editAddress(index)">编辑</view>
  29. <view class="set-control" @tap.stop="delAddress(index)">删除</view>
  30. <view v-if="+item.type === 1" class="get-used">常用地址</view>
  31. <view v-if="+item.type === 0" class="set-used" @tap.stop="submitAddress(item)">设为常用</view>
  32. </view>
  33. </view>
  34. <view class="bottom"></view>
  35. </scroll-view>
  36. <view v-else class="noaddress">还没有地址呢</view>
  37. <view class="adress_bottom">
  38. <navigator url="../add-address/add-address" class="add-address big-btn new_address">新增地址</navigator>
  39. <view v-if="title === '选择地址'" @tap="chooseAddress" class="add-address big-btn bg">使用此地址</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. _API_AddressGet,
  46. _API_AddressDel,
  47. _API_AddressSearch,
  48. _API_AddressUpdata
  49. } from '@/apis/address.js'
  50. export default {
  51. data() {
  52. return {
  53. title: '地址管理',
  54. address_index: -1,
  55. search_name: ''
  56. }
  57. },
  58. computed: {
  59. list() {
  60. return this.$store.state.address.list
  61. }
  62. },
  63. created() { // 监听添加或者删除地址消息提示
  64. uni.$on('ADDRESS', msg => {
  65. uni.toast(msg)
  66. })
  67. },
  68. methods: {
  69. // 搜索地址
  70. toSearchAddress() {
  71. this.address_index = -1
  72. _API_AddressSearch({
  73. search_name: this.search_name
  74. }).then(res => {
  75. if (res.code === 200) {
  76. let list = res.data.list.map(item => ({
  77. con_name: item.username,
  78. con_mobile: item.mobile,
  79. province: item.province,
  80. city: item.city,
  81. area: item.town,
  82. address: item.address,
  83. level: +item.level,
  84. id: item.id,
  85. nickname: item.nickname
  86. }))
  87. this.$store.commit('address/GET_ADDRESS', list)
  88. }
  89. })
  90. },
  91. editAddress(index) { // 点击编辑地址
  92. uni.navigateTo({
  93. url: `../add-address/add-address?index=${String(index)}`
  94. })
  95. },
  96. delAddress(index) { // 点击删除地址
  97. uni.showModal({
  98. title: '提示',
  99. content: '确定要删除这个地址?',
  100. success: (res) => {
  101. if (res.confirm) {
  102. _API_AddressDel({
  103. id: this.list[index].id
  104. }).then(res => {
  105. this.$store.commit('address/DEL', index)
  106. })
  107. }
  108. }
  109. })
  110. },
  111. submitAddress(item) { // 设置为常用地址
  112. const address = {
  113. id: item.id,
  114. con_name: item.con_name,
  115. con_mobile: item.con_mobile,
  116. province: item.province,
  117. city: item.city,
  118. area: item.area,
  119. address: item.address,
  120. type: 1
  121. }
  122. uni.showModal({
  123. title: '提示',
  124. content: '确定要设置这个地址为常用地址?',
  125. success: (res) => {
  126. if (res.confirm) {
  127. _API_AddressUpdata(address).then(res => {
  128. if (res.code === 200) {
  129. // uni.navigateBack()
  130. uni.$emit('ADDRESS', '设置成功')
  131. setTimeout(() => {
  132. uni.showLoading({
  133. mask: true
  134. })
  135. _API_AddressGet().then(res => {
  136. this.$store.commit('address/GET_ADDRESS',
  137. res.data.list)
  138. })
  139. }, 333)
  140. } else {
  141. uni.showModal({
  142. content: res.message || '设置失败',
  143. showCancel: false
  144. })
  145. }
  146. })
  147. }
  148. }
  149. })
  150. },
  151. chooseAddress() { // 如果是选择地址
  152. // if (this.title === '选择地址') {
  153. if (this.address_index > -1) {
  154. this.$store.commit('address/CHOOSEADDRESS', this.address_index)
  155. uni.navigateBack()
  156. } else {
  157. uni.showModal({
  158. content: "你还没有选择地址",
  159. showCancel: false
  160. })
  161. }
  162. // }
  163. // return
  164. }
  165. },
  166. onShow() {
  167. setTimeout(() => {
  168. uni.showLoading({
  169. mask: true
  170. })
  171. _API_AddressGet().then(res => {
  172. this.$store.commit('address/GET_ADDRESS', res.data.list)
  173. })
  174. }, 333)
  175. },
  176. onLoad(opt) {
  177. if (opt.choose) { // 表示用户是从商品详情页或确认订单页进来的
  178. this.title = '选择地址'
  179. }
  180. // console.log(this.title)
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. .address-manage {
  186. @include page();
  187. display: flex;
  188. justify-content: space-between;
  189. flex-direction: column;
  190. .AddressTop {
  191. display: flex;
  192. align-items: center;
  193. justify-content: space-between;
  194. background: #ffffff;
  195. width: 100%;
  196. padding: 30rpx;
  197. box-sizing: border-box;
  198. &-left {
  199. flex: 1;
  200. overflow: hidden;
  201. margin-right: 30rpx;
  202. height: 80rpx;
  203. box-sizing: border-box;
  204. border: 1px solid #CCCCCC;
  205. border-radius: 80rpx;
  206. display: flex;
  207. align-items: center;
  208. justify-content: space-between;
  209. padding: 20rpx 30rpx;
  210. &-search {
  211. display: block;
  212. width: 40rpx;
  213. height: 40rpx;
  214. }
  215. &-input {
  216. flex: 1;
  217. overflow: hidden;
  218. font-size: 28rpx;
  219. color: #333333;
  220. margin: 0 10rpx;
  221. }
  222. &-clear {
  223. display: block;
  224. width: 32rpx;
  225. height: 32rpx;
  226. }
  227. }
  228. &-right {
  229. width: 132rpx;
  230. height: 64rpx;
  231. border-radius: 64rpx;
  232. background: linear-gradient(to right, #F97C55, #F44545);
  233. color: #FFFFFF;
  234. font-size: 28rpx;
  235. text-align: center;
  236. line-height: 64rpx;
  237. }
  238. }
  239. .AddressList {
  240. width: 100%;
  241. padding: 30rpx;
  242. box-sizing: border-box;
  243. flex: 1;
  244. overflow: hidden;
  245. // margin-bottom: 20rpx;
  246. &-item {
  247. width: 100%;
  248. padding: 30rpx;
  249. background: #ffffff;
  250. margin-bottom: 30rpx;
  251. position: relative;
  252. border-radius: 24rpx;
  253. &.active {
  254. background: linear-gradient(to right, #F97C55, #F44545);
  255. &-set {
  256. .set-used {
  257. background: #ffffff !important;
  258. }
  259. }
  260. .level {
  261. background: linear-gradient(203deg, #FBDCAC 0%, #FFEFD7 31%, #FFDCA5 55%, #FEEACB 90%, #F9D193 100%) !important;
  262. color: #F44545 !important;
  263. }
  264. .color {
  265. color: #ffffff !important;
  266. }
  267. }
  268. &-title {
  269. color: #999999;
  270. font-size: 28rpx;
  271. margin-bottom: 20rpx;
  272. .spec {
  273. color: #333333;
  274. font-size: 32rpx;
  275. margin-right: 20rpx;
  276. }
  277. }
  278. &-desc {
  279. color: #999999;
  280. font-size: 28rpx;
  281. margin-bottom: 30rpx;
  282. }
  283. &-info {
  284. display: flex;
  285. align-items: center;
  286. justify-content: space-between;
  287. padding-bottom: 30rpx;
  288. margin-bottom: 30rpx;
  289. border-bottom: 1px solid #E9E9E9;
  290. .info-text {
  291. color: #333333;
  292. font-size: 28rpx;
  293. flex: 1;
  294. overflow: hidden;
  295. margin-right: 40rpx;
  296. }
  297. .info-arrow {
  298. display: block;
  299. width: 30rpx;
  300. height: 30rpx;
  301. }
  302. }
  303. &-set {
  304. width: 100%;
  305. display: flex;
  306. align-items: center;
  307. justify-content: flex-start;
  308. .get-used {
  309. color: #EA4A41;
  310. font-size: 24rpx;
  311. width: 136rpx;
  312. height: 50rpx;
  313. border-radius: 8rpx;
  314. background: #FFF4F3;
  315. text-align: center;
  316. line-height: 50rpx;
  317. margin-left: auto;
  318. }
  319. .set-used {
  320. color: #333;
  321. font-size: 24rpx;
  322. width: 136rpx;
  323. height: 50rpx;
  324. border-radius: 8rpx;
  325. background: #F8F8F8;
  326. text-align: center;
  327. line-height: 50rpx;
  328. margin-left: auto;
  329. }
  330. .set-control {
  331. color: #333333;
  332. font-size: 24rpx;
  333. width: 112rpx;
  334. height: 50rpx;
  335. border-radius: 50rpx;
  336. background: #F8F8F8;
  337. text-align: center;
  338. line-height: 50rpx;
  339. &:nth-of-type(1) {
  340. margin-right: 20rpx;
  341. }
  342. }
  343. }
  344. &-level {
  345. position: absolute;
  346. top: 30rpx;
  347. right: 30rpx;
  348. transform: translate(30rpx, 14rpx);
  349. width: 156rpx;
  350. height: 50rpx;
  351. border-top-left-radius: 50rpx;
  352. border-bottom-left-radius: 50rpx;
  353. background: linear-gradient(to right, #F97C55, #F44545);
  354. color: #FFFFFF;
  355. font-size: 24rpx;
  356. text-align: center;
  357. line-height: 50rpx;
  358. }
  359. }
  360. }
  361. .address_search {
  362. width: 100%;
  363. display: flex;
  364. align-items: center;
  365. justify-content: space-between;
  366. padding: 12rpx 30rpx;
  367. box-sizing: border-box;
  368. color: #333333;
  369. background-color: #FFFFFF;
  370. margin-bottom: 1px;
  371. .address_search_main {
  372. width: calc(100% - 106rpx);
  373. background-color: #F2F4F5;
  374. height: 64rpx;
  375. padding: 0 22px;
  376. border-radius: 64rpx;
  377. display: flex;
  378. justify-content: space-between;
  379. align-items: center;
  380. &::before {
  381. content: "";
  382. display: block;
  383. width: 36rpx;
  384. height: 36rpx;
  385. background-image: url(../../static/icon/search.png);
  386. background-size: 100% 100%;
  387. margin-right: 26rpx;
  388. }
  389. .address_search_input {
  390. flex: 1;
  391. }
  392. }
  393. .address_search_btn {
  394. font-size: 32rpx;
  395. width: 80rpx;
  396. }
  397. }
  398. .content {
  399. .item {
  400. background: #FFFFFF;
  401. border-bottom: 20rpx solid $app-base-bg;
  402. box-sizing: border-box;
  403. padding: 0 30rpx;
  404. .fixed_title {
  405. height: 74rpx;
  406. line-height: 74rpx;
  407. color: #333333;
  408. font-size: 28rpx;
  409. }
  410. .item_main {
  411. padding: 18rpx 0;
  412. border-bottom: 1px solid #D7D7D7;
  413. .label {
  414. width: 120rpx;
  415. text-align: left;
  416. }
  417. .item_main_agent {
  418. display: flex;
  419. justify-content: space-between;
  420. align-items: center;
  421. margin-bottom: 30rpx;
  422. .item_agent_info {
  423. display: flex;
  424. align-items: center;
  425. justify-content: flex-start;
  426. color: #333333;
  427. font-size: 28rpx;
  428. width: calc(100% - 118rpx);
  429. text-overflow: ellipsis;
  430. overflow: hidden;
  431. }
  432. .item_agent_level {
  433. color: #FFFFFF;
  434. font-size: 24rpx;
  435. background-color: #F76454;
  436. border-radius: 4rpx;
  437. height: 36rpx;
  438. line-height: 36rpx;
  439. width: 108rpx;
  440. text-align: center;
  441. }
  442. }
  443. .item_main_user {
  444. .item_main_user_left {
  445. display: flex;
  446. align-items: center;
  447. justify-content: flex-start;
  448. }
  449. .item_main_user_right {
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. height: 42rpx;
  454. border-radius: 42rpx;
  455. background-color: #F76454;
  456. color: #FFFFFF;
  457. padding: 0 15rpx;
  458. }
  459. color: #333333;
  460. font-size: 28rpx;
  461. display: flex;
  462. justify-content: space-between;
  463. align-items: center;
  464. margin-bottom: 20rpx;
  465. }
  466. .item_main_address {
  467. width: 100%;
  468. display: flex;
  469. justify-content: flex-end;
  470. align-items: center;
  471. .address_text {
  472. width: 100%;
  473. color: #999999;
  474. font-size: 28rpx;
  475. line-height: 38rpx;
  476. }
  477. }
  478. }
  479. .item_set_footer {
  480. height: 77rpx;
  481. display: flex;
  482. justify-content: space-between;
  483. align-items: center;
  484. color: #333333;
  485. font-size: 24rpx !important;
  486. .check {
  487. display: flex;
  488. justify-content: flex-start;
  489. align-items: center;
  490. &::before {
  491. content: "";
  492. display: block;
  493. width: 36rpx;
  494. height: 36rpx;
  495. box-sizing: border-box;
  496. border: 2rpx solid #F76454;
  497. text-align: center;
  498. line-height: 34rpx;
  499. border-radius: 50%;
  500. color: #FFFFFF;
  501. margin-right: 17rpx;
  502. }
  503. }
  504. .checked {
  505. &::before {
  506. content: "\2714";
  507. background-color: #F76454;
  508. }
  509. }
  510. .item_set_footer_right {
  511. .edit-del {
  512. display: flex;
  513. justify-content: flex-end;
  514. align-items: center;
  515. height: 100%;
  516. width: 268rpx;
  517. color: $app-sec-text-color;
  518. justify-content: space-between;
  519. .edit,
  520. .del {
  521. flex: 1;
  522. height: 100%;
  523. text-align: center;
  524. &.del {
  525. text-align: right;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. .bottom {
  533. height: 88rpx;
  534. }
  535. }
  536. .noaddress {
  537. @include flex();
  538. height: 100%;
  539. color: $app-sec-text-color;
  540. }
  541. .add-address {
  542. left: 0;
  543. bottom: 0;
  544. margin: 0;
  545. width: 100%;
  546. position: fixed;
  547. border-radius: 0;
  548. }
  549. .bottom {
  550. height: 60rpx;
  551. }
  552. .adress_bottom {
  553. left: 0;
  554. bottom: 0;
  555. margin: 0;
  556. width: 100%;
  557. position: fixed;
  558. border-radius: 0;
  559. height: 88rpx;
  560. display: flex;
  561. justify-content: space-between;
  562. align-items: center;
  563. .add-address {
  564. flex: 1;
  565. height: 88rpx;
  566. position: relative;
  567. background: #F76454;
  568. }
  569. .new_address {
  570. border: none;
  571. background-color: #FFFFFF;
  572. }
  573. }
  574. .userLevel {
  575. font-size: 24rpx !important;
  576. color: #F76454;
  577. overflow: hidden;
  578. text-overflow: ellipsis;
  579. white-space: nowrap;
  580. }
  581. }
  582. </style>