order.vue 17 KB

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