order.vue 14 KB

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