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