shoppingCart.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. import goodsInputItem from '@/components/shopping/goodsInputItem.vue';
  168. export default {
  169. components: {
  170. goodsInputItem
  171. },
  172. data() {
  173. return {
  174. gradeValue:-1,
  175. isLogin:false,
  176. allChecked:false,
  177. checkboxValue1:[],
  178. list: [
  179. ],
  180. value1:'',
  181. show:false,
  182. show1:false,
  183. totalPrice:0.00,
  184. isOld:false,
  185. checkboxList:[],
  186. gradeList:[],
  187. examine:[],
  188. provinceList:[],
  189. cityList:[],
  190. detail:{},
  191. detailIndex:-1,
  192. applyObj:{
  193. applyAreasJson:null,
  194. examDateJson:null
  195. }
  196. }
  197. },
  198. onLoad(option) {
  199. },
  200. onShow() {
  201. this.isLogin = this.$method.isLogin()
  202. if(this.isLogin){
  203. if(uni.getStorageSync('updateCart')||!this.isOld){
  204. this.isOld = true
  205. this.cartList()
  206. uni.removeStorageSync('updateCart')//消费购物车刷新事件
  207. }
  208. }
  209. },
  210. methods: {
  211. checkAreaData(){
  212. if(this.examine.length==0){
  213. uni.showModal({
  214. title: "提示",
  215. content: '请选择考期',
  216. showCancel: false
  217. })
  218. return false
  219. }
  220. if(this.provinceList.length==0){
  221. uni.showModal({
  222. title: "提示",
  223. content: '请选择报考地区',
  224. showCancel: false
  225. })
  226. return false
  227. }
  228. if(this.cityList.length==0){
  229. uni.showModal({
  230. title: "提示",
  231. content: '请选择报考地区',
  232. showCancel: false
  233. })
  234. return false
  235. }
  236. return true
  237. },
  238. checkData(){
  239. if(this.detail.templateType=='class'){
  240. if(this.gradeValue<0){
  241. uni.showModal({
  242. title: "提示",
  243. content: '请选择班级',
  244. showCancel: false
  245. })
  246. return false
  247. }
  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.show = false
  277. }else{
  278. if(!this.checkAreaData()){
  279. return
  280. }
  281. this.examDate = this.examine[this.examIndex]
  282. let pData = this.provinceList[this.pAreaIndex]
  283. let cData = this.cityList[this.cAreaIndex]
  284. this.applyAreas = {areaName:pData.areaName,areaId:pData.areaId,cityId:cData.areaId,cityName:cData.areaName}
  285. this.applyObj.applyAreasJson = JSON.stringify(this.applyAreas)
  286. this.applyObj.examDateJson = JSON.stringify(this.examDate)
  287. this.show1 = false
  288. }
  289. },
  290. getExamine(id) {
  291. let self = this
  292. this.$api.getExamine({projectId:id}).then(res => {
  293. if(res.data.code==200){
  294. self.examine = res.data.rows
  295. }
  296. });
  297. },
  298. getCityList(id) {
  299. let self = this
  300. this.$api.getCityList({parentId:id}).then(res => {
  301. if(res.data.code==200){
  302. self.cityList = res.data.rows
  303. }
  304. });
  305. },
  306. getProvinceList() {
  307. let self = this
  308. if(self.provinceList.length>0){
  309. return
  310. }
  311. this.$api.getProvinceList().then(res => {
  312. if(res.data.code==200){
  313. self.provinceList = res.data.rows
  314. if(self.provinceList.length>0){
  315. self.getCityList(self.provinceList[0].areaId)
  316. }
  317. }
  318. });
  319. },
  320. goodsGradeList(goodsId) {
  321. let self = this
  322. this.$api.goodsGradeList({goodsId:goodsId}).then(res => {
  323. if(res.data.code==200){
  324. self.gradeList = res.data.rows
  325. if(self.gradeList.length==0){
  326. let item = {
  327. className:'系统分班',
  328. gradeId:0
  329. }
  330. self.gradeList.push(item)
  331. }
  332. }
  333. });
  334. },
  335. openPopup(index,item,itemIndex){
  336. this.detail = item
  337. this.detailIndex = itemIndex
  338. if(index==0){
  339. this.gradeValue = -1
  340. this.show = true
  341. this.goodsGradeList(item.goodsId)
  342. }else{
  343. this.applyObj={
  344. applyAreasJson:null,
  345. examDateJson:null
  346. }
  347. this.show1 = true
  348. this.getProvinceList()
  349. self.getExamine(item.projectId)
  350. }
  351. },
  352. checkboxGroupChange(e){
  353. this.checkboxList = e
  354. },
  355. countPrice(list){
  356. },
  357. checkboxChange1(e) {
  358. //console.log(e);
  359. },
  360. login(){
  361. uni.navigateTo({url:'/pages/login/login'});
  362. },
  363. cartList() {
  364. let self = this
  365. this.allChecked = false
  366. this.totalPrice = 0.00
  367. this.checkboxList =[]
  368. this.$api.cartList().then(res => {
  369. if(res.data.code==200){
  370. for (let i = 0; i < res.data.rows.length; i++) {
  371. let item = res.data.rows[i]
  372. item.checked = false
  373. if(item.status!=1||item.goodsStatus!=1){
  374. item.disabled = true
  375. }else{
  376. item.disabled = false
  377. }
  378. item.show = false
  379. item.gradObj = {} //存储班级
  380. item.applyAreas = {}
  381. item.examDate = {}
  382. }
  383. self.list = res.data.rows
  384. }
  385. });
  386. },
  387. delItem(item) {
  388. let self = this
  389. this.$api.deleteCart(item.id).then(res => {
  390. if(res.data.code==200){
  391. self.cartList()
  392. }
  393. });
  394. },
  395. swipeChange(e, item) {
  396. item.show = e;
  397. },
  398. goBuy(){
  399. console.log(this.checkboxList,66)
  400. return
  401. this.$navTo.togo('/pages2/order/confirm_pay');
  402. },
  403. checkboxChange(n) {
  404. console.log('change', n);
  405. if(n.value){
  406. this.totalPrice += this.list[n.name].standPrice
  407. }else{
  408. this.totalPrice -= this.list[n.name].standPrice
  409. }
  410. },
  411. checkboxAllChange(n){
  412. this.totalPrice = 0.00
  413. this.checkboxList = []
  414. if(n.value){
  415. for(let i =0;i<this.list.length;i++){
  416. this.list[i].checked = true
  417. this.totalPrice += this.list[i].standPrice
  418. this.checkboxList.push(i)
  419. }
  420. }else{
  421. for(let i =0;i<this.list.length;i++){
  422. this.list[i].checked = false
  423. }
  424. }
  425. }
  426. }
  427. }
  428. </script>
  429. <style >
  430. page{
  431. background-color: #EAEEF1;
  432. }
  433. </style>
  434. <style scoped>
  435. .operate{
  436. background-color: #FF3B30;
  437. color: #FFFFFF;
  438. border-top-right-radius: 16rpx;
  439. border-bottom-right-radius: 16rpx;
  440. margin-bottom: 20rpx;
  441. display: flex;
  442. align-items:center;
  443. justify-content:center;
  444. padding: 0 20rpx;
  445. }
  446. .picker-item {
  447. height: 50px;
  448. align-items: center;
  449. justify-content: center;
  450. text-align: center;
  451. }
  452. .picker-view {
  453. width: 100%;
  454. height: 420rpx;
  455. text-align: center;
  456. }
  457. .topTxt{
  458. font-size: 30rpx;
  459. color: #666666;
  460. text-align: center;
  461. padding: 20rpx 0;
  462. }
  463. .blackTxt{
  464. font-size: 30rpx;
  465. font-family: PingFang SC;
  466. font-weight: bold;
  467. color: #333333;
  468. }
  469. .redTxt{
  470. font-size: 30rpx;
  471. font-family: PingFang SC;
  472. color: #FF2D55;
  473. margin-top: 13rpx;
  474. }
  475. .blue-box{
  476. background: #EBF5FF;
  477. }
  478. .white-box{
  479. width: 646rpx;
  480. border-radius: 24rpx;
  481. align-items: center;
  482. display: flex;
  483. padding-left: 15rpx;
  484. }
  485. .okBtn{
  486. width: 200rpx;
  487. height: 64rpx;
  488. background: linear-gradient(0deg, #015EEA, #00C0FA);
  489. border-radius: 32rpx;
  490. color: #FFFFFF;
  491. text-align: center;
  492. line-height: 64rpx;
  493. }
  494. .confrim-btn{
  495. height: 98rpx;
  496. width: 100%;
  497. display: flex;
  498. align-items: center;
  499. justify-content:center;
  500. }
  501. .grade{
  502. height: 23rpx;
  503. font-size: 24rpx;
  504. color: #999999;
  505. margin: 0 auto;
  506. margin-top: 15rpx;
  507. text-align: center;
  508. }
  509. .line1{
  510. width: 80rpx;
  511. height: 8rpx;
  512. background: #999999;
  513. border-radius: 4rpx;
  514. margin: 0 auto;
  515. margin-top: 15rpx;
  516. }
  517. .popup_box {
  518. height: 700rpx;
  519. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(145, 156, 178, 0.1);
  520. border-radius: 32rpx 32rpx 0rpx 0rpx;
  521. }
  522. .item{
  523. width: 100%;
  524. background: #FFFFFF;
  525. border-radius: 16rpx;
  526. margin-bottom: 20rpx;
  527. padding: 15rpx;
  528. display: flex;
  529. }
  530. .priceTag{
  531. font-size: 30rpx;
  532. font-family: PingFang SC;
  533. font-weight: bold;
  534. color: #FF2D55;
  535. display: flex;
  536. flex-direction: row-reverse;
  537. margin-right: 8rpx;
  538. }
  539. .btn2{
  540. width: 200rpx;
  541. height: 64rpx;
  542. background: linear-gradient(0deg, #015EEA, #00C0FA);
  543. border-radius: 32rpx;
  544. text-align: center;
  545. line-height: 64rpx;
  546. }
  547. .bottomBox{
  548. position: fixed;
  549. bottom: 0;
  550. width: 100%;
  551. left: 0;
  552. height:98rpx ;
  553. background-color: #FFFFFF;
  554. display: flex;
  555. justify-content: space-between;
  556. align-items: center;
  557. padding: 0 30rpx;
  558. }
  559. </style>