order1.vue 15 KB

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