cart.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view class="container">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item" @click="navChoose(index)" :class="{ navC: index == navIc }">{{ item.text }}</view>
  5. </view>
  6. <!-- 订单列表 -->
  7. <swiper :current="navIc" class="swiper-box" duration="300" @change="changeTab" :style="{ height: maxheight }">
  8. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  9. <scroll-view scroll-y="true" class="scroll-y">
  10. <view class="order-item" @click="goToOrderDetail(i)" v-for="i in tabItem.orderList" :key="i.id">
  11. <view class="i-td">
  12. <view class="td-left">订单编号:{{ i.order_id }}</view>
  13. <view class="td-right">{{ i.stateTip }}</view>
  14. </view>
  15. <view class="goods-box" v-for="(item, index) in i.cartInfo">
  16. <view class="goods-left flex">
  17. <image class="goods-img" :src="item.productInfo.image || '../../static/error/errorImage.jpg'"></image>
  18. <view class="goods-name">
  19. <view class="p clamp2">{{ item.productInfo.store_name }}</view>
  20. <view class="span">{{ i.shipping_type == 1 ? '送货上门' : '到店自提' }}</view>
  21. </view>
  22. </view>
  23. <view class="goods-price">
  24. <view class="">¥{{ price(item.productInfo.attrInfo.price) }}</view>
  25. <view class="num">x{{ item.cart_num }}</view>
  26. <br />
  27. </view>
  28. </view>
  29. <view class="i-td">
  30. <view class="td-left"></view>
  31. <view class="i-bottom">
  32. 共计{{ i.total_num }}件商品
  33. <text>合计 ¥{{ i.pay_price }}</text>
  34. ( {{ i.pay_postage * 1 > 0 ? '含物流费用¥' + i.pay_postage * 1 : '免邮' }})
  35. </view>
  36. </view>
  37. <view class="btn-box" v-if="tabItem.state == 0">
  38. <view class="btn" @click.stop="qxzf(i)">取消支付</view>
  39. <view class="btn" @click.stop="ljzf(i)">立即支付</view>
  40. </view>
  41. <view class="btn-box" v-if="tabItem.state == 1">
  42. <view class="btn" @click.stop="sqth(i)" v-if="i.store_id != 0 && !i.is_virtual">申请退款</view>
  43. <view class="btn" @click.stop="sqth(i)" v-if="i.store_id == 0 && i.gift_uid == 0 && !i.is_virtual">申请退款</view>
  44. <view v-if="i.shipping_type == 2">
  45. <view class="btn" @click.stop="showCode(i)" v-if="i.gift_uid == 0 || i.gift_uid == userInfo.uid">查看券码</view>
  46. </view>
  47. </view>
  48. <view class="btn-box" v-if="tabItem.state == 2">
  49. <!-- <view v-if="i.shipping_type == 1" class="btn-look">查看物流</view> -->
  50. <view v-if="i.shipping_type == 1" class="btn" @click.stop="orderTake(i, index)">确认收货</view>
  51. <view v-if="i.shipping_type == 2">
  52. <view class="btn" @click.stop="showCode(i)" v-if="i.gift_uid == 0 || i.gift_uid == userInfo.uid">查看券码</view>
  53. </view>
  54. </view>
  55. </view>
  56. </scroll-view>
  57. </swiper-item>
  58. </swiper>
  59. </view>
  60. </template>
  61. <script>
  62. import { orderList, orderCancel, orderDel, orderTake } from '@/api/order.js';
  63. import { mapState, mapMutations } from 'vuex';
  64. export default {
  65. computed: {
  66. ...mapState('user', ['userInfo'])
  67. },
  68. onReady(res) {
  69. var _this = this;
  70. uni.getSystemInfo({
  71. success: resu => {
  72. const query = uni.createSelectorQuery();
  73. query.select('.swiper-box').boundingClientRect();
  74. query.exec(function(res) {
  75. _this.maxheight = resu.windowHeight - res[0].top + 'px';
  76. console.log('打印页面的剩余高度', _this.height);
  77. });
  78. },
  79. fail: res => {}
  80. });
  81. },
  82. data() {
  83. return {
  84. maxheight: '',
  85. navIc: 0,
  86. navList: [
  87. {
  88. state: 0,
  89. text: '待付款',
  90. loadingType: 'more',
  91. orderList: [],
  92. page: 1, //当前页数
  93. limit: 10 //每次信息条数
  94. },
  95. {
  96. state: 1,
  97. text: '待发货',
  98. loadingType: 'more',
  99. orderList: [],
  100. page: 1, //当前页数
  101. limit: 10 //每次信息条数
  102. },
  103. {
  104. state: 2,
  105. text: '待收货',
  106. loadingType: 'more',
  107. orderList: [],
  108. page: 1, //当前页数
  109. limit: 10 //每次信息条数
  110. },
  111. {
  112. state: 3,
  113. text: '已完成',
  114. loadingType: 'more',
  115. orderList: [],
  116. page: 1, //当前页数
  117. limit: 10 //每次信息条数
  118. },
  119. {
  120. state: -1,
  121. text: '退款中',
  122. loadingType: 'more',
  123. orderList: [],
  124. page: 1, //当前页数
  125. limit: 10 //每次信息条数
  126. },
  127. {
  128. state: -2,
  129. text: '已退款',
  130. loadingType: 'more',
  131. orderList: [],
  132. page: 1, //当前页数
  133. limit: 10 //每次信息条数
  134. }
  135. ]
  136. };
  137. },
  138. onShow() {
  139. this.navList = [
  140. {
  141. state: 0,
  142. text: '待付款',
  143. loadingType: 'more',
  144. orderList: [],
  145. page: 1, //当前页数
  146. limit: 10 //每次信息条数
  147. },
  148. {
  149. state: 1,
  150. text: '待发货',
  151. loadingType: 'more',
  152. orderList: [],
  153. page: 1, //当前页数
  154. limit: 10 //每次信息条数
  155. },
  156. {
  157. state: 2,
  158. text: '待收货',
  159. loadingType: 'more',
  160. orderList: [],
  161. page: 1, //当前页数
  162. limit: 10 //每次信息条数
  163. },
  164. {
  165. state: 3,
  166. text: '已完成',
  167. loadingType: 'more',
  168. orderList: [],
  169. page: 1, //当前页数
  170. limit: 10 //每次信息条数
  171. },
  172. {
  173. state: -1,
  174. text: '退款中',
  175. loadingType: 'more',
  176. orderList: [],
  177. page: 1, //当前页数
  178. limit: 10 //每次信息条数
  179. },
  180. {
  181. state: -2,
  182. text: '已退款',
  183. loadingType: 'more',
  184. orderList: [],
  185. page: 1, //当前页数
  186. limit: 10 //每次信息条数
  187. }
  188. ];
  189. this.loadData();
  190. },
  191. methods: {
  192. navChoose(index) {
  193. this.navIc = index;
  194. this.loadData();
  195. },
  196. price(price) {
  197. return (price * 1).toFixed(2);
  198. },
  199. //swiper 切换
  200. changeTab(e) {
  201. this.navIc = e.target.current;
  202. this.loadData('tabChange');
  203. },
  204. //获取订单列表
  205. loadData(source) {
  206. //这里是将订单挂载到tab列表下
  207. let index = this.navIc;
  208. let navItem = this.navList[index];
  209. let state = navItem.state;
  210. if (source === 'tabChange' && navItem.loaded === true) {
  211. //tab切换只有第一次需要加载数据
  212. return;
  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(({ data }) => {
  230. console.log(data);
  231. let arr = data.map(e => {
  232. console.log(e, 123456);
  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. navItem.page++;
  240. if (navItem.limit == data.length) {
  241. //判断是否还有数据, 有改为 more, 没有改为noMore
  242. navItem.loadingType = 'more';
  243. return;
  244. } else {
  245. //判断是否还有数据, 有改为 more, 没有改为noMore
  246. navItem.loadingType = 'noMore';
  247. }
  248. uni.hideLoading();
  249. this.$set(navItem, 'loaded', true);
  250. })
  251. .catch(e => {
  252. console.log(e);
  253. });
  254. },
  255. orderTake(item, index) {
  256. let obj = this;
  257. uni.showModal({
  258. title: '是否确认收货?',
  259. success: res => {
  260. if (res.confirm) {
  261. orderTake({
  262. uni: item.order_id
  263. })
  264. .then(e => {
  265. obj.navList[obj.navIc].orderList.splice(index, 1);
  266. uni.showToast({
  267. title: '收货成功'
  268. });
  269. })
  270. .catch(e => {
  271. console.log(e);
  272. });
  273. } else if (res.cancel) {
  274. console.log('取消');
  275. }
  276. }
  277. });
  278. },
  279. //跳转到订单详情
  280. goToOrderDetail(e) {
  281. uni.navigateTo({
  282. url: '/pages/order/orderDetail?id=' + e.order_id
  283. });
  284. },
  285. showCode(e) {
  286. uni.navigateTo({
  287. url: '/pages/order/verifyCode?id=' + e.order_id
  288. });
  289. },
  290. orderStateExp(state) {
  291. let stateTip = '',
  292. stateTipColor = '#fa436a';
  293. switch (+state) {
  294. case 0:
  295. stateTip = '待发货';
  296. break;
  297. case 1:
  298. stateTip = '待收货';
  299. break;
  300. case 2:
  301. stateTip = '已完成';
  302. break;
  303. case 3:
  304. stateTip = '待评价';
  305. break;
  306. case 4:
  307. stateTip = '已完成';
  308. stateTipColor = '#901b21';
  309. break;
  310. case 9:
  311. stateTip = '订单已关闭';
  312. stateTipColor = '#909399';
  313. break;
  314. //更多自定义
  315. }
  316. return {
  317. stateTip,
  318. stateTipColor
  319. };
  320. },
  321. qxzf(item) {
  322. uni.showModal({
  323. title: '订单取消',
  324. content: '是否取消订单?',
  325. success: e => {
  326. if (e.confirm) {
  327. uni.showLoading({
  328. title: '请稍后'
  329. });
  330. orderCancel({ id: item.order_id })
  331. .then(e => {
  332. uni.showToast({
  333. title: '取消成功',
  334. duration: 2000,
  335. position: 'top'
  336. });
  337. })
  338. .catch(e => {
  339. console.log(e);
  340. });
  341. //取消订单后删除待付款中该项
  342. let list = this.navList[this.navIc].orderList;
  343. let index = list.findIndex(val => val.id === item.id);
  344. index !== -1 && list.splice(index, 1);
  345. uni.hideLoading();
  346. }
  347. }
  348. });
  349. },
  350. ljzf(e) {
  351. let yajin = 0;
  352. e.cartInfo.forEach(item => {
  353. console.log(item.deposit);
  354. yajin += item.deposit * 1;
  355. });
  356. console.log(yajin);
  357. uni.navigateTo({
  358. url: '/pages/money/pay?type=1&ordid=' + e.order_id + '&money=' + (e.pay_price * 1 + yajin)
  359. });
  360. },
  361. sqth(i) {
  362. uni.navigateTo({
  363. url: '/pages/order/orderRefund?id=' + i.order_id
  364. });
  365. }
  366. }
  367. };
  368. </script>
  369. <style lang="scss" scoped>
  370. page {
  371. min-height: 100%;
  372. height: auto;
  373. background: #f8f1f2;
  374. }
  375. .container {
  376. width: 100%;
  377. min-height: 100%;
  378. height: auto;
  379. position: fixed;
  380. .navbar {
  381. position: relative;
  382. z-index: 10;
  383. margin: 20rpx;
  384. display: flex;
  385. border-radius: 40rpx;
  386. background-color: #ee2f72;
  387. .nav-item {
  388. margin: 0 10rpx;
  389. text-align: center;
  390. flex: 1;
  391. color: #ffffff;
  392. font-size: 28rpx;
  393. margin: 10rpx;
  394. line-height: 60rpx;
  395. }
  396. .navC {
  397. background-color: #ffffff;
  398. color: #ee2f72;
  399. line-height: 60rpx;
  400. border-radius: 50rpx;
  401. }
  402. }
  403. .tab-content,
  404. .scroll-y {
  405. height: 100%;
  406. }
  407. .order-item {
  408. display: grid;
  409. margin-bottom: 20rpx;
  410. }
  411. .btn-box {
  412. border-top: 1px solid #f2f2f2;
  413. height: 100rpx;
  414. width: 100%;
  415. padding-right: 20rpx;
  416. background-color: #ffffff;
  417. display: flex;
  418. justify-content: flex-end;
  419. align-items: center;
  420. .btn {
  421. margin-left: 10rpx;
  422. width: 144rpx;
  423. height: 55rpx;
  424. border: 1px solid #ee2f72;
  425. border-radius: 28rpx;
  426. font-size: 26rpx;
  427. font-family: PingFang SC;
  428. font-weight: 500;
  429. color: #ee2f72;
  430. line-height: 55rpx;
  431. text-align: center;
  432. }
  433. .btn-look {
  434. margin-left: 10rpx;
  435. width: 144rpx;
  436. height: 55rpx;
  437. border: 1px solid #ebebeb;
  438. border-radius: 28rpx;
  439. font-size: 26rpx;
  440. font-family: PingFang SC;
  441. font-weight: 500;
  442. color: #999999;
  443. line-height: 55rpx;
  444. text-align: center;
  445. }
  446. }
  447. .i-td {
  448. display: flex;
  449. justify-content: space-between;
  450. background-color: #ffffff;
  451. padding: 20rpx;
  452. color: #999999;
  453. font-size: 25rpx;
  454. .i-bottom {
  455. span {
  456. margin: 0 10rpx;
  457. b {
  458. font-size: 28rpx;
  459. color: #4f4f4f;
  460. }
  461. }
  462. }
  463. }
  464. .goods-box {
  465. height: 100%;
  466. display: flex;
  467. justify-content: space-between;
  468. background-color: #f7f7f7;
  469. padding: 20rpx;
  470. .goods-left {
  471. align-items: flex-start;
  472. .goods-img {
  473. width: 160rpx;
  474. height: 160rpx;
  475. }
  476. .goods-name {
  477. margin: 10rpx 40rpx;
  478. color: #666666;
  479. font-size: 30rpx;
  480. .p {
  481. max-width: 300rpx;
  482. margin-bottom: 10rpx;
  483. }
  484. .span {
  485. width: 120rpx;
  486. background-color: #ffeae5;
  487. color: #fd5b23;
  488. text-align: center;
  489. font-size: 24rpx;
  490. padding: 5rpx;
  491. border-radius: 5rpx;
  492. }
  493. }
  494. }
  495. .goods-price {
  496. margin: 10rpx 0;
  497. text-align: right;
  498. display: grid;
  499. color: #999999;
  500. font-size: 24rpx;
  501. position: relative;
  502. b {
  503. color: #ee2f72;
  504. font-size: 35rpx;
  505. }
  506. .num {
  507. position: absolute;
  508. bottom: 20rpx;
  509. right: 10rpx;
  510. }
  511. }
  512. }
  513. }
  514. </style>