order.vue 16 KB

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