address-manage.vue 13 KB

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