order.vue 15 KB

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