order.vue 15 KB

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