order.vue 15 KB

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