cart.vue 12 KB

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