order.vue 15 KB

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