order.vue 17 KB

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