order.vue 17 KB

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