order.vue 14 KB

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