order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view class="content">
  3. <view class="header">
  4. <view class="title">
  5. 我的订单
  6. </view>
  7. </view>
  8. <view class="navbar">
  9. <view v-for="(item, index) in navList" :key="index" class="nav-item"
  10. :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  11. </view>
  12. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  13. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  14. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  15. <!-- 空白页 -->
  16. <!-- #ifdef H5 -->
  17. <empty src="../../static/error/emptyOrder.png"
  18. v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  19. <!-- #endif -->
  20. <!-- #ifndef H5 -->
  21. <empty src="../static/error/emptyOrder.png"
  22. v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
  23. <!-- #endif -->
  24. <!-- 订单列表 -->
  25. <view @click="navTo( '/pages/order/orderDetail?type=1&id=' + item.order_id )"
  26. v-for="(item, index) in tabItem.orderList" :key="index" class="order-item position-relative">
  27. <view class="i-top b-b flex">
  28. <view class="order-code flex">
  29. <view class="no">
  30. 订单编号:
  31. </view>
  32. <view>
  33. {{ item.order_id }}
  34. </view>
  35. </view>
  36. <text class="font-size-sm" :style="{ color: item.stateTipColor }">{{ item._status._title }}</text>
  37. <!-- <text v-if="item.status === 4" class="del-btn iconfont icondelete" @click="deleteOrder(index)"></text> -->
  38. </view>
  39. <scroll-view v-if="item.cartInfo.length > 0" class="goods-box" scroll-x>
  40. <view v-for="(goodsItem, goodsIndex) in item.cartInfo" :key="goodsIndex" class="goods-item">
  41. <image class="goods-img" :src="goodsItem.productInfo.image" mode="aspectFill">
  42. </image>
  43. <view class="good-name clamp">
  44. {{goodsItem.productInfo.attrInfo.suk}}*{{goodsItem.cart_num}}
  45. </view>
  46. </view>
  47. </scroll-view>
  48. <view class="info-info">
  49. <view class="js">
  50. 共{{item.cartInfo.length}}件
  51. </view>
  52. <view class="hj">
  53. 合计:¥{{item.pay_price}}
  54. </view>
  55. </view>
  56. <!-- 底部操作栏 -->
  57. <view class="btm-btn-wrap flex">
  58. <view class="btm-left">
  59. 下单时间:{{item._add_time.split(' ')[0].replace(/-/g,'/')}}
  60. </view>
  61. <view class="btm-right flex">
  62. <view class="btm-btn" @click.stop="cancelOrder(item)"
  63. v-if="item._status._title == '未支付'">
  64. 取消订单
  65. </view>
  66. <view class="btm-btn ksps"
  67. @click.stop="navTo( '/pages/user/money/pay?type=1&ordid=' + item.order_id + '&money=' + item.pay_price)"
  68. v-if="item._status._title == '未支付'">
  69. 前往支付
  70. </view>
  71. <view class="btm-btn ksps" @click.stop="orderTake(item, index)"
  72. v-if="item._status._title == '待收货'">
  73. 确认收货
  74. </view>
  75. <view class="btm-btn ksps"
  76. @click.stop="navTo('/pages/order/orderRefund?id=' + item.order_id)"
  77. v-if="item._status._title == '未发货'||item._status._title == '未核销'">
  78. 申请退款
  79. </view>
  80. <view class="btm-btn ksps"
  81. @click.stop="navTo('/pages/order/WriteOff?id=' + item.order_id)"
  82. v-if="item._status._title == '待核销'">
  83. 核销码
  84. </view>
  85. <view class="btm-btn ksps" @click.stop="evaluate(item)"
  86. v-if="item._status._title == '待评价'">
  87. 立即评价
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <uni-load-more v-if="!(tabItem.orderList.length==0&&tabItem.loaded === true)" :status="tabItem.loadingType"></uni-load-more>
  93. </scroll-view>
  94. </swiper-item>
  95. </swiper>
  96. </view>
  97. </template>
  98. <script>
  99. import {
  100. orderList,
  101. orderCancel,
  102. orderDel,
  103. orderTake
  104. } from '@/api/order.js';
  105. export default {
  106. data() {
  107. return {
  108. tabCurrentIndex: 0,
  109. navList: [{
  110. state: 0,
  111. text: '待支付',
  112. loadingType: 'more',
  113. orderList: [],
  114. page: 1, //当前页数
  115. limit: 10 //每次信息条数
  116. },
  117. {
  118. state: 1,
  119. text: '待发货',
  120. loadingType: 'more',
  121. orderList: [],
  122. page: 1, //当前页数
  123. limit: 10 //每次信息条数
  124. },
  125. {
  126. state: 2,
  127. text: '待收货',
  128. loadingType: 'more',
  129. orderList: [],
  130. page: 1, //当前页数
  131. limit: 10 //每次信息条数
  132. },
  133. {
  134. state: 3,
  135. text: '待评价',
  136. loadingType: 'more',
  137. orderList: [],
  138. page: 1, //当前页数
  139. limit: 10 //每次信息条数
  140. },
  141. {
  142. state: 4,
  143. text: '已完成',
  144. loadingType: 'more',
  145. orderList: [],
  146. page: 1, //当前页数
  147. limit: 10 //每次信息条数
  148. }
  149. ]
  150. };
  151. },
  152. onLoad(options) {
  153. this.loadData();
  154. },
  155. // #ifdef APP-PLUS || H5
  156. onBackPress(e) {
  157. uni.switchTab({
  158. url: '/pages/user/user',
  159. });
  160. return true;
  161. },
  162. // #endif
  163. methods: {
  164. // 评价
  165. evaluate(item){
  166. if(item.cartInfo.length==1){
  167. uni.navigateTo({
  168. url: '/pages/order/evaluate?unique=' + item.cartInfo[0].unique
  169. });
  170. }else{
  171. this.navTo( '/pages/order/orderDetail?type=1&id=' + item.order_id )
  172. }
  173. },
  174. // 确认收货
  175. orderTake(item, index) {
  176. let obj = this;
  177. uni.showModal({
  178. title: '是否确认收货?',
  179. success: () => {
  180. orderTake({
  181. uni: item.order_id
  182. })
  183. .then(e => {
  184. obj.navList[obj.tabCurrentIndex].orderList.splice(index, 1);
  185. uni.showToast({
  186. title: '收货成功'
  187. });
  188. })
  189. .catch(e => {
  190. console.log(e);
  191. });
  192. }
  193. });
  194. },
  195. // 跳转页面
  196. navTo(url) {
  197. uni.navigateTo({
  198. url
  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') {
  208. navItem.page = 1;
  209. navItem.orderList = [];
  210. navItem.loadingType = 'more';
  211. navItem.loaded=false;
  212. //tab切换只有第一次需要加载数据
  213. }
  214. if (navItem.loadingType === 'loading') {
  215. //防止重复加载
  216. return;
  217. }
  218. if (navItem.loadingType === 'noMore') {
  219. //防止重复加载
  220. return;
  221. }
  222. // 修改当前对象状态为加载中
  223. navItem.loadingType = 'loading';
  224. orderList({
  225. type: state,
  226. page: navItem.page,
  227. limit: navItem.limit
  228. })
  229. .then(({
  230. data
  231. }) => {
  232. let arr = data.map(e => {
  233. let b = this.orderStateExp(e.status);
  234. e.stateTip = b.stateTip;
  235. e.stateTipColor = b.stateTipColor;
  236. return e;
  237. });
  238. navItem.orderList = navItem.orderList.concat(arr);
  239. // console.log(navItem.orderList);
  240. navItem.page++;
  241. if (navItem.limit == data.length) {
  242. //判断是否还有数据, 有改为 more, 没有改为noMore
  243. navItem.loadingType = 'more';
  244. return;
  245. } else {
  246. //判断是否还有数据, 有改为 more, 没有改为noMore
  247. navItem.loadingType = 'noMore';
  248. }
  249. uni.hideLoading();
  250. this.$set(navItem, 'loaded', true);
  251. })
  252. .catch(e => {
  253. console.log(e);
  254. });
  255. },
  256. //swiper 切换
  257. changeTab(e) {
  258. this.tabCurrentIndex = e.target.current;
  259. this.loadData('tabChange');
  260. },
  261. //顶部tab点击
  262. tabClick(index) {
  263. this.tabCurrentIndex = index;
  264. },
  265. //删除订单
  266. deleteOrder(index) {
  267. uni.showLoading({
  268. title: '请稍后',
  269. mask: true
  270. });
  271. setTimeout(() => {
  272. this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
  273. uni.hideLoading();
  274. }, 600);
  275. },
  276. //取消订单
  277. cancelOrder(item) {
  278. uni.showModal({
  279. title: '订单取消',
  280. content: '是否取消订单?',
  281. success: e => {
  282. if (e.confirm) {
  283. uni.showLoading({
  284. title: '请稍后',
  285. mask: true
  286. });
  287. orderCancel({
  288. id: item.order_id
  289. })
  290. .then(e => {
  291. uni.showToast({
  292. title: '取消成功',
  293. duration: 2000,
  294. position: 'top'
  295. });
  296. })
  297. .catch(e => {
  298. console.log(e);
  299. });
  300. //取消订单后删除待付款中该项
  301. let list = this.navList[this.tabCurrentIndex].orderList;
  302. let index = list.findIndex(val => val.id === item.id);
  303. index !== -1 && list.splice(index, 1);
  304. uni.hideLoading();
  305. }
  306. }
  307. });
  308. },
  309. //订单状态文字和颜色
  310. orderStateExp(state) {
  311. let stateTip = '',
  312. stateTipColor = '#3C82E6';
  313. switch (+state) {
  314. case 0:
  315. stateTip = '待付款';
  316. stateTipColor = '#3C82E6'
  317. break;
  318. case 1:
  319. stateTip = '待发货';
  320. stateTipColor = '#3C82E6'
  321. break;
  322. case 2:
  323. stateTip = '待收货';
  324. break;
  325. case 3:
  326. stateTip = '待评价';
  327. break;
  328. case 4:
  329. stateTip = '已完成';
  330. stateTipColor = '#999999';
  331. break;
  332. case 9:
  333. stateTip = '订单已关闭';
  334. stateTipColor = '#909399';
  335. break;
  336. //更多自定义
  337. }
  338. return {
  339. stateTip,
  340. stateTipColor
  341. };
  342. }
  343. }
  344. };
  345. </script>
  346. <style lang="scss">
  347. .content {
  348. height: 100%;
  349. background: linear-gradient(180deg, rgba(#3C82E6, 0.3), rgba(#5395F5, 0));
  350. background-size: 100% 645rpx;
  351. background-repeat: no-repeat;
  352. }
  353. .header {
  354. padding-top: var(--status-bar-height);
  355. .title {
  356. height: 50px;
  357. font-size: 18px;
  358. line-height: 50px;
  359. text-align: center;
  360. font-weight: bold;
  361. }
  362. }
  363. .swiper-box {
  364. height: calc(100% - 90px);
  365. }
  366. .list-scroll-content {
  367. height: 100%;
  368. padding-top: 30rpx;
  369. }
  370. .navbar {
  371. display: flex;
  372. height: 40px;
  373. padding: 6px;
  374. background: $bg-gradual;
  375. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  376. position: relative;
  377. z-index: 10;
  378. margin: 0 30rpx;
  379. border-radius: 99rpx;
  380. .nav-item {
  381. flex: 1;
  382. display: flex;
  383. justify-content: center;
  384. align-items: center;
  385. height: 28px;
  386. font-size: 15px;
  387. line-height: 28px;
  388. color: #FFF;
  389. position: relative;
  390. &.current {
  391. color: $base-color;
  392. background-color: #FFF;
  393. border-radius: 99rpx;
  394. }
  395. }
  396. }
  397. .order-item {
  398. padding-left: 30rpx;
  399. padding-right: 30rpx;
  400. margin: 0 30rpx;
  401. margin-bottom: 30rpx;
  402. border-radius: 30rpx;
  403. background: #fff;
  404. color: #A8ADBF;
  405. .i-top {
  406. height: 80rpx;
  407. .order-code{
  408. font-size: $font-sm;
  409. .no{
  410. padding: 10rpx 10rpx;
  411. background-color: #FFEAE5;
  412. color: #FD5B23;
  413. line-height: 1;
  414. border-top-right-radius: 10rpx;
  415. border-bottom-left-radius: 10rpx;
  416. margin-right: 10rpx;
  417. }
  418. }
  419. .del-btn {
  420. padding: 10rpx 0 10rpx 36rpx;
  421. font-size: $font-lg;
  422. position: relative;
  423. &:after {
  424. content: '';
  425. width: 0;
  426. height: 30rpx;
  427. border-left: 1px solid $border-color-dark;
  428. position: absolute;
  429. left: 20rpx;
  430. top: 50%;
  431. transform: translateY(-50%);
  432. }
  433. }
  434. }
  435. .info-info {
  436. width: 215rpx;
  437. height: 200rpx;
  438. position: absolute;
  439. top: 80rpx;
  440. right: 35rpx;
  441. display: flex;
  442. flex-direction: column;
  443. justify-content: flex-end;
  444. align-items: flex-end;
  445. font-size: 30rpx;
  446. font-weight: 500;
  447. .hj {
  448. padding-top: 40rpx;
  449. color: $font-color-dark;
  450. padding-bottom: 20rpx;
  451. }
  452. }
  453. /* 多条商品 */
  454. .goods-box {
  455. height: 200rpx;
  456. padding: 20rpx 0;
  457. white-space: nowrap;
  458. padding-right: 250rpx;
  459. .goods-item {
  460. width: 120rpx;
  461. height: 180rpx;
  462. display: inline-block;
  463. margin-right: 24rpx;
  464. }
  465. .goods-img {
  466. display: block;
  467. width: 120rpx;
  468. height: 120rpx;
  469. }
  470. .good-name {
  471. font-size: 24rpx;
  472. text-align: center;
  473. width: 120rpx;
  474. padding-top: 10rpx;
  475. margin-right: 0;
  476. color: $font-color-dark;
  477. }
  478. }
  479. .btm-btn-wrap {
  480. height: 90rpx;
  481. width: 100%;
  482. font-size: 24rpx;
  483. font-weight: 500;
  484. color: #A3A8BB;
  485. line-height: 1;
  486. .btm-right {
  487. justify-content: flex-end;
  488. }
  489. .btm-btn {
  490. width: 144rpx;
  491. padding: 10rpx 0;
  492. border: 2px solid #ededed;
  493. border-radius: 28rpx;
  494. font-size: 26rpx;
  495. font-weight: 500;
  496. text-align: center;
  497. margin-left: 10rpx;
  498. color: #999999;
  499. }
  500. .ksps {
  501. border-color: #4589ec;
  502. color: #4589ec;
  503. }
  504. }
  505. }
  506. ::v-deep .empty-content {
  507. background: transparent;
  508. }
  509. </style>