order.vue 15 KB

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