shoppingCart.vue 18 KB

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