time.vue 16 KB

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