order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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: 3,
  127. text: '待评价',
  128. loadingType: 'more',
  129. orderList: [],
  130. page: 1, //当前页数
  131. limit: 10 //每次信息条数
  132. },
  133. {
  134. state: 4,
  135. text: '已完成',
  136. loadingType: 'more',
  137. orderList: [],
  138. page: 1, //当前页数
  139. limit: 10 //每次信息条数
  140. }
  141. ]
  142. };
  143. },
  144. onLoad(options) {
  145. this.loadData();
  146. },
  147. // #ifdef APP-PLUS || H5
  148. onBackPress(e) {
  149. uni.switchTab({
  150. url: '/pages/user/user',
  151. });
  152. return true;
  153. },
  154. // #endif
  155. methods: {
  156. // 评价
  157. evaluate(item){
  158. if(item.cartInfo.length==1){
  159. uni.navigateTo({
  160. url: '/pages/order/evaluate?unique=' + item.cartInfo[0].unique
  161. });
  162. }else{
  163. this.navTo( '/pages/order/orderDetail?type=1&id=' + item.order_id )
  164. }
  165. },
  166. // 确认收货
  167. orderTake(item, index) {
  168. let obj = this;
  169. uni.showModal({
  170. title: '是否确认收货?',
  171. success: () => {
  172. orderTake({
  173. uni: item.order_id
  174. })
  175. .then(e => {
  176. obj.navList[obj.tabCurrentIndex].orderList.splice(index, 1);
  177. uni.showToast({
  178. title: '收货成功'
  179. });
  180. })
  181. .catch(e => {
  182. console.log(e);
  183. });
  184. }
  185. });
  186. },
  187. // 跳转页面
  188. navTo(url) {
  189. uni.navigateTo({
  190. url
  191. });
  192. },
  193. //获取订单列表
  194. loadData(source) {
  195. //这里是将订单挂载到tab列表下
  196. let index = this.tabCurrentIndex;
  197. let navItem = this.navList[index];
  198. let state = navItem.state;
  199. if (source === 'tabChange') {
  200. navItem.page = 1;
  201. navItem.orderList = [];
  202. navItem.loadingType = 'more';
  203. navItem.loaded=false;
  204. //tab切换只有第一次需要加载数据
  205. }
  206. if (navItem.loadingType === 'loading') {
  207. //防止重复加载
  208. return;
  209. }
  210. if (navItem.loadingType === 'noMore') {
  211. //防止重复加载
  212. return;
  213. }
  214. // 修改当前对象状态为加载中
  215. navItem.loadingType = 'loading';
  216. orderList({
  217. type: state,
  218. page: navItem.page,
  219. limit: navItem.limit
  220. })
  221. .then(({
  222. data
  223. }) => {
  224. let arr = data.map(e => {
  225. let b = this.orderStateExp(e.status);
  226. e.stateTip = b.stateTip;
  227. e.stateTipColor = b.stateTipColor;
  228. return e;
  229. });
  230. navItem.orderList = navItem.orderList.concat(arr);
  231. // console.log(navItem.orderList);
  232. navItem.page++;
  233. if (navItem.limit == data.length) {
  234. //判断是否还有数据, 有改为 more, 没有改为noMore
  235. navItem.loadingType = 'more';
  236. return;
  237. } else {
  238. //判断是否还有数据, 有改为 more, 没有改为noMore
  239. navItem.loadingType = 'noMore';
  240. }
  241. uni.hideLoading();
  242. this.$set(navItem, 'loaded', true);
  243. })
  244. .catch(e => {
  245. console.log(e);
  246. });
  247. },
  248. //swiper 切换
  249. changeTab(e) {
  250. this.tabCurrentIndex = e.target.current;
  251. this.loadData('tabChange');
  252. },
  253. //顶部tab点击
  254. tabClick(index) {
  255. this.tabCurrentIndex = index;
  256. },
  257. //删除订单
  258. deleteOrder(index) {
  259. uni.showLoading({
  260. title: '请稍后',
  261. mask: true
  262. });
  263. setTimeout(() => {
  264. this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
  265. uni.hideLoading();
  266. }, 600);
  267. },
  268. //取消订单
  269. cancelOrder(item) {
  270. uni.showModal({
  271. title: '订单取消',
  272. content: '是否取消订单?',
  273. success: e => {
  274. if (e.confirm) {
  275. uni.showLoading({
  276. title: '请稍后',
  277. mask: true
  278. });
  279. orderCancel({
  280. id: item.order_id
  281. })
  282. .then(e => {
  283. uni.showToast({
  284. title: '取消成功',
  285. duration: 2000,
  286. position: 'top'
  287. });
  288. })
  289. .catch(e => {
  290. console.log(e);
  291. });
  292. //取消订单后删除待付款中该项
  293. let list = this.navList[this.tabCurrentIndex].orderList;
  294. let index = list.findIndex(val => val.id === item.id);
  295. index !== -1 && list.splice(index, 1);
  296. uni.hideLoading();
  297. }
  298. }
  299. });
  300. },
  301. //订单状态文字和颜色
  302. orderStateExp(state) {
  303. let stateTip = '',
  304. stateTipColor = '#3C82E6';
  305. switch (+state) {
  306. case 0:
  307. stateTip = '待付款';
  308. stateTipColor = '#3C82E6'
  309. break;
  310. case 1:
  311. stateTip = '待发货';
  312. stateTipColor = '#3C82E6'
  313. break;
  314. case 2:
  315. stateTip = '待收货';
  316. break;
  317. case 3:
  318. stateTip = '待评价';
  319. break;
  320. case 4:
  321. stateTip = '已完成';
  322. stateTipColor = '#999999';
  323. break;
  324. case 9:
  325. stateTip = '订单已关闭';
  326. stateTipColor = '#909399';
  327. break;
  328. //更多自定义
  329. }
  330. return {
  331. stateTip,
  332. stateTipColor
  333. };
  334. }
  335. }
  336. };
  337. </script>
  338. <style lang="scss">
  339. .content {
  340. height: 100%;
  341. background: linear-gradient(180deg, rgba(#3C82E6, 0.3), rgba(#5395F5, 0));
  342. background-size: 100% 645rpx;
  343. background-repeat: no-repeat;
  344. }
  345. .header {
  346. padding-top: var(--status-bar-height);
  347. .title {
  348. height: 50px;
  349. font-size: 18px;
  350. line-height: 50px;
  351. text-align: center;
  352. font-weight: bold;
  353. }
  354. }
  355. .swiper-box {
  356. height: calc(100% - 90px);
  357. }
  358. .list-scroll-content {
  359. height: 100%;
  360. padding-top: 30rpx;
  361. }
  362. .navbar {
  363. display: flex;
  364. height: 40px;
  365. padding: 6px;
  366. background: $bg-gradual;
  367. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  368. position: relative;
  369. z-index: 10;
  370. margin: 0 30rpx;
  371. border-radius: 99rpx;
  372. .nav-item {
  373. flex: 1;
  374. display: flex;
  375. justify-content: center;
  376. align-items: center;
  377. height: 28px;
  378. font-size: 15px;
  379. line-height: 28px;
  380. color: #FFF;
  381. position: relative;
  382. &.current {
  383. color: $base-color;
  384. background-color: #FFF;
  385. border-radius: 99rpx;
  386. }
  387. }
  388. }
  389. .order-item {
  390. padding-left: 30rpx;
  391. padding-right: 30rpx;
  392. margin: 0 30rpx;
  393. margin-bottom: 30rpx;
  394. border-radius: 30rpx;
  395. background: #fff;
  396. color: #A8ADBF;
  397. .i-top {
  398. height: 80rpx;
  399. .order-code{
  400. font-size: $font-sm;
  401. .no{
  402. padding: 10rpx 10rpx;
  403. background-color: #FFEAE5;
  404. color: #FD5B23;
  405. line-height: 1;
  406. border-top-right-radius: 10rpx;
  407. border-bottom-left-radius: 10rpx;
  408. margin-right: 10rpx;
  409. }
  410. }
  411. .del-btn {
  412. padding: 10rpx 0 10rpx 36rpx;
  413. font-size: $font-lg;
  414. position: relative;
  415. &:after {
  416. content: '';
  417. width: 0;
  418. height: 30rpx;
  419. border-left: 1px solid $border-color-dark;
  420. position: absolute;
  421. left: 20rpx;
  422. top: 50%;
  423. transform: translateY(-50%);
  424. }
  425. }
  426. }
  427. .info-info {
  428. width: 215rpx;
  429. height: 200rpx;
  430. position: absolute;
  431. top: 80rpx;
  432. right: 35rpx;
  433. display: flex;
  434. flex-direction: column;
  435. justify-content: flex-end;
  436. align-items: flex-end;
  437. font-size: 30rpx;
  438. font-weight: 500;
  439. .hj {
  440. padding-top: 40rpx;
  441. color: $font-color-dark;
  442. padding-bottom: 20rpx;
  443. }
  444. }
  445. /* 多条商品 */
  446. .goods-box {
  447. height: 200rpx;
  448. padding: 20rpx 0;
  449. white-space: nowrap;
  450. padding-right: 250rpx;
  451. .goods-item {
  452. width: 120rpx;
  453. height: 180rpx;
  454. display: inline-block;
  455. margin-right: 24rpx;
  456. }
  457. .goods-img {
  458. display: block;
  459. width: 120rpx;
  460. height: 120rpx;
  461. }
  462. .good-name {
  463. font-size: 24rpx;
  464. text-align: center;
  465. width: 120rpx;
  466. padding-top: 10rpx;
  467. margin-right: 0;
  468. color: $font-color-dark;
  469. }
  470. }
  471. .btm-btn-wrap {
  472. height: 90rpx;
  473. width: 100%;
  474. font-size: 24rpx;
  475. font-weight: 500;
  476. color: #A3A8BB;
  477. line-height: 1;
  478. .btm-right {
  479. justify-content: flex-end;
  480. }
  481. .btm-btn {
  482. width: 144rpx;
  483. padding: 10rpx 0;
  484. border: 2px solid #ededed;
  485. border-radius: 28rpx;
  486. font-size: 26rpx;
  487. font-weight: 500;
  488. text-align: center;
  489. margin-left: 10rpx;
  490. color: #999999;
  491. }
  492. .ksps {
  493. border-color: #4589ec;
  494. color: #4589ec;
  495. }
  496. }
  497. }
  498. /deep/ .empty-content {
  499. background: transparent;
  500. }
  501. </style>