refundOrder.vue 15 KB

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