order.vue 16 KB

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