shoppingCart.vue 17 KB

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