shoppingCart.vue 16 KB

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