shoppingCart.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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. console.log(option,987)
  186. },
  187. onShow() {
  188. this.isLogin = this.$method.isLogin();
  189. if (this.isLogin) {
  190. if (uni.getStorageSync('updateCart') || !this.isOld) {
  191. this.isOld = true;
  192. this.cartList();
  193. uni.removeStorageSync('updateCart'); //消费购物车刷新事件
  194. }
  195. }
  196. },
  197. methods: {
  198. bindChangeE(e) {
  199. console.log(e.detail.value);
  200. this.examIndex = e.detail.value[0];
  201. },
  202. bindChange(e) {
  203. const val = e.detail.value;
  204. if (this.pAreaIndex != e.detail.value[0]) {
  205. this.pAreaIndex = e.detail.value[0];
  206. this.getCityList(this.provinceList[this.pAreaIndex].areaId);
  207. }
  208. if (this.cAreaIndex != e.detail.value[1]) {
  209. this.cAreaIndex = e.detail.value[1];
  210. }
  211. },
  212. checkAreaData() {
  213. if (this.examine.length == 0) {
  214. uni.showModal({
  215. title: '提示',
  216. content: '请选择考期',
  217. showCancel: false
  218. });
  219. return false;
  220. }
  221. // if (this.provinceList.length == 0) {
  222. // uni.showModal({
  223. // title: '提示',
  224. // content: '请选择报考地区',
  225. // showCancel: false
  226. // });
  227. // return false;
  228. // }
  229. // if (this.cityList.length == 0) {
  230. // uni.showModal({
  231. // title: '提示',
  232. // content: '请选择报考地区',
  233. // showCancel: false
  234. // });
  235. // return false;
  236. // }
  237. return true;
  238. },
  239. checkData() {
  240. if (this.detail.templateType == 'class') {
  241. if (this.gradeValue < 0) {
  242. uni.showModal({
  243. title: '提示',
  244. content: '请选择班级',
  245. showCancel: false
  246. });
  247. return false;
  248. }
  249. } else if (this.detail.templateType == 'apply') {
  250. // if (!this.applyObj.applyAreasJson) {
  251. // uni.showModal({
  252. // title: '提示',
  253. // content: '请选择报考地区',
  254. // showCancel: false
  255. // });
  256. // return false;
  257. // }
  258. if (!this.applyObj.examDateJson) {
  259. uni.showModal({
  260. title: '提示',
  261. content: '请选择考期',
  262. showCancel: false
  263. });
  264. return false;
  265. }
  266. }
  267. return true;
  268. },
  269. //弹出框确定
  270. okPopup(index) {
  271. if (index == 0) {
  272. if (!this.checkData()) {
  273. return;
  274. }
  275. this.gradeIndex = this.gradeValue;
  276. this.list[this.detailIndex].gradObj = this.gradeList[this.gradeIndex]; //商品赋值选中班级
  277. this.show = false;
  278. } else {
  279. if (!this.checkAreaData()) {
  280. return;
  281. }
  282. this.examDate = this.examine[this.examIndex];
  283. let pData = this.provinceList[this.pAreaIndex];
  284. let cData = this.cityList[this.cAreaIndex];
  285. this.applyAreas = { areaName: pData.areaName, areaId: pData.areaId, cityId: cData.areaId, cityName: cData.areaName };
  286. // this.applyObj.applyAreasJson = JSON.stringify(this.applyAreas)
  287. // this.applyObj.examDateJson = JSON.stringify(this.examDate)
  288. this.list[this.detailIndex].examDate = this.examDate; //商品赋值选中考期地区
  289. this.list[this.detailIndex].applyAreas = this.applyAreas; //商品赋值选中考期地区
  290. this.show1 = false;
  291. }
  292. },
  293. getExamine(id) {
  294. let self = this;
  295. this.$api.getExamine({ projectId: id }).then(res => {
  296. if (res.data.code == 200) {
  297. self.examine = res.data.rows;
  298. }
  299. });
  300. },
  301. getCityList(id) {
  302. let self = this;
  303. this.$api.getCityList({ parentId: id }).then(res => {
  304. if (res.data.code == 200) {
  305. self.cityList = res.data.rows;
  306. }
  307. });
  308. },
  309. getProvinceList() {
  310. let self = this;
  311. if (self.provinceList.length > 0) {
  312. return;
  313. }
  314. this.$api.getProvinceList().then(res => {
  315. if (res.data.code == 200) {
  316. self.provinceList = res.data.rows;
  317. if (self.provinceList.length > 0) {
  318. self.getCityList(self.provinceList[0].areaId);
  319. }
  320. }
  321. });
  322. },
  323. goodsGradeList(goodsId) {
  324. let self = this;
  325. this.$api.goodsGradeList({ goodsId: goodsId }).then(res => {
  326. if (res.data.code == 200) {
  327. self.gradeList = res.data.rows;
  328. if (self.gradeList.length == 0) {
  329. let item = {
  330. className: '系统分班',
  331. gradeId: 0
  332. };
  333. self.gradeList.push(item);
  334. }
  335. }
  336. });
  337. },
  338. openPopup(index, item, itemIndex) {
  339. this.detail = item;
  340. this.detailIndex = itemIndex;
  341. if (index == 0) {
  342. this.gradeValue = -1;
  343. this.show = true;
  344. this.goodsGradeList(item.goodsId);
  345. } else {
  346. this.applyObj = {
  347. applyAreasJson: null,
  348. examDateJson: null
  349. };
  350. (this.pAreaIndex = 0), (this.cAreaIndex = 0), (this.examIndex = 0), (this.show1 = true);
  351. this.getProvinceList();
  352. this.getExamine(item.projectId);
  353. }
  354. },
  355. checkboxGroupChange(e) {
  356. this.checkboxList = e;
  357. if(this.checkboxList.length==this.list.length){
  358. this.allChecked = true;
  359. }else{
  360. this.allChecked = false;
  361. }
  362. console.log(this.checkboxList)
  363. },
  364. countPrice(list) {},
  365. checkboxChange1(e) {
  366. //console.log(e);
  367. },
  368. login() {
  369. uni.navigateTo({ url: '/pages/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');
  443. },
  444. checkboxChange(n) {
  445. console.log('change', n);
  446. if (n.value) {
  447. this.totalPrice += this.list[n.name].standPrice;
  448. } else {
  449. this.totalPrice -= this.list[n.name].standPrice;
  450. }
  451. },
  452. checkboxAllChange(n) {
  453. this.totalPrice = 0.0;
  454. this.checkboxList = [];
  455. if (n.value) {
  456. for (let i = 0; i < this.list.length; i++) {
  457. this.list[i].checked = true;
  458. this.totalPrice += this.list[i].standPrice;
  459. this.checkboxList.push(i);
  460. }
  461. } else {
  462. for (let i = 0; i < this.list.length; i++) {
  463. this.list[i].checked = false;
  464. }
  465. }
  466. }
  467. }
  468. };
  469. </script>
  470. <style>
  471. page {
  472. background-color: #eaeef1;
  473. }
  474. </style>
  475. <style scoped>
  476. .operate {
  477. background-color: #ff3b30;
  478. color: #ffffff;
  479. border-top-right-radius: 16rpx;
  480. border-bottom-right-radius: 16rpx;
  481. margin-bottom: 20rpx;
  482. display: flex;
  483. align-items: center;
  484. justify-content: center;
  485. padding: 0 20rpx;
  486. }
  487. .picker-item {
  488. height: 50px;
  489. align-items: center;
  490. justify-content: center;
  491. text-align: center;
  492. }
  493. .picker-view {
  494. width: 100%;
  495. height: 420rpx;
  496. text-align: center;
  497. }
  498. .topTxt {
  499. font-size: 30rpx;
  500. color: #666666;
  501. text-align: center;
  502. padding: 20rpx 0;
  503. }
  504. .blackTxt {
  505. font-size: 30rpx;
  506. font-family: PingFang SC;
  507. font-weight: bold;
  508. color: #333333;
  509. }
  510. .redTxt {
  511. font-size: 30rpx;
  512. font-family: PingFang SC;
  513. color: #ff2d55;
  514. margin-top: 13rpx;
  515. }
  516. .blue-box {
  517. background: #ebf5ff;
  518. }
  519. .white-box {
  520. width: 646rpx;
  521. border-radius: 24rpx;
  522. align-items: center;
  523. display: flex;
  524. padding-left: 15rpx;
  525. }
  526. .okBtn {
  527. width: 200rpx;
  528. height: 64rpx;
  529. background: linear-gradient(0deg, #015eea, #00c0fa);
  530. border-radius: 32rpx;
  531. color: #ffffff;
  532. text-align: center;
  533. line-height: 64rpx;
  534. }
  535. .confrim-btn {
  536. height: 98rpx;
  537. width: 100%;
  538. display: flex;
  539. align-items: center;
  540. justify-content: center;
  541. }
  542. .grade {
  543. height: 23rpx;
  544. font-size: 24rpx;
  545. color: #999999;
  546. margin: 0 auto;
  547. margin-top: 15rpx;
  548. text-align: center;
  549. }
  550. .line1 {
  551. width: 80rpx;
  552. height: 8rpx;
  553. background: #999999;
  554. border-radius: 4rpx;
  555. margin: 0 auto;
  556. margin-top: 15rpx;
  557. }
  558. .popup_box {
  559. height: 700rpx;
  560. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  561. border-radius: 32rpx 32rpx 0rpx 0rpx;
  562. }
  563. .item {
  564. width: 100%;
  565. background: #ffffff;
  566. border-radius: 16rpx;
  567. margin-bottom: 20rpx;
  568. padding: 15rpx;
  569. display: flex;
  570. }
  571. .priceTag {
  572. font-size: 30rpx;
  573. font-family: PingFang SC;
  574. font-weight: bold;
  575. color: #ff2d55;
  576. display: flex;
  577. flex-direction: row-reverse;
  578. margin-right: 8rpx;
  579. }
  580. .btn2 {
  581. width: 200rpx;
  582. height: 64rpx;
  583. background: linear-gradient(0deg, #015eea, #00c0fa);
  584. border-radius: 32rpx;
  585. text-align: center;
  586. line-height: 64rpx;
  587. }
  588. .bottomBox {
  589. position: fixed;
  590. bottom: 0;
  591. width: 100%;
  592. left: 0;
  593. height: 98rpx;
  594. background-color: #ffffff;
  595. display: flex;
  596. justify-content: space-between;
  597. align-items: center;
  598. padding: 0 30rpx;
  599. }
  600. </style>