shoppingCart.vue 16 KB

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