order.vue 15 KB

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