order.vue 13 KB

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