order.vue 16 KB

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