orderAfter.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <view class="content">
  3. <!-- <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item"
  5. :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  6. </view> -->
  7. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  8. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  9. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  10. <!-- 空白页 -->
  11. <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  12. <!-- 订单列表 -->
  13. <view @click="goToOrderDetail(item)" v-for="(item, index) in tabItem.orderList" :key="index"
  14. class="order-item">
  15. <view class="i-top b-b">
  16. <text class="time">{{ item._add_time }}</text>
  17. <text class="state" :style="{ color: item.stateTipColor }">{{ item._status._title }}</text>
  18. </view>
  19. <scroll-view v-if="item.cartInfo.length > 1" class="goods-box" scroll-x>
  20. <view v-for="(goodsItem, goodsIndex) in item.cartInfo" :key="goodsIndex" class="goods-item">
  21. <image class="goods-img" :src="goodsItem.productInfo.image" mode="aspectFill"></image>
  22. </view>
  23. </scroll-view>
  24. <view class="goods-box-single" v-for="(goodsItem, goodsIndex) in item.cartInfo"
  25. :key="goodsIndex">
  26. <image class="goods-img" :src="goodsItem.productInfo.image" mode="scaleToFill"></image>
  27. <view class="right">
  28. <view class="flex flextop">
  29. <text class="title clamp2">{{ goodsItem.productInfo.store_name }}</text>
  30. <text class="price">{{ moneyNum(goodsItem.productInfo.price) }}</text>
  31. </view>
  32. <view class="row flex">
  33. <text
  34. class="row_title">{{ goodsItem.productInfo.attrInfo ? goodsItem.productInfo.attrInfo.suk : '' }}</text>
  35. <text class="attr-box"> x {{ goodsItem.cart_num }}</text>
  36. </view>
  37. <view class="row flex">
  38. <text class="attr-box">( 服务费:{{goodsItem.day_deducted}} 服务天数:{{goodsItem.day}}
  39. )</text>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="action-box b-t">
  44. <button v-if="item._status._title == '已退款'" @click.stop="deleteOrder(item,index)"
  45. class="action-btn recom">删除订单</button>
  46. <button @click.stop="goToOrderDetail(item)" class="action-btn evaluate">查看详情</button>
  47. </view>
  48. </view>
  49. <uni-load-more :status="tabItem.loadingType"></uni-load-more>
  50. </scroll-view>
  51. </swiper-item>
  52. </swiper>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. orderList,
  58. orderDel
  59. } from '@/api/order.js';
  60. export default {
  61. data() {
  62. return {
  63. tabCurrentIndex: 0,
  64. navList: [{
  65. state: -1,
  66. text: '退款中',
  67. loadingType: 'more',
  68. orderList: [],
  69. page: 1, //当前页数
  70. limit: 10 //每次信息条数
  71. },
  72. {
  73. state: -2,
  74. text: '已退款',
  75. loadingType: 'more',
  76. orderList: [],
  77. page: 1, //当前页数
  78. limit: 10 //每次信息条数
  79. },
  80. {
  81. state: -3,
  82. text: '全部',
  83. loadingType: 'more',
  84. orderList: [],
  85. page: 1, //当前页数
  86. limit: 10 //每次信息条数
  87. }
  88. ]
  89. };
  90. },
  91. onLoad(options) {
  92. /**
  93. * 修复app端点击除全部订单外的按钮进入时不加载数据的问题
  94. * 替换onLoad下代码即可
  95. */
  96. this.tabCurrentIndex = +options.state;
  97. // #ifndef MP
  98. this.loadData();
  99. // #endif
  100. // #ifdef MP
  101. if (options.state == 0) {
  102. this.loadData();
  103. }
  104. // #endif
  105. },
  106. // #ifdef APP-PLUS || H5
  107. onBackPress(e) {
  108. uni.switchTab({
  109. url: '/pages/user/user',
  110. });
  111. return true;
  112. },
  113. // #endif
  114. methods: {
  115. // 转换金额为数字
  116. moneyNum(value) {
  117. return +value;
  118. },
  119. // 确认收货
  120. //跳转到订单详情
  121. goToOrderDetail(e) {
  122. uni.navigateTo({
  123. url: '/pages/order/orderDetail?id=' + e.order_id
  124. });
  125. },
  126. //获取订单列表
  127. loadData(source) {
  128. //这里是将订单挂载到tab列表下
  129. let index = this.tabCurrentIndex;
  130. let navItem = this.navList[index];
  131. let state = navItem.state;
  132. if (source === 'tabChange' && navItem.loaded === true) {
  133. //tab切换只有第一次需要加载数据
  134. return;
  135. }
  136. if (navItem.loadingType === 'loading') {
  137. //防止重复加载
  138. return;
  139. }
  140. if (navItem.loadingType === 'noMore') {
  141. //防止重复加载
  142. return;
  143. }
  144. // 修改当前对象状态为加载中
  145. navItem.loadingType = 'loading';
  146. orderList({
  147. type: state,
  148. page: navItem.page,
  149. limit: navItem.limit
  150. })
  151. .then(({
  152. data
  153. }) => {
  154. let arr = data.map(e => {
  155. let b = this.orderStateExp(e.status);
  156. e.stateTip = b.stateTip;
  157. e.stateTipColor = b.stateTipColor;
  158. return e;
  159. });
  160. navItem.orderList = navItem.orderList.concat(arr);
  161. // console.log(navItem.orderList);
  162. navItem.page++;
  163. if (navItem.limit == data.length) {
  164. //判断是否还有数据, 有改为 more, 没有改为noMore
  165. navItem.loadingType = 'more';
  166. return;
  167. } else {
  168. //判断是否还有数据, 有改为 more, 没有改为noMore
  169. navItem.loadingType = 'noMore';
  170. }
  171. uni.hideLoading();
  172. this.$set(navItem, 'loaded', true);
  173. })
  174. .catch(e => {
  175. console.log(e);
  176. });
  177. },
  178. //swiper 切换
  179. changeTab(e) {
  180. this.tabCurrentIndex = e.target.current;
  181. this.loadData('tabChange');
  182. },
  183. //顶部tab点击
  184. tabClick(index) {
  185. this.tabCurrentIndex = index;
  186. },
  187. //删除订单
  188. deleteOrder(item, index) {
  189. let that = this;
  190. uni.showLoading({
  191. title: '请稍后',
  192. mask:true
  193. });
  194. uni.showModal({
  195. title: '删除订单',
  196. content: '删除订单后不可恢复,是否删除?',
  197. success: res => {
  198. uni.showLoading({
  199. title: '请稍后'
  200. });
  201. if (res.confirm) {
  202. orderDel({
  203. uni: item.order_id
  204. }).then(() => {
  205. that.navList[that.tabCurrentIndex].orderList.splice(index, 1);
  206. uni.hideLoading();
  207. }).catch((e) => {
  208. uni.hideLoading();
  209. console.log(e);
  210. })
  211. }
  212. },
  213. });
  214. },
  215. //订单状态文字和颜色
  216. orderStateExp(state) {
  217. let stateTip = '',
  218. stateTipColor = '#fa436a';
  219. switch (+state) {
  220. case 0:
  221. stateTip = '待付款';
  222. break;
  223. case 1:
  224. stateTip = '待发货';
  225. break;
  226. case 2:
  227. stateTip = '待收货';
  228. break;
  229. case 3:
  230. stateTip = '待评价';
  231. break;
  232. case 4:
  233. stateTip = '已完成';
  234. stateTipColor = '#5dbc7c';
  235. break;
  236. case 9:
  237. stateTip = '订单已关闭';
  238. stateTipColor = '#909399';
  239. break;
  240. //更多自定义
  241. }
  242. return {
  243. stateTip,
  244. stateTipColor
  245. };
  246. }
  247. }
  248. };
  249. </script>
  250. <style lang="scss">
  251. page,
  252. .content {
  253. background: $page-color-base;
  254. height: 100%;
  255. }
  256. .swiper-box {
  257. height:100%;
  258. }
  259. .list-scroll-content {
  260. height: 100%;
  261. padding-top: 30rpx;
  262. }
  263. .navbar {
  264. display: flex;
  265. height: 40px;
  266. padding: 0 5px;
  267. background: #fff;
  268. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  269. position: relative;
  270. z-index: 10;
  271. .nav-item {
  272. flex: 1;
  273. display: flex;
  274. justify-content: center;
  275. align-items: center;
  276. height: 100%;
  277. font-size: 15px;
  278. color: $font-color-dark;
  279. position: relative;
  280. &.current {
  281. color: $base-color;
  282. &:after {
  283. content: '';
  284. position: absolute;
  285. left: 50%;
  286. bottom: 0;
  287. transform: translateX(-50%);
  288. width: 44px;
  289. height: 0;
  290. border-bottom: 2px solid $base-color;
  291. }
  292. }
  293. }
  294. }
  295. .uni-swiper-item {
  296. height: auto;
  297. }
  298. .order-item {
  299. display: flex;
  300. flex-direction: column;
  301. padding-left: 30rpx;
  302. background: #fff;
  303. margin: 0 $page-row-spacing;
  304. margin-bottom: 30rpx;
  305. border-radius: 20rpx;
  306. padding-bottom: 10rpx;
  307. .i-top {
  308. display: flex;
  309. align-items: center;
  310. height: 80rpx;
  311. padding-right: 30rpx;
  312. font-size: $font-base;
  313. color: $font-color-dark;
  314. position: relative;
  315. .time {
  316. flex: 1;
  317. }
  318. .state {
  319. color: $base-color;
  320. }
  321. .del-btn {
  322. padding: 10rpx 0 10rpx 36rpx;
  323. font-size: $font-lg;
  324. color: $font-color-light;
  325. position: relative;
  326. &:after {
  327. content: '';
  328. width: 0;
  329. height: 30rpx;
  330. border-left: 1px solid $border-color-dark;
  331. position: absolute;
  332. left: 20rpx;
  333. top: 50%;
  334. transform: translateY(-50%);
  335. }
  336. }
  337. }
  338. /* 多条商品 */
  339. .goods-box {
  340. height: 160rpx;
  341. padding: 20rpx 0;
  342. white-space: nowrap;
  343. .goods-item {
  344. width: 120rpx;
  345. height: 120rpx;
  346. display: inline-block;
  347. margin-right: 24rpx;
  348. }
  349. .goods-img {
  350. display: block;
  351. width: 100%;
  352. height: 100%;
  353. }
  354. }
  355. /* 单条商品 */
  356. .goods-box-single {
  357. display: flex;
  358. padding: 20rpx 0;
  359. .goods-img {
  360. display: block;
  361. width: 170rpx;
  362. height: 170rpx;
  363. border-radius: 20rpx;
  364. }
  365. .right {
  366. flex: 1;
  367. display: flex;
  368. flex-direction: column;
  369. padding: 0 30rpx 0 24rpx;
  370. overflow: hidden;
  371. .flextop {
  372. align-items: flex-start;
  373. line-height: 1.3;
  374. }
  375. .row {
  376. margin-top: 10rpx;
  377. }
  378. .row_title {
  379. padding: 5rpx 10rpx;
  380. background-color: #dddddd;
  381. border-radius: 10rpx;
  382. font-size: 22rpx;
  383. color: #ffffff;
  384. }
  385. .title {
  386. font-size: $font-base + 2rpx;
  387. color: $font-color-dark;
  388. width: 80%;
  389. min-height: 2.5rem;
  390. }
  391. .attr-box {
  392. display: flex;
  393. justify-content: flex-end;
  394. font-size: $font-sm + 2rpx;
  395. color: $font-color-light;
  396. }
  397. .price {
  398. display: inline;
  399. font-size: $font-base + 2rpx;
  400. color: $font-color-light;
  401. &:before {
  402. content: '¥';
  403. font-size: $font-sm;
  404. }
  405. }
  406. }
  407. }
  408. .price-box {
  409. display: flex;
  410. justify-content: flex-end;
  411. align-items: baseline;
  412. padding: 20rpx 30rpx;
  413. font-size: $font-sm + 2rpx;
  414. color: $font-color-light;
  415. .num {
  416. margin: 0 8rpx;
  417. color: $font-color-dark;
  418. }
  419. .price {
  420. font-size: $font-lg;
  421. color: $font-color-dark;
  422. &:before {
  423. content: '¥';
  424. font-size: $font-sm;
  425. margin: 0 2rpx 0 8rpx;
  426. }
  427. }
  428. }
  429. .action-box {
  430. display: flex;
  431. justify-content: flex-end;
  432. align-items: center;
  433. height: 100rpx;
  434. position: relative;
  435. padding-right: 30rpx;
  436. }
  437. .action-btn {
  438. width: 160rpx;
  439. height: 60rpx;
  440. margin: 0;
  441. margin-left: 24rpx;
  442. padding: 0;
  443. text-align: center;
  444. line-height: 60rpx;
  445. font-size: $font-sm + 2rpx;
  446. color: $color-red;
  447. border-radius: 100px;
  448. border: 1px solid $color-red;
  449. background-color: #FFFFFF;
  450. &.recom {
  451. color: $font-color-light;
  452. border: 1px solid $font-color-light;
  453. }
  454. &.evaluate {
  455. color: $color-yellow;
  456. border: 1px solid $color-yellow;
  457. }
  458. }
  459. }
  460. /* load-more */
  461. .uni-load-more {
  462. display: flex;
  463. flex-direction: row;
  464. height: 80rpx;
  465. align-items: center;
  466. justify-content: center;
  467. }
  468. .uni-load-more__text {
  469. font-size: 28rpx;
  470. color: #999;
  471. }
  472. .uni-load-more__img {
  473. height: 24px;
  474. width: 24px;
  475. margin-right: 10px;
  476. }
  477. .uni-load-more__img>view {
  478. position: absolute;
  479. }
  480. .uni-load-more__img>view view {
  481. width: 6px;
  482. height: 2px;
  483. border-top-left-radius: 1px;
  484. border-bottom-left-radius: 1px;
  485. background: #999;
  486. position: absolute;
  487. opacity: 0.2;
  488. transform-origin: 50%;
  489. animation: load 1.56s ease infinite;
  490. }
  491. .uni-load-more__img>view view:nth-child(1) {
  492. transform: rotate(90deg);
  493. top: 2px;
  494. left: 9px;
  495. }
  496. .uni-load-more__img>view view:nth-child(2) {
  497. transform: rotate(180deg);
  498. top: 11px;
  499. right: 0;
  500. }
  501. .uni-load-more__img>view view:nth-child(3) {
  502. transform: rotate(270deg);
  503. bottom: 2px;
  504. left: 9px;
  505. }
  506. .uni-load-more__img>view view:nth-child(4) {
  507. top: 11px;
  508. left: 0;
  509. }
  510. .load1,
  511. .load2,
  512. .load3 {
  513. height: 24px;
  514. width: 24px;
  515. }
  516. .load2 {
  517. transform: rotate(30deg);
  518. }
  519. .load3 {
  520. transform: rotate(60deg);
  521. }
  522. .load1 view:nth-child(1) {
  523. animation-delay: 0s;
  524. }
  525. .load2 view:nth-child(1) {
  526. animation-delay: 0.13s;
  527. }
  528. .load3 view:nth-child(1) {
  529. animation-delay: 0.26s;
  530. }
  531. .load1 view:nth-child(2) {
  532. animation-delay: 0.39s;
  533. }
  534. .load2 view:nth-child(2) {
  535. animation-delay: 0.52s;
  536. }
  537. .load3 view:nth-child(2) {
  538. animation-delay: 0.65s;
  539. }
  540. .load1 view:nth-child(3) {
  541. animation-delay: 0.78s;
  542. }
  543. .load2 view:nth-child(3) {
  544. animation-delay: 0.91s;
  545. }
  546. .load3 view:nth-child(3) {
  547. animation-delay: 1.04s;
  548. }
  549. .load1 view:nth-child(4) {
  550. animation-delay: 1.17s;
  551. }
  552. .load2 view:nth-child(4) {
  553. animation-delay: 1.3s;
  554. }
  555. .load3 view:nth-child(4) {
  556. animation-delay: 1.43s;
  557. }
  558. @-webkit-keyframes load {
  559. 0% {
  560. opacity: 1;
  561. }
  562. 100% {
  563. opacity: 0.2;
  564. }
  565. }
  566. </style>