order.vue 16 KB

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