shoppingCart.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false" title="购物车" :border-bottom="false" title-color="#333333" back-icon-color="#ffffff">
  4. <view class="slot-wrap"><image src="/static/logo2.png" style="width: 178rpx;height: 31rpx;margin-left: 30rpx;"></image></view>
  5. </u-navbar>
  6. <view v-show="isLogin">
  7. <view v-if="!list.length"><u-empty text="购物车为空" margin-top="500" mode="car"></u-empty></view>
  8. <view v-else>
  9. <view style="padding: 8rpx;padding-bottom: 98rpx;">
  10. <uni-swipe-action>
  11. <u-checkbox-group @change="checkboxGroupChange" placement="column" >
  12. <view>
  13. <uni-swipe-action-item :autoClose="false" @change="swipeChange($event, item)" :show="item.show" v-for="(item, index) in list" :key="index">
  14. <view class="goods-item">
  15. <view class="item-wrap">
  16. <view class="goods-msg">
  17. <u-checkbox @change="checkboxChange" :disabled="item.goodsStatus == 0" style="width: 100%;" v-model="list[index].checked" shape="circle" :name="index">
  18. <view class="flex">
  19. <view class="goods-img">
  20. <image :src="$method.splitImgHost(item.coverUrl, true)"></image>
  21. </view>
  22. <view class="flex__auto">
  23. <view class="goods-title">{{ item.goodsName }}</view>
  24. <view class="priceTag">¥ {{ item.standPrice }}</view>
  25. <view class="priceTag" v-if="item.goodsStatus == 0">该商品已下架</view>
  26. </view>
  27. </view>
  28. </u-checkbox>
  29. </view>
  30. <view class="goods-select" v-if="item.templateType != null && item.goodsType == 1">
  31. <u-line color="#D6D6DB" />
  32. <view class="goods-select__type" v-if="item.templateType == 'class'"
  33. @click="openPopup(0, item, index)">
  34. <view style="color: #666666;font-size: 24rpx;">{{ !item.gradObj.className ? '选择班级' : item.gradObj.className }}</view>
  35. <view><u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
  36. </view>
  37. <view class="goods-select__type" v-if="item.templateType == 'apply'"
  38. @click="openPopup(1, item, index)"
  39. >
  40. <view style="color: #666666;font-size: 24rpx;">
  41. {{
  42. !item.applyAreas.areaName
  43. ? '报考地区'
  44. : item.examDate.examineName + '-' + item.applyAreas.areaName + '-' + item.applyAreas.cityName
  45. }}
  46. </view>
  47. <view><u-icon name="arrow-right" color="#999999" size="28"></u-icon></view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <template v-slot:right>
  53. <view class="operate" @click="delItem(item)">
  54. <view><text>删除</text></view>
  55. </view>
  56. </template>
  57. </uni-swipe-action-item>
  58. </view>
  59. </u-checkbox-group>
  60. </uni-swipe-action>
  61. </view>
  62. <view class="bottomBox" v-if="!hideBuyState">
  63. <view>
  64. <u-checkbox label="all" name="all" shape="circle" @change="checkboxAllChange" v-model="allChecked"></u-checkbox>
  65. <text>全选</text>
  66. </view>
  67. <view style="display: flex;align-items: center;">
  68. <view style="color: #999999;margin-right: 8rpx;">合计</view>
  69. <view class="priceTag">¥ {{ toFixed(totalPrice) }}</view>
  70. <view style="display: flex;color: #FFFFFF;align-items: center;"><view class="btn2" @click="goBuy()">结算</view></view>
  71. </view>
  72. </view>
  73. </view>
  74. <u-popup v-model="show" mode="bottom" border-radius="40">
  75. <view class="popup_box">
  76. <view style="margin-bottom: 20rpx;">
  77. <view class="line1"></view>
  78. <view class="grade">选择班级</view>
  79. </view>
  80. <u-line color="#D6D6DB" />
  81. <view>
  82. <scroll-view scroll-y="true" style="height: 536rpx;">
  83. <view>
  84. <u-radio-group v-model="gradeValue">
  85. <view v-for="(item, index) in gradeList" :key="index">
  86. <view style="display: flex;align-items: center;padding: 20rpx;">
  87. <view>
  88. <u-radio shape="circle" :name="index">
  89. <view :class="index == gradeValue? 'white-box blue-box' : 'white-box'">
  90. <view>
  91. <view class="blackTxt">{{ item.className }}</view>
  92. <view class="redTxt" v-if="item.classEndTime">有效期至:{{ $method.timestampToTime(item.classEndTime) }}</view>
  93. <view class="redTxt" v-if="item.classEndTime">本班还剩{{ $method.GetRTime(item.classEndTime) }}天将结束学习</view>
  94. </view>
  95. </view>
  96. </u-radio>
  97. </view>
  98. </view>
  99. </view>
  100. </u-radio-group>
  101. </view>
  102. </scroll-view>
  103. </view>
  104. <view class="confrim-btn"><view class="okBtn" @click="okPopup(0)">确定</view></view>
  105. </view>
  106. </u-popup>
  107. <u-popup v-model="show1" mode="bottom" border-radius="40">
  108. <view class="popup_box">
  109. <view style="margin-bottom: 20rpx;">
  110. <view class="line1"></view>
  111. <view class="grade">选择考期/地区</view>
  112. </view>
  113. <u-line color="#D6D6DB" />
  114. <view style="display: flex;height: 536rpx;">
  115. <view style="width: 50%;">
  116. <view class="topTxt">考期</view>
  117. <view>
  118. <picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChangeE" class="picker-view">
  119. <picker-view-column>
  120. <view class="picker-item" v-for="(item, index) in examine" :key="index">{{ item.examineName }}</view>
  121. </picker-view-column>
  122. </picker-view>
  123. </view>
  124. </view>
  125. <view style="width: 50%;">
  126. <view class="topTxt">地区</view>
  127. <view>
  128. <picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view">
  129. <picker-view-column>
  130. <view class="picker-item" v-for="(item, index) in provinceList" :key="index">{{ item.areaName }}</view>
  131. </picker-view-column>
  132. <picker-view-column>
  133. <view class="picker-item" v-for="(item, index) in cityList" :key="index">{{ item.areaName }}</view>
  134. </picker-view-column>
  135. </picker-view>
  136. </view>
  137. </view>
  138. </view>
  139. <view class="confrim-btn"><view class="okBtn" @click="okPopup(1)">确定</view></view>
  140. </view>
  141. </u-popup>
  142. </view>
  143. <view v-show="!isLogin">
  144. <view style="display: flex;align-items:center;flex-direction: column;margin-top: 40%;font-size: 32rpx;">
  145. <view style="color: #999999;">您还没有登录哦~</view>
  146. <view style="margin-top: 30rpx;"><u-button type="primary" @click="login">去登录</u-button></view>
  147. </view>
  148. </view>
  149. </view>
  150. </template>
  151. <script>
  152. import { mapGetters } from 'vuex';
  153. export default {
  154. data() {
  155. return {
  156. gradeValue: -1,
  157. isLogin: false,
  158. allChecked: false,
  159. checkboxValue1: [],
  160. list: [],
  161. value1: '',
  162. show: false,
  163. show1: false,
  164. totalPrice: 0.0,
  165. isOld: false,
  166. checkboxList: [],
  167. gradeList: [],
  168. examine: [],
  169. provinceList: [],
  170. cityList: [],
  171. detail: {},
  172. detailIndex: -1,
  173. applyObj: {
  174. applyAreasJson: null,
  175. examDateJson: null
  176. },
  177. pAreaIndex: 0,
  178. cAreaIndex: 0,
  179. examIndex: 0
  180. };
  181. },
  182. computed: { ...mapGetters(['userInfo','hideBuyState']) },
  183. onLoad(option) {
  184. console.log(option,987)
  185. },
  186. onShow() {
  187. this.isLogin = this.$method.isLogin();
  188. if (this.isLogin) {
  189. if (uni.getStorageSync('updateCart') || !this.isOld) {
  190. this.isOld = true;
  191. this.cartList();
  192. uni.removeStorageSync('updateCart'); //消费购物车刷新事件
  193. }
  194. }
  195. },
  196. methods: {
  197. toFixed(num) {
  198. console.log(num)
  199. return num.toFixed(2)
  200. },
  201. bindChangeE(e) {
  202. console.log(e.detail.value);
  203. this.examIndex = e.detail.value[0];
  204. },
  205. bindChange(e) {
  206. const val = e.detail.value;
  207. if (this.pAreaIndex != e.detail.value[0]) {
  208. this.pAreaIndex = e.detail.value[0];
  209. this.getCityList(this.provinceList[this.pAreaIndex].areaId);
  210. }
  211. if (this.cAreaIndex != e.detail.value[1]) {
  212. this.cAreaIndex = e.detail.value[1];
  213. }
  214. },
  215. checkAreaData() {
  216. if (this.examine.length == 0) {
  217. uni.showModal({
  218. title: '提示',
  219. content: '请选择考期',
  220. showCancel: false
  221. });
  222. return false;
  223. }
  224. return true;
  225. },
  226. checkData() {
  227. if (this.detail.templateType == 'class') {
  228. if (this.gradeValue < 0) {
  229. uni.showModal({
  230. title: '提示',
  231. content: '请选择班级',
  232. showCancel: false
  233. });
  234. return false;
  235. }
  236. } else if (this.detail.templateType == 'apply') {
  237. if (!this.applyObj.examDateJson) {
  238. uni.showModal({
  239. title: '提示',
  240. content: '请选择考期',
  241. showCancel: false
  242. });
  243. return false;
  244. }
  245. }
  246. return true;
  247. },
  248. //弹出框确定
  249. okPopup(index) {
  250. if (index == 0) {
  251. if (!this.checkData()) {
  252. return;
  253. }
  254. this.gradeIndex = this.gradeValue;
  255. this.list[this.detailIndex].gradObj = this.gradeList[this.gradeIndex]; //商品赋值选中班级
  256. this.show = false;
  257. } else {
  258. if (!this.checkAreaData()) {
  259. return;
  260. }
  261. this.examDate = this.examine[this.examIndex];
  262. let pData = this.provinceList[this.pAreaIndex];
  263. let cData = this.cityList[this.cAreaIndex];
  264. this.applyAreas = { areaName: pData.areaName, areaId: pData.areaId, cityId: cData.areaId, cityName: cData.areaName };
  265. // this.applyObj.applyAreasJson = JSON.stringify(this.applyAreas)
  266. // this.applyObj.examDateJson = JSON.stringify(this.examDate)
  267. this.list[this.detailIndex].examDate = this.examDate; //商品赋值选中考期地区
  268. this.list[this.detailIndex].applyAreas = this.applyAreas; //商品赋值选中考期地区
  269. this.show1 = false;
  270. }
  271. },
  272. getExamine(id) {
  273. let self = this;
  274. this.$api.getExamine({ projectId: id }).then(res => {
  275. if (res.data.code == 200) {
  276. self.examine = res.data.rows;
  277. }
  278. });
  279. },
  280. getCityList(id) {
  281. let self = this;
  282. this.$api.getCityList({ parentId: id }).then(res => {
  283. if (res.data.code == 200) {
  284. self.cityList = res.data.rows;
  285. }
  286. });
  287. },
  288. getProvinceList() {
  289. let self = this;
  290. if (self.provinceList.length > 0) {
  291. return;
  292. }
  293. this.$api.getProvinceList().then(res => {
  294. if (res.data.code == 200) {
  295. self.provinceList = res.data.rows;
  296. if (self.provinceList.length > 0) {
  297. self.getCityList(self.provinceList[0].areaId);
  298. }
  299. }
  300. });
  301. },
  302. goodsGradeList(goodsId) {
  303. let self = this;
  304. this.$api.goodsGradeList({ goodsId: goodsId }).then(res => {
  305. if (res.data.code == 200) {
  306. self.gradeList = res.data.rows;
  307. if (self.gradeList.length == 0) {
  308. let item = {
  309. className: '系统分班',
  310. gradeId: 0
  311. };
  312. self.gradeList.push(item);
  313. }
  314. }
  315. });
  316. },
  317. openPopup(index, item, itemIndex) {
  318. this.detail = item;
  319. this.detailIndex = itemIndex;
  320. if (index == 0) {
  321. this.gradeValue = -1;
  322. this.show = true;
  323. this.goodsGradeList(item.goodsId);
  324. } else {
  325. this.applyObj = {
  326. applyAreasJson: null,
  327. examDateJson: null
  328. };
  329. (this.pAreaIndex = 0), (this.cAreaIndex = 0), (this.examIndex = 0), (this.show1 = true);
  330. this.getProvinceList();
  331. this.getExamine(item.projectId);
  332. }
  333. },
  334. checkboxGroupChange(e) {
  335. this.checkboxList = e;
  336. if(this.checkboxList.length==this.list.length){
  337. this.allChecked = true;
  338. }else{
  339. this.allChecked = false;
  340. }
  341. console.log(this.checkboxList)
  342. },
  343. countPrice(list) {},
  344. login() {
  345. uni.navigateTo({ url: '/pages4/login/login' });
  346. },
  347. cartList() {
  348. let self = this;
  349. this.allChecked = false;
  350. this.totalPrice = 0.0;
  351. this.checkboxList = [];
  352. this.$api.cartList().then(res => {
  353. if (res.data.code == 200) {
  354. for (let i = 0; i < res.data.rows.length; i++) {
  355. let item = res.data.rows[i];
  356. item.checked = false;
  357. if (item.status != 1 || item.goodsStatus != 1) {
  358. item.disabled = true;
  359. } else {
  360. item.disabled = false;
  361. }
  362. item.show = false;
  363. item.gradObj = {}; //存储班级
  364. item.applyAreas = {};
  365. item.examDate = {};
  366. }
  367. self.list = res.data.rows;
  368. }
  369. });
  370. },
  371. delItem(item) {
  372. let self = this;
  373. this.$api.deleteCart(item.id).then(res => {
  374. if (res.data.code == 200) {
  375. self.cartList();
  376. }
  377. });
  378. },
  379. swipeChange(e, item) {
  380. item.show = e;
  381. },
  382. goBuy() {
  383. if (this.checkboxList.length == 0) {
  384. uni.showModal({
  385. title: '提示',
  386. content: '请选择商品',
  387. showCancel: false
  388. });
  389. return;
  390. }
  391. let checkGoodsList = [];
  392. for (let i = 0; i < this.checkboxList.length; i++) {
  393. let index = this.checkboxList[i];
  394. let item = this.list[index];
  395. checkGoodsList.push(item);
  396. if (item.templateType == 'class' && item.goodsType == 1) {
  397. if (!item.gradObj.className) {
  398. uni.showModal({
  399. title: '提示',
  400. content: '请选择班级',
  401. showCancel: false
  402. });
  403. return false;
  404. }
  405. }
  406. if (item.templateType == 'apply' && item.goodsType == 1) {
  407. // if (!item.applyAreas.areaName) {
  408. // uni.showModal({
  409. // title: '提示',
  410. // content: '请选择报考地区',
  411. // showCancel: false
  412. // });
  413. // return false;
  414. // }
  415. }
  416. }
  417. this.$store.commit('setShoppingCartList', { shoppingCartList: checkGoodsList });
  418. this.$navTo.togo('/pages2/order/confirm_pay?fromCart=true');
  419. },
  420. checkboxChange(n) {
  421. console.log('change', n);
  422. this.$nextTick(() => {
  423. this.totalPrice = 0.0;
  424. for (let i = 0; i < this.list.length; i++) {
  425. if(this.list[i].checked) {
  426. console.log(this.list[i],999)
  427. this.totalPrice += this.list[i].standPrice;
  428. }
  429. }
  430. })
  431. },
  432. checkboxAllChange(n) {
  433. this.$nextTick(() => {
  434. this.totalPrice = 0.0;
  435. this.checkboxList = [];
  436. if (n.value) {
  437. for (let i = 0; i < this.list.length; i++) {
  438. this.list[i].checked = true;
  439. this.totalPrice += this.list[i].standPrice;
  440. this.checkboxList.push(i);
  441. }
  442. } else {
  443. for (let i = 0; i < this.list.length; i++) {
  444. this.list[i].checked = false;
  445. }
  446. }
  447. })
  448. }
  449. }
  450. };
  451. </script>
  452. <style>
  453. page {
  454. background-color: #eaeef1;
  455. }
  456. </style>
  457. <style scoped lang="scss">
  458. .operate {
  459. background-color: #ff3b30;
  460. color: #ffffff;
  461. border-top-right-radius: 16rpx;
  462. border-bottom-right-radius: 16rpx;
  463. margin-bottom: 20rpx;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. padding: 0 20rpx;
  468. }
  469. .picker-item {
  470. height: 50px;
  471. align-items: center;
  472. justify-content: center;
  473. text-align: center;
  474. }
  475. .picker-view {
  476. width: 100%;
  477. height: 420rpx;
  478. text-align: center;
  479. }
  480. .topTxt {
  481. font-size: 30rpx;
  482. color: #666666;
  483. text-align: center;
  484. padding: 20rpx 0;
  485. }
  486. .blackTxt {
  487. font-size: 30rpx;
  488. font-family: PingFang SC;
  489. font-weight: bold;
  490. color: #333333;
  491. }
  492. .redTxt {
  493. font-size: 30rpx;
  494. font-family: PingFang SC;
  495. color: #ff2d55;
  496. margin-top: 13rpx;
  497. }
  498. .blue-box {
  499. background: #ebf5ff;
  500. }
  501. .white-box {
  502. width: 646rpx;
  503. border-radius: 24rpx;
  504. align-items: center;
  505. display: flex;
  506. padding-left: 15rpx;
  507. }
  508. .okBtn {
  509. width: 200rpx;
  510. height: 64rpx;
  511. background: linear-gradient(0deg, #015eea, #00c0fa);
  512. border-radius: 32rpx;
  513. color: #ffffff;
  514. text-align: center;
  515. line-height: 64rpx;
  516. }
  517. .confrim-btn {
  518. border-top:1px solid #EEEEEE;
  519. height: 98rpx;
  520. width: 100%;
  521. display: flex;
  522. align-items: center;
  523. justify-content: center;
  524. }
  525. .grade {
  526. height: 23rpx;
  527. font-size: 24rpx;
  528. color: #999999;
  529. margin: 0 auto;
  530. margin-top: 15rpx;
  531. text-align: center;
  532. }
  533. .line1 {
  534. width: 80rpx;
  535. height: 8rpx;
  536. background: #999999;
  537. border-radius: 4rpx;
  538. margin: 0 auto;
  539. margin-top: 15rpx;
  540. }
  541. .popup_box {
  542. height: 700rpx;
  543. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  544. border-radius: 32rpx 32rpx 0rpx 0rpx;
  545. }
  546. .goods-item {
  547. width: 100%;
  548. background: #ffffff;
  549. border-radius: 16rpx;
  550. margin-bottom: 16rpx;
  551. padding: 15rpx 0;
  552. display: flex;
  553. .item-wrap {
  554. width:100%;
  555. .goods-msg {
  556. padding: 0 15rpx;
  557. display: flex;
  558. align-items:center;
  559. .flex {
  560. display: flex;
  561. padding-bottom: 15rpx;
  562. width:610rpx;
  563. .goods-img {
  564. overflow: hidden;
  565. border-radius:16rpx;
  566. image {
  567. display: block;
  568. width: 278rpx;
  569. height: 156rpx;
  570. }
  571. }
  572. &__auto {
  573. margin-left: 20rpx;
  574. flex: 1;
  575. .goods-title {
  576. color: #333333;
  577. font-size: 30rpx;
  578. font-weight: bold;
  579. text-align: right;
  580. }
  581. .priceTag {
  582. font-size: 30rpx;
  583. font-family: PingFang SC;
  584. font-weight: bold;
  585. color: #ff2d55;
  586. display: flex;
  587. flex-direction: row-reverse;
  588. margin-right: 8rpx;
  589. }
  590. }
  591. }
  592. }
  593. .goods-select {
  594. &__type {
  595. display: flex;
  596. justify-content: space-between;
  597. align-items: center;
  598. height: 50rpx;
  599. padding: 0 15rpx;
  600. }
  601. }
  602. }
  603. }
  604. .btn2 {
  605. width: 200rpx;
  606. height: 64rpx;
  607. background: linear-gradient(0deg, #015eea, #00c0fa);
  608. border-radius: 32rpx;
  609. text-align: center;
  610. line-height: 64rpx;
  611. }
  612. .bottomBox {
  613. position: fixed;
  614. bottom: 0;
  615. width: 100%;
  616. left: 0;
  617. height: 98rpx;
  618. background-color: #ffffff;
  619. display: flex;
  620. justify-content: space-between;
  621. align-items: center;
  622. padding: 0 30rpx;
  623. .priceTag {
  624. font-size: 30rpx;
  625. font-family: PingFang SC;
  626. font-weight: bold;
  627. color: #ff2d55;
  628. display: flex;
  629. flex-direction: row-reverse;
  630. margin-right: 20rpx;
  631. }
  632. }
  633. </style>