order1.vue 15 KB

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