cart.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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">
  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 + i.pay_postage_sh * 1 > 0 ? '含物流费用¥' + (i.pay_postage * 1 + i.pay_postage_sh * 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">申请退款</view>
  43. <view class="btn" @click.stop="sqth(i)" v-if="i.store_id == 0 && i.gift_uid == 0">申请退款</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. data() {
  69. return {
  70. navIc: 0,
  71. navList: [
  72. {
  73. state: 0,
  74. text: '待付款',
  75. loadingType: 'more',
  76. orderList: [],
  77. page: 1, //当前页数
  78. limit: 10 //每次信息条数
  79. },
  80. {
  81. state: 1,
  82. text: '待发货',
  83. loadingType: 'more',
  84. orderList: [],
  85. page: 1, //当前页数
  86. limit: 10 //每次信息条数
  87. },
  88. {
  89. state: 2,
  90. text: '待收货',
  91. loadingType: 'more',
  92. orderList: [],
  93. page: 1, //当前页数
  94. limit: 10 //每次信息条数
  95. },
  96. {
  97. state: 3,
  98. text: '已完成',
  99. loadingType: 'more',
  100. orderList: [],
  101. page: 1, //当前页数
  102. limit: 10 //每次信息条数
  103. }
  104. ]
  105. };
  106. },
  107. onShow() {
  108. this.navList = [
  109. {
  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. this.loadData();
  143. },
  144. methods: {
  145. navChoose(index) {
  146. this.navIc = index;
  147. this.loadData();
  148. },
  149. price(price) {
  150. return (price * 1).toFixed(2);
  151. },
  152. //swiper 切换
  153. changeTab(e) {
  154. this.navIc = e.target.current;
  155. this.loadData('tabChange');
  156. },
  157. //获取订单列表
  158. loadData(source) {
  159. //这里是将订单挂载到tab列表下
  160. let index = this.navIc;
  161. let navItem = this.navList[index];
  162. let state = navItem.state;
  163. if (source === 'tabChange' && navItem.loaded === true) {
  164. //tab切换只有第一次需要加载数据
  165. return;
  166. }
  167. if (navItem.loadingType === 'loading') {
  168. //防止重复加载
  169. return;
  170. }
  171. if (navItem.loadingType === 'noMore') {
  172. //防止重复加载
  173. return;
  174. }
  175. // 修改当前对象状态为加载中
  176. navItem.loadingType = 'loading';
  177. orderList({
  178. type: state,
  179. page: navItem.page,
  180. limit: navItem.limit
  181. })
  182. .then(({ data }) => {
  183. console.log(data);
  184. let arr = data.map(e => {
  185. console.log(e, 123456);
  186. let b = this.orderStateExp(e.status);
  187. e.stateTip = b.stateTip;
  188. e.stateTipColor = b.stateTipColor;
  189. return e;
  190. });
  191. navItem.orderList = navItem.orderList.concat(arr);
  192. navItem.page++;
  193. if (navItem.limit == data.length) {
  194. //判断是否还有数据, 有改为 more, 没有改为noMore
  195. navItem.loadingType = 'more';
  196. return;
  197. } else {
  198. //判断是否还有数据, 有改为 more, 没有改为noMore
  199. navItem.loadingType = 'noMore';
  200. }
  201. uni.hideLoading();
  202. this.$set(navItem, 'loaded', true);
  203. })
  204. .catch(e => {
  205. console.log(e);
  206. });
  207. },
  208. orderTake(item, index) {
  209. let obj = this;
  210. uni.showModal({
  211. title: '是否确认收货?',
  212. success: res => {
  213. if (res.confirm) {
  214. orderTake({
  215. uni: item.order_id
  216. })
  217. .then(e => {
  218. obj.navList[obj.navIc].orderList.splice(index, 1);
  219. uni.showToast({
  220. title: '收货成功'
  221. });
  222. })
  223. .catch(e => {
  224. console.log(e);
  225. });
  226. } else if (res.cancel) {
  227. console.log('取消');
  228. }
  229. }
  230. });
  231. },
  232. //跳转到订单详情
  233. goToOrderDetail(e) {
  234. uni.navigateTo({
  235. url: '/pages/order/orderDetail?id=' + e.order_id
  236. });
  237. },
  238. showCode(e) {
  239. uni.navigateTo({
  240. url: '/pages/order/verifyCode?id=' + e.order_id
  241. });
  242. },
  243. orderStateExp(state) {
  244. let stateTip = '',
  245. stateTipColor = '#fa436a';
  246. switch (+state) {
  247. case 0:
  248. stateTip = '待发货';
  249. break;
  250. case 1:
  251. stateTip = '待收货';
  252. break;
  253. case 2:
  254. stateTip = '已完成';
  255. break;
  256. case 3:
  257. stateTip = '待评价';
  258. break;
  259. case 4:
  260. stateTip = '已完成';
  261. stateTipColor = '#901b21';
  262. break;
  263. case 9:
  264. stateTip = '订单已关闭';
  265. stateTipColor = '#909399';
  266. break;
  267. //更多自定义
  268. }
  269. return {
  270. stateTip,
  271. stateTipColor
  272. };
  273. },
  274. qxzf(item) {
  275. uni.showModal({
  276. title: '订单取消',
  277. content: '是否取消订单?',
  278. success: e => {
  279. if (e.confirm) {
  280. uni.showLoading({
  281. title: '请稍后'
  282. });
  283. orderCancel({ id: item.order_id })
  284. .then(e => {
  285. uni.showToast({
  286. title: '取消成功',
  287. duration: 2000,
  288. position: 'top'
  289. });
  290. })
  291. .catch(e => {
  292. console.log(e);
  293. });
  294. //取消订单后删除待付款中该项
  295. let list = this.navList[this.navIc].orderList;
  296. let index = list.findIndex(val => val.id === item.id);
  297. index !== -1 && list.splice(index, 1);
  298. uni.hideLoading();
  299. }
  300. }
  301. });
  302. },
  303. ljzf(e) {
  304. let yajin = 0;
  305. e.cartInfo.forEach(item => {
  306. console.log(item.deposit);
  307. yajin += item.deposit * 1;
  308. });
  309. console.log(yajin);
  310. uni.navigateTo({
  311. url: '/pages/money/pay?type=1&ordid=' + e.order_id + '&money=' + (e.pay_price * 1 + yajin)
  312. });
  313. },
  314. sqth(i) {
  315. uni.navigateTo({
  316. url: '/pages/order/orderRefund?id=' + i.order_id
  317. });
  318. }
  319. }
  320. };
  321. </script>
  322. <style lang="scss" scoped>
  323. page {
  324. height: 100%;
  325. background: #f8f1f2;
  326. }
  327. .container {
  328. width: 100%;
  329. height: 100%;
  330. position: fixed;
  331. .navbar {
  332. position: relative;
  333. z-index: 10;
  334. margin: 20rpx;
  335. display: flex;
  336. border-radius: 40rpx;
  337. background-color: #ee2f72;
  338. .nav-item {
  339. margin: 0 10rpx;
  340. text-align: center;
  341. flex: 1;
  342. color: #ffffff;
  343. font-size: 28rpx;
  344. margin: 10rpx;
  345. line-height: 60rpx;
  346. }
  347. .navC {
  348. background-color: #ffffff;
  349. color: #ee2f72;
  350. line-height: 60rpx;
  351. border-radius: 50rpx;
  352. }
  353. }
  354. .swiper-box,
  355. .tab-content,
  356. .scroll-y {
  357. height: calc(100vh - 44px);
  358. }
  359. .order-item {
  360. display: grid;
  361. margin-bottom: 20rpx;
  362. }
  363. .btn-box {
  364. border-top: 1px solid #f2f2f2;
  365. height: 100rpx;
  366. width: 100%;
  367. padding-right: 20rpx;
  368. background-color: #ffffff;
  369. display: flex;
  370. justify-content: flex-end;
  371. align-items: center;
  372. .btn {
  373. margin-left: 10rpx;
  374. width: 144rpx;
  375. height: 55rpx;
  376. border: 1px solid #901b21;
  377. border-radius: 28rpx;
  378. font-size: 26rpx;
  379. font-family: PingFang SC;
  380. font-weight: 500;
  381. color: #901b21;
  382. line-height: 55rpx;
  383. text-align: center;
  384. }
  385. .btn-look {
  386. margin-left: 10rpx;
  387. width: 144rpx;
  388. height: 55rpx;
  389. border: 1px solid #ebebeb;
  390. border-radius: 28rpx;
  391. font-size: 26rpx;
  392. font-family: PingFang SC;
  393. font-weight: 500;
  394. color: #999999;
  395. line-height: 55rpx;
  396. text-align: center;
  397. }
  398. }
  399. .i-td {
  400. display: flex;
  401. justify-content: space-between;
  402. background-color: #ffffff;
  403. padding: 20rpx;
  404. color: #999999;
  405. font-size: 25rpx;
  406. .i-bottom {
  407. span {
  408. margin: 0 10rpx;
  409. b {
  410. font-size: 28rpx;
  411. color: #4f4f4f;
  412. }
  413. }
  414. }
  415. }
  416. .goods-box {
  417. height: 100%;
  418. display: flex;
  419. justify-content: space-between;
  420. background-color: #f7f7f7;
  421. padding: 20rpx;
  422. .goods-left {
  423. align-items: flex-start;
  424. .goods-img {
  425. width: 160rpx;
  426. height: 160rpx;
  427. }
  428. .goods-name {
  429. margin: 10rpx 40rpx;
  430. color: #666666;
  431. font-size: 30rpx;
  432. .p {
  433. max-width: 300rpx;
  434. margin-bottom: 10rpx;
  435. }
  436. .span {
  437. width: 120rpx;
  438. background-color: #ffeae5;
  439. color: #fd5b23;
  440. text-align: center;
  441. font-size: 24rpx;
  442. padding: 5rpx;
  443. border-radius: 5rpx;
  444. }
  445. }
  446. }
  447. .goods-price {
  448. margin: 10rpx 0;
  449. text-align: right;
  450. display: grid;
  451. color: #999999;
  452. font-size: 24rpx;
  453. position: relative;
  454. b {
  455. color: #901b21;
  456. font-size: 35rpx;
  457. }
  458. .num {
  459. position: absolute;
  460. bottom: 20rpx;
  461. right: 10rpx;
  462. }
  463. }
  464. }
  465. }
  466. </style>