shoppingCart.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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">¥ {{ toFixed(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. toFixed(num) {
  195. console.log(num)
  196. return num.toFixed(2)
  197. },
  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. 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. this.$nextTick(() => {
  444. this.totalPrice = 0.0;
  445. for (let i = 0; i < this.list.length; i++) {
  446. if(this.list[i].checked) {
  447. console.log(this.list[i],999)
  448. this.totalPrice += this.list[i].standPrice;
  449. }
  450. }
  451. })
  452. },
  453. checkboxAllChange(n) {
  454. this.$nextTick(() => {
  455. this.totalPrice = 0.0;
  456. this.checkboxList = [];
  457. if (n.value) {
  458. for (let i = 0; i < this.list.length; i++) {
  459. this.list[i].checked = true;
  460. this.totalPrice += this.list[i].standPrice;
  461. this.checkboxList.push(i);
  462. }
  463. } else {
  464. for (let i = 0; i < this.list.length; i++) {
  465. this.list[i].checked = false;
  466. }
  467. }
  468. })
  469. }
  470. }
  471. };
  472. </script>
  473. <style>
  474. page {
  475. background-color: #eaeef1;
  476. }
  477. </style>
  478. <style scoped lang="scss">
  479. .operate {
  480. background-color: #ff3b30;
  481. color: #ffffff;
  482. border-top-right-radius: 16rpx;
  483. border-bottom-right-radius: 16rpx;
  484. margin-bottom: 20rpx;
  485. display: flex;
  486. align-items: center;
  487. justify-content: center;
  488. padding: 0 20rpx;
  489. }
  490. .picker-item {
  491. height: 50px;
  492. align-items: center;
  493. justify-content: center;
  494. text-align: center;
  495. }
  496. .picker-view {
  497. width: 100%;
  498. height: 420rpx;
  499. text-align: center;
  500. }
  501. .topTxt {
  502. font-size: 30rpx;
  503. color: #666666;
  504. text-align: center;
  505. padding: 20rpx 0;
  506. }
  507. .blackTxt {
  508. font-size: 30rpx;
  509. font-family: PingFang SC;
  510. font-weight: bold;
  511. color: #333333;
  512. }
  513. .redTxt {
  514. font-size: 30rpx;
  515. font-family: PingFang SC;
  516. color: #ff2d55;
  517. margin-top: 13rpx;
  518. }
  519. .blue-box {
  520. background: #ebf5ff;
  521. }
  522. .white-box {
  523. width: 646rpx;
  524. border-radius: 24rpx;
  525. align-items: center;
  526. display: flex;
  527. padding-left: 15rpx;
  528. }
  529. .okBtn {
  530. width: 200rpx;
  531. height: 64rpx;
  532. background: linear-gradient(0deg, #015eea, #00c0fa);
  533. border-radius: 32rpx;
  534. color: #ffffff;
  535. text-align: center;
  536. line-height: 64rpx;
  537. }
  538. .confrim-btn {
  539. border-top:1px solid #EEEEEE;
  540. height: 98rpx;
  541. width: 100%;
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. }
  546. .grade {
  547. height: 23rpx;
  548. font-size: 24rpx;
  549. color: #999999;
  550. margin: 0 auto;
  551. margin-top: 15rpx;
  552. text-align: center;
  553. }
  554. .line1 {
  555. width: 80rpx;
  556. height: 8rpx;
  557. background: #999999;
  558. border-radius: 4rpx;
  559. margin: 0 auto;
  560. margin-top: 15rpx;
  561. }
  562. .popup_box {
  563. height: 700rpx;
  564. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  565. border-radius: 32rpx 32rpx 0rpx 0rpx;
  566. }
  567. .goods-item {
  568. width: 100%;
  569. background: #ffffff;
  570. border-radius: 16rpx;
  571. margin-bottom: 16rpx;
  572. padding: 15rpx 0;
  573. display: flex;
  574. .item-wrap {
  575. width:100%;
  576. .goods-msg {
  577. padding: 0 15rpx;
  578. display: flex;
  579. align-items:center;
  580. .flex {
  581. display: flex;
  582. padding-bottom: 15rpx;
  583. width:610rpx;
  584. .goods-img {
  585. overflow: hidden;
  586. border-radius:16rpx;
  587. image {
  588. display: block;
  589. width: 278rpx;
  590. height: 134rpx;
  591. }
  592. }
  593. &__auto {
  594. margin-left: 20rpx;
  595. flex: 1;
  596. .goods-title {
  597. color: #333333;
  598. font-size: 30rpx;
  599. font-weight: bold;
  600. text-align: right;
  601. .priceTag {
  602. font-size: 30rpx;
  603. font-family: PingFang SC;
  604. font-weight: bold;
  605. color: #ff2d55;
  606. display: flex;
  607. flex-direction: row-reverse;
  608. margin-right: 8rpx;
  609. }
  610. }
  611. }
  612. }
  613. }
  614. .goods-select {
  615. &__type {
  616. display: flex;
  617. justify-content: space-between;
  618. align-items: center;
  619. height: 50rpx;
  620. padding: 0 15rpx;
  621. }
  622. }
  623. }
  624. }
  625. .btn2 {
  626. width: 200rpx;
  627. height: 64rpx;
  628. background: linear-gradient(0deg, #015eea, #00c0fa);
  629. border-radius: 32rpx;
  630. text-align: center;
  631. line-height: 64rpx;
  632. }
  633. .bottomBox {
  634. position: fixed;
  635. bottom: 0;
  636. width: 100%;
  637. left: 0;
  638. height: 98rpx;
  639. background-color: #ffffff;
  640. display: flex;
  641. justify-content: space-between;
  642. align-items: center;
  643. padding: 0 30rpx;
  644. .priceTag {
  645. font-size: 30rpx;
  646. font-family: PingFang SC;
  647. font-weight: bold;
  648. color: #ff2d55;
  649. display: flex;
  650. flex-direction: row-reverse;
  651. margin-right: 20rpx;
  652. }
  653. }
  654. </style>