order.vue 17 KB

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