order.vue 15 KB

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