shoppingCart.vue 16 KB

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