order.vue 15 KB

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