orderDl.vue 12 KB

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