order.vue 17 KB

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