order.vue 15 KB

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