order.vue 15 KB

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