refundOrder.vue 14 KB

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