shoppingCart.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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. // if (this.provinceList.length == 0) {
  225. // uni.showModal({
  226. // title: '提示',
  227. // content: '请选择报考地区',
  228. // showCancel: false
  229. // });
  230. // return false;
  231. // }
  232. // if (this.cityList.length == 0) {
  233. // uni.showModal({
  234. // title: '提示',
  235. // content: '请选择报考地区',
  236. // showCancel: false
  237. // });
  238. // return false;
  239. // }
  240. return true;
  241. },
  242. checkData() {
  243. if (this.detail.templateType == 'class') {
  244. if (this.gradeValue < 0) {
  245. uni.showModal({
  246. title: '提示',
  247. content: '请选择班级',
  248. showCancel: false
  249. });
  250. return false;
  251. }
  252. } else if (this.detail.templateType == 'apply') {
  253. // if (!this.applyObj.applyAreasJson) {
  254. // uni.showModal({
  255. // title: '提示',
  256. // content: '请选择报考地区',
  257. // showCancel: false
  258. // });
  259. // return false;
  260. // }
  261. if (!this.applyObj.examDateJson) {
  262. uni.showModal({
  263. title: '提示',
  264. content: '请选择考期',
  265. showCancel: false
  266. });
  267. return false;
  268. }
  269. }
  270. return true;
  271. },
  272. //弹出框确定
  273. okPopup(index) {
  274. if (index == 0) {
  275. if (!this.checkData()) {
  276. return;
  277. }
  278. this.gradeIndex = this.gradeValue;
  279. this.list[this.detailIndex].gradObj = this.gradeList[this.gradeIndex]; //商品赋值选中班级
  280. this.show = false;
  281. } else {
  282. if (!this.checkAreaData()) {
  283. return;
  284. }
  285. this.examDate = this.examine[this.examIndex];
  286. let pData = this.provinceList[this.pAreaIndex];
  287. let cData = this.cityList[this.cAreaIndex];
  288. this.applyAreas = { areaName: pData.areaName, areaId: pData.areaId, cityId: cData.areaId, cityName: cData.areaName };
  289. // this.applyObj.applyAreasJson = JSON.stringify(this.applyAreas)
  290. // this.applyObj.examDateJson = JSON.stringify(this.examDate)
  291. this.list[this.detailIndex].examDate = this.examDate; //商品赋值选中考期地区
  292. this.list[this.detailIndex].applyAreas = this.applyAreas; //商品赋值选中考期地区
  293. this.show1 = false;
  294. }
  295. },
  296. getExamine(id) {
  297. let self = this;
  298. this.$api.getExamine({ projectId: id }).then(res => {
  299. if (res.data.code == 200) {
  300. self.examine = res.data.rows;
  301. }
  302. });
  303. },
  304. getCityList(id) {
  305. let self = this;
  306. this.$api.getCityList({ parentId: id }).then(res => {
  307. if (res.data.code == 200) {
  308. self.cityList = res.data.rows;
  309. }
  310. });
  311. },
  312. getProvinceList() {
  313. let self = this;
  314. if (self.provinceList.length > 0) {
  315. return;
  316. }
  317. this.$api.getProvinceList().then(res => {
  318. if (res.data.code == 200) {
  319. self.provinceList = res.data.rows;
  320. if (self.provinceList.length > 0) {
  321. self.getCityList(self.provinceList[0].areaId);
  322. }
  323. }
  324. });
  325. },
  326. goodsGradeList(goodsId) {
  327. let self = this;
  328. this.$api.goodsGradeList({ goodsId: goodsId }).then(res => {
  329. if (res.data.code == 200) {
  330. self.gradeList = res.data.rows;
  331. if (self.gradeList.length == 0) {
  332. let item = {
  333. className: '系统分班',
  334. gradeId: 0
  335. };
  336. self.gradeList.push(item);
  337. }
  338. }
  339. });
  340. },
  341. openPopup(index, item, itemIndex) {
  342. this.detail = item;
  343. this.detailIndex = itemIndex;
  344. if (index == 0) {
  345. this.gradeValue = -1;
  346. this.show = true;
  347. this.goodsGradeList(item.goodsId);
  348. } else {
  349. this.applyObj = {
  350. applyAreasJson: null,
  351. examDateJson: null
  352. };
  353. (this.pAreaIndex = 0), (this.cAreaIndex = 0), (this.examIndex = 0), (this.show1 = true);
  354. this.getProvinceList();
  355. this.getExamine(item.projectId);
  356. }
  357. },
  358. checkboxGroupChange(e) {
  359. this.checkboxList = e;
  360. if(this.checkboxList.length==this.list.length){
  361. this.allChecked = true;
  362. }else{
  363. this.allChecked = false;
  364. }
  365. console.log(this.checkboxList)
  366. },
  367. countPrice(list) {},
  368. login() {
  369. uni.navigateTo({ url: '/pages4/login/login' });
  370. },
  371. cartList() {
  372. let self = this;
  373. this.allChecked = false;
  374. this.totalPrice = 0.0;
  375. this.checkboxList = [];
  376. this.$api.cartList().then(res => {
  377. if (res.data.code == 200) {
  378. for (let i = 0; i < res.data.rows.length; i++) {
  379. let item = res.data.rows[i];
  380. item.checked = false;
  381. if (item.status != 1 || item.goodsStatus != 1) {
  382. item.disabled = true;
  383. } else {
  384. item.disabled = false;
  385. }
  386. item.show = false;
  387. item.gradObj = {}; //存储班级
  388. item.applyAreas = {};
  389. item.examDate = {};
  390. }
  391. self.list = res.data.rows;
  392. }
  393. });
  394. },
  395. delItem(item) {
  396. let self = this;
  397. this.$api.deleteCart(item.id).then(res => {
  398. if (res.data.code == 200) {
  399. self.cartList();
  400. }
  401. });
  402. },
  403. swipeChange(e, item) {
  404. item.show = e;
  405. },
  406. goBuy() {
  407. if (this.checkboxList.length == 0) {
  408. uni.showModal({
  409. title: '提示',
  410. content: '请选择商品',
  411. showCancel: false
  412. });
  413. return;
  414. }
  415. let checkGoodsList = [];
  416. for (let i = 0; i < this.checkboxList.length; i++) {
  417. let index = this.checkboxList[i];
  418. let item = this.list[index];
  419. checkGoodsList.push(item);
  420. if (item.templateType == 'class' && item.goodsType == 1) {
  421. if (!item.gradObj.className) {
  422. uni.showModal({
  423. title: '提示',
  424. content: '请选择班级',
  425. showCancel: false
  426. });
  427. return false;
  428. }
  429. }
  430. if (item.templateType == 'apply' && item.goodsType == 1) {
  431. // if (!item.applyAreas.areaName) {
  432. // uni.showModal({
  433. // title: '提示',
  434. // content: '请选择报考地区',
  435. // showCancel: false
  436. // });
  437. // return false;
  438. // }
  439. }
  440. }
  441. this.$store.commit('setShoppingCartList', { shoppingCartList: checkGoodsList });
  442. this.$navTo.togo('/pages2/order/confirm_pay?fromCart=true');
  443. },
  444. checkboxChange(n) {
  445. console.log('change', n);
  446. this.$nextTick(() => {
  447. this.totalPrice = 0.0;
  448. for (let i = 0; i < this.list.length; i++) {
  449. if(this.list[i].checked) {
  450. console.log(this.list[i],999)
  451. this.totalPrice += this.list[i].standPrice;
  452. }
  453. }
  454. })
  455. },
  456. checkboxAllChange(n) {
  457. this.$nextTick(() => {
  458. this.totalPrice = 0.0;
  459. this.checkboxList = [];
  460. if (n.value) {
  461. for (let i = 0; i < this.list.length; i++) {
  462. this.list[i].checked = true;
  463. this.totalPrice += this.list[i].standPrice;
  464. this.checkboxList.push(i);
  465. }
  466. } else {
  467. for (let i = 0; i < this.list.length; i++) {
  468. this.list[i].checked = false;
  469. }
  470. }
  471. })
  472. }
  473. }
  474. };
  475. </script>
  476. <style>
  477. page {
  478. background-color: #eaeef1;
  479. }
  480. </style>
  481. <style scoped lang="scss">
  482. .operate {
  483. background-color: #ff3b30;
  484. color: #ffffff;
  485. border-top-right-radius: 16rpx;
  486. border-bottom-right-radius: 16rpx;
  487. margin-bottom: 20rpx;
  488. display: flex;
  489. align-items: center;
  490. justify-content: center;
  491. padding: 0 20rpx;
  492. }
  493. .picker-item {
  494. height: 50px;
  495. align-items: center;
  496. justify-content: center;
  497. text-align: center;
  498. }
  499. .picker-view {
  500. width: 100%;
  501. height: 420rpx;
  502. text-align: center;
  503. }
  504. .topTxt {
  505. font-size: 30rpx;
  506. color: #666666;
  507. text-align: center;
  508. padding: 20rpx 0;
  509. }
  510. .blackTxt {
  511. font-size: 30rpx;
  512. font-family: PingFang SC;
  513. font-weight: bold;
  514. color: #333333;
  515. }
  516. .redTxt {
  517. font-size: 30rpx;
  518. font-family: PingFang SC;
  519. color: #ff2d55;
  520. margin-top: 13rpx;
  521. }
  522. .blue-box {
  523. background: #ebf5ff;
  524. }
  525. .white-box {
  526. width: 646rpx;
  527. border-radius: 24rpx;
  528. align-items: center;
  529. display: flex;
  530. padding-left: 15rpx;
  531. }
  532. .okBtn {
  533. width: 200rpx;
  534. height: 64rpx;
  535. background: linear-gradient(0deg, #015eea, #00c0fa);
  536. border-radius: 32rpx;
  537. color: #ffffff;
  538. text-align: center;
  539. line-height: 64rpx;
  540. }
  541. .confrim-btn {
  542. border-top:1px solid #EEEEEE;
  543. height: 98rpx;
  544. width: 100%;
  545. display: flex;
  546. align-items: center;
  547. justify-content: center;
  548. }
  549. .grade {
  550. height: 23rpx;
  551. font-size: 24rpx;
  552. color: #999999;
  553. margin: 0 auto;
  554. margin-top: 15rpx;
  555. text-align: center;
  556. }
  557. .line1 {
  558. width: 80rpx;
  559. height: 8rpx;
  560. background: #999999;
  561. border-radius: 4rpx;
  562. margin: 0 auto;
  563. margin-top: 15rpx;
  564. }
  565. .popup_box {
  566. height: 700rpx;
  567. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  568. border-radius: 32rpx 32rpx 0rpx 0rpx;
  569. }
  570. .goods-item {
  571. width: 100%;
  572. background: #ffffff;
  573. border-radius: 16rpx;
  574. margin-bottom: 16rpx;
  575. padding: 15rpx 0;
  576. display: flex;
  577. .item-wrap {
  578. width:100%;
  579. .goods-msg {
  580. padding: 0 15rpx;
  581. display: flex;
  582. align-items:center;
  583. .flex {
  584. display: flex;
  585. padding-bottom: 15rpx;
  586. width:610rpx;
  587. .goods-img {
  588. overflow: hidden;
  589. border-radius:16rpx;
  590. image {
  591. display: block;
  592. width: 278rpx;
  593. height: 156rpx;
  594. }
  595. }
  596. &__auto {
  597. margin-left: 20rpx;
  598. flex: 1;
  599. .goods-title {
  600. color: #333333;
  601. font-size: 30rpx;
  602. font-weight: bold;
  603. text-align: right;
  604. }
  605. .priceTag {
  606. font-size: 30rpx;
  607. font-family: PingFang SC;
  608. font-weight: bold;
  609. color: #ff2d55;
  610. display: flex;
  611. flex-direction: row-reverse;
  612. margin-right: 8rpx;
  613. }
  614. }
  615. }
  616. }
  617. .goods-select {
  618. &__type {
  619. display: flex;
  620. justify-content: space-between;
  621. align-items: center;
  622. height: 50rpx;
  623. padding: 0 15rpx;
  624. }
  625. }
  626. }
  627. }
  628. .btn2 {
  629. width: 200rpx;
  630. height: 64rpx;
  631. background: linear-gradient(0deg, #015eea, #00c0fa);
  632. border-radius: 32rpx;
  633. text-align: center;
  634. line-height: 64rpx;
  635. }
  636. .bottomBox {
  637. position: fixed;
  638. bottom: 0;
  639. width: 100%;
  640. left: 0;
  641. height: 98rpx;
  642. background-color: #ffffff;
  643. display: flex;
  644. justify-content: space-between;
  645. align-items: center;
  646. padding: 0 30rpx;
  647. .priceTag {
  648. font-size: 30rpx;
  649. font-family: PingFang SC;
  650. font-weight: bold;
  651. color: #ff2d55;
  652. display: flex;
  653. flex-direction: row-reverse;
  654. margin-right: 20rpx;
  655. }
  656. }
  657. </style>