order.vue 12 KB

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