order.vue 17 KB

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