shoppingCart.vue 16 KB

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