order.vue 15 KB

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