shoppingCart.vue 18 KB

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