shoppingCart.vue 16 KB

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