order.vue 15 KB

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