shoppingCart.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. for(let i =0;i<this.checkboxList.length;i++){
  427. let index = this.checkboxList[i]
  428. let item = this.list[index]
  429. if(item.templateType=='class'){
  430. if(!item.gradObj.className){
  431. uni.showModal({
  432. title: "提示",
  433. content: '请选择班级',
  434. showCancel: false
  435. })
  436. return false
  437. }
  438. }
  439. if(item.templateType=='apply'){
  440. if(!item.applyAreas.areaName){
  441. uni.showModal({
  442. title: "提示",
  443. content: '请选择报考地区',
  444. showCancel: false
  445. })
  446. return false
  447. }
  448. }
  449. }
  450. this.$navTo.togo('/pages2/order/confirm_pay');
  451. },
  452. checkboxChange(n) {
  453. console.log('change', n);
  454. if(n.value){
  455. this.totalPrice += this.list[n.name].standPrice
  456. }else{
  457. this.totalPrice -= this.list[n.name].standPrice
  458. }
  459. },
  460. checkboxAllChange(n){
  461. this.totalPrice = 0.00
  462. this.checkboxList = []
  463. if(n.value){
  464. for(let i =0;i<this.list.length;i++){
  465. this.list[i].checked = true
  466. this.totalPrice += this.list[i].standPrice
  467. this.checkboxList.push(i)
  468. }
  469. }else{
  470. for(let i =0;i<this.list.length;i++){
  471. this.list[i].checked = false
  472. }
  473. }
  474. }
  475. }
  476. }
  477. </script>
  478. <style >
  479. page{
  480. background-color: #EAEEF1;
  481. }
  482. </style>
  483. <style scoped>
  484. .operate{
  485. background-color: #FF3B30;
  486. color: #FFFFFF;
  487. border-top-right-radius: 16rpx;
  488. border-bottom-right-radius: 16rpx;
  489. margin-bottom: 20rpx;
  490. display: flex;
  491. align-items:center;
  492. justify-content:center;
  493. padding: 0 20rpx;
  494. }
  495. .picker-item {
  496. height: 50px;
  497. align-items: center;
  498. justify-content: center;
  499. text-align: center;
  500. }
  501. .picker-view {
  502. width: 100%;
  503. height: 420rpx;
  504. text-align: center;
  505. }
  506. .topTxt{
  507. font-size: 30rpx;
  508. color: #666666;
  509. text-align: center;
  510. padding: 20rpx 0;
  511. }
  512. .blackTxt{
  513. font-size: 30rpx;
  514. font-family: PingFang SC;
  515. font-weight: bold;
  516. color: #333333;
  517. }
  518. .redTxt{
  519. font-size: 30rpx;
  520. font-family: PingFang SC;
  521. color: #FF2D55;
  522. margin-top: 13rpx;
  523. }
  524. .blue-box{
  525. background: #EBF5FF;
  526. }
  527. .white-box{
  528. width: 646rpx;
  529. border-radius: 24rpx;
  530. align-items: center;
  531. display: flex;
  532. padding-left: 15rpx;
  533. }
  534. .okBtn{
  535. width: 200rpx;
  536. height: 64rpx;
  537. background: linear-gradient(0deg, #015EEA, #00C0FA);
  538. border-radius: 32rpx;
  539. color: #FFFFFF;
  540. text-align: center;
  541. line-height: 64rpx;
  542. }
  543. .confrim-btn{
  544. height: 98rpx;
  545. width: 100%;
  546. display: flex;
  547. align-items: center;
  548. justify-content:center;
  549. }
  550. .grade{
  551. height: 23rpx;
  552. font-size: 24rpx;
  553. color: #999999;
  554. margin: 0 auto;
  555. margin-top: 15rpx;
  556. text-align: center;
  557. }
  558. .line1{
  559. width: 80rpx;
  560. height: 8rpx;
  561. background: #999999;
  562. border-radius: 4rpx;
  563. margin: 0 auto;
  564. margin-top: 15rpx;
  565. }
  566. .popup_box {
  567. height: 700rpx;
  568. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  569. border-radius: 32rpx 32rpx 0rpx 0rpx;
  570. }
  571. .item{
  572. width: 100%;
  573. background: #FFFFFF;
  574. border-radius: 16rpx;
  575. margin-bottom: 20rpx;
  576. padding: 15rpx;
  577. display: flex;
  578. }
  579. .priceTag{
  580. font-size: 30rpx;
  581. font-family: PingFang SC;
  582. font-weight: bold;
  583. color: #FF2D55;
  584. display: flex;
  585. flex-direction: row-reverse;
  586. margin-right: 8rpx;
  587. }
  588. .btn2{
  589. width: 200rpx;
  590. height: 64rpx;
  591. background: linear-gradient(0deg, #015EEA, #00C0FA);
  592. border-radius: 32rpx;
  593. text-align: center;
  594. line-height: 64rpx;
  595. }
  596. .bottomBox{
  597. position: fixed;
  598. bottom: 0;
  599. width: 100%;
  600. left: 0;
  601. height:98rpx ;
  602. background-color: #FFFFFF;
  603. display: flex;
  604. justify-content: space-between;
  605. align-items: center;
  606. padding: 0 30rpx;
  607. }
  608. </style>