order.vue 17 KB

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