dfOrder.vue 15 KB

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