order.vue 17 KB

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