order.vue 17 KB

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