cart.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. <template>
  2. <view class="container cart clearfix">
  3. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="9"></tui-skeleton>
  4. <view class="container-cart-main tui-skeleton" :class="[!isShowNoLogin ? 'show' : 'none']">
  5. <view class="container-cart" v-if="goodsList.length > 0" :class="showContentClass">
  6. <scroll-view class="cart-content" scroll-y @scrolltolower="toLower">
  7. <view class="goods-list" v-if="isShowGoodsList">
  8. <view v-for="(item, index) in goodsList" :key="index" class="goods-item">
  9. <view class="shoptitle">
  10. <!--选择商店的全部商品 :disabled="isNnder"-->
  11. <view class="checkbox-box">
  12. <button class="checkbox iconfont"
  13. :class="[item.checked ?'icon-gouxuanl':'icon-weigouxuan']"
  14. @click.stop="checkShop(item)" :disabled="item.isDisabled && !isshowDelbtn">
  15. </button>
  16. </view>
  17. <view class="text">{{item.name}}</view>
  18. </view>
  19. <view class="productlist">
  20. <view class="goods-pros"
  21. v-for="(pros,idx) in item.productsList"
  22. :key="idx"
  23. >
  24. <view class="goods-pros-t">
  25. <!--选择商品-->
  26. <view class="checkbox-box" :class="[pros.validFlag == '2' && !isshowDelbtn ?'disabled' : '']">
  27. <button class="checkbox iconfont"
  28. :disabled="pros.validFlag == '2' && !isshowDelbtn"
  29. :class="[pros.productsChecked ?'icon-gouxuanl':'icon-weigouxuan']"
  30. @click.stop="ischeck(item,pros,idx)">
  31. </button>
  32. </view>
  33. <view class="pros-img" @click.stop="navToListPage(pros.id)" ><image :src="pros.mainImage" alt="" /></view>
  34. <view class="pros-product">
  35. <view class="producttitle" @click.stop="navToListPage(pros.id)" >
  36. <text v-if="pros.validFlag == '2'" class="no-text">商品已下架</text>{{pros.name}}
  37. </view>
  38. <view class="productspec">规格:{{pros.unit}}</view>
  39. <view class="productprice">
  40. <!--使用过滤器对总价改变-->
  41. <view class="price"
  42. :class="[pros.validFlag == '2' ?'disabled' : '']">
  43. <text :class="[pros.validFlag == '2' ?'disabled' : 'money-sign']">¥</text>{{pros.retailPrice.toFixed(2)}}
  44. </view>
  45. <view class="count" v-if="pros.validFlag == '1'" :class="[isshowDelbtn ? 'none':'show']">
  46. <view class="number-box">
  47. <view class="iconfont icon-jianhao" :class="[pros.validFlag == '2'?'disabled':'']" @click="changeCountSub(item,pros)"></view>
  48. <input class="btn-input" type="number" maxlength='4' v-model="pros.productCount" @blur="changeNnmber($event,item,pros)">
  49. <view class="iconfont icon-jiahao" :class="[pros.validFlag == '2'?'disabled':'']" @click="changeCountAdd(item,pros)"></view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="goods-pros-b" :class="[isshowDelbtn ? 'none':'show']" >
  58. <view class="sum">合计:<text class="money"><text class="money-sign">¥</text>{{item.totalPrice.toFixed(2)}}</text></view>
  59. </view>
  60. </view>
  61. </view>
  62. <!--加载loadding-->
  63. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  64. <tui-nomore :visible="!pullUpOn" bgcolor="#F7F7F7" :text='nomoreText'></tui-nomore>
  65. <!--加载loadding-->
  66. </scroll-view>
  67. <!-- 脚部菜单 -->
  68. <view class="footer">
  69. <view class="footer-le">
  70. <view class="foot-check checkbox-box" @tap.stop="checkAll()">
  71. <button class="checkbox iconfont" :class="[isCheckAll?'icon-gouxuan':'icon-weigouxuan']"></button>
  72. <view class="text">全选</view>
  73. </view>
  74. <view class="foot-check-delbtn">
  75. <button class="delBtn" @tap.stop="showDelManager">删除</button>
  76. </view>
  77. <view class="sum">总价:<text class="money-sign">¥</text><text class="money">{{allPrice.toFixed(2)}}</text></view>
  78. </view>
  79. <view v-if="!isshowDelbtn" class="footer-ri" >
  80. <view class="btn" @tap="toConfirmation">去结算({{allCount}})</view>
  81. </view>
  82. <view v-else class="footer-del">
  83. <view class="btn btn-cancel" @tap.stop="hideDelManage">取消</view>
  84. <view class="btn btn-confirm" @tap.stop="deleteList">删除</view>
  85. </view>
  86. </view>
  87. </view>
  88. <view v-else class="cart-content empty" :class="showEmptyClass">
  89. <view class="empty-container">
  90. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  91. <text class="error-text">购物车空空如也,快去商城逛逛吧~</text>
  92. <view class="login-btn" @click="goIndex">去商城</view>
  93. </view>
  94. </view>
  95. </view>
  96. <no-login
  97. v-if="isShowNoLogin"
  98. :telPhone='telPhone'
  99. :alertType ='3'
  100. :path = 'true'
  101. >
  102. </no-login>
  103. <!-- 删除购物车提示弹窗 -->
  104. <model-alert v-if="isShowDelModal"
  105. :alertText='alertText'
  106. @btnConfirm ='deleteCart'>
  107. </model-alert>
  108. <!-- 透明模态层 -->
  109. <modal-layer v-if='modallayer'></modal-layer>
  110. </view>
  111. </template>
  112. <script>
  113. import modelAlert from '@/components/module/modelAlert/modelAlert'
  114. import noLogin from '@/components/module/noLogin/nologin'//未登录弹窗
  115. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  116. import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
  117. import tuiNomore from "@/components/tui-components/nomore/nomore"
  118. import modalLayer from "@/components/modal-layer"
  119. export default{
  120. components:{
  121. modelAlert,
  122. noLogin,
  123. tuiSkeleton,
  124. tuiLoadmore,
  125. tuiNomore,
  126. modalLayer
  127. },
  128. data(){
  129. return{
  130. userID:'',
  131. telPhone:'',
  132. alertType:'',
  133. isStock:'',
  134. goodsList:[], //购物车的商品
  135. delGoodsList:'',//要删除的商品
  136. setGoodData:'', //确认订单的商品
  137. isCheckAll:false,//是否全选
  138. allPrice:0,//所有价格
  139. allCount:0,//被选中的产品数量
  140. isNnder:true,
  141. isModallayer:false,
  142. skeletonShow:true,
  143. isShowNoLogin:false,
  144. isShowGoodsList:true,// 显示购物车
  145. isshowDelbtn:false,
  146. isShowDelModal:false,//删除商品确认弹窗
  147. isDisabled: false, // 供应商/店铺全选是否禁用状态
  148. showEmptyClass:'none',//显示空购物车
  149. showContentClass:'show',//显示列表
  150. scrollHeight: 'auto',
  151. alertText:'确定删除选中的商品吗?',
  152. nomoreText: '上拉显示更多',
  153. hasNextPage: false,
  154. loadding: false,
  155. pullUpOn: true,
  156. pullFlag: true,
  157. pageSize: 10,
  158. pageNum: 1,
  159. }
  160. },
  161. onLoad(){
  162. this.setScrollHeight();
  163. },
  164. filters:{//单件商品的价格 × 数量
  165. totalprice(val,count){
  166. return (val * count).toFixed(2)
  167. }
  168. },
  169. methods:{
  170. initData(){
  171. this.isModallayer = false //遮罩层 防止多次点击
  172. this.skeletonShow = true //预加载圆圈
  173. this.isCheckAll=false//是否全选
  174. this.$api.getStorage().then((resolve) => {
  175. this.userID = resolve.userID;
  176. this.isShowNoLogin = false;
  177. this.initGetCartGoodsList();
  178. })
  179. },
  180. initLogin(){
  181. this.$api.getStorage().then((resolve) => {
  182. this.skeletonShow = false //预加载圆圈
  183. this.telPhone = resolve.tel;
  184. this.isShowNoLogin = true;
  185. this.alertType ='3'
  186. })
  187. },
  188. setScrollHeight() {
  189. // 窗口高度-footer高度
  190. const {windowHeight, pixelRatio} = uni.getSystemInfoSync();
  191. setTimeout(()=> {
  192. const query = uni.createSelectorQuery().in(this);
  193. query.selectAll('.footer').boundingClientRect();
  194. query.exec(res => {
  195. this.windowHeight = windowHeight;
  196. if(res[0][0]) {
  197. this.scrollHeight = windowHeight - res[0][0].height;
  198. }
  199. })
  200. }, 500)
  201. },
  202. initGetCartGoodsList(){//初始化购物车 index:1
  203. let param = {userID:this.userID,organizeID:this.userOrganizeID,index:1,pageSize:this.pageSize}
  204. this.$api.get('/shopping/cart',param,
  205. response =>{
  206. this.$store.commit('updateAllNum',response.data.cartQuantity)
  207. const results = response.data.page.results;
  208. if(results&&results.length > 0){
  209. this.showEmptyClass ='none'
  210. this.showContentClass ='show'
  211. this.hasNextPage = response.data.page.hasNextPage;
  212. this.goodsList = results;
  213. this.goodsList.forEach((item,index) => {
  214. let productsListLength = item.productsList.length,
  215. invalidLength = 0;
  216. item.productsList.forEach(pros => {
  217. pros.shopID = item.shopID;
  218. if(pros.validFlag == 2) {invalidLength++;}
  219. })
  220. item.isDisabled = invalidLength === productsListLength;
  221. })
  222. this.pullFlag = false;
  223. setTimeout(()=>{this.pullFlag = true;},500)
  224. if(this.hasNextPage){
  225. this.pullUpOn = false
  226. this.nomoreText = '上拉显示更多'
  227. }else{
  228. if(this.goodsList.length < 4){
  229. this.pullUpOn = true
  230. }else{
  231. this.pullUpOn = false
  232. this.nomoreText = '已至底部'
  233. }
  234. }
  235. } else {
  236. this.goodsList = [];
  237. this.showEmptyClass ='show'
  238. this.showContentClass ='none'
  239. }
  240. this.skeletonShow = false
  241. }
  242. )
  243. },
  244. getOnReachBottomData(){//上拉加载
  245. this.pageNum+=1
  246. console.log(this.pageNum)
  247. let param = {userID:this.userID,organizeID:this.userOrganizeID,index:this.pageNum,pageSize:this.pageSize}
  248. this.$api.get('/shopping/cart',param,
  249. response => {
  250. if(response.code === '1'){
  251. let resData = response.data.page.results
  252. this.hasNextPage = response.data.page.hasNextPage;
  253. this.goodsList = this.goodsList.concat(resData)
  254. this.pullFlag = false;// 防上拉暴滑
  255. setTimeout(()=>{this.pullFlag = true;},500)
  256. if(this.hasNextPage){
  257. this.pullUpOn = false
  258. this.nomoreText = '上拉显示更多'
  259. }else{
  260. this.loadding = false
  261. this.pullUpOn = false
  262. this.nomoreText = '已至底部'
  263. }
  264. }else{
  265. this.$util.msg(response.msg,2000);
  266. }
  267. }
  268. )
  269. },
  270. ischeck(item,pro){//为未选中的时候改变为true,反之为true
  271. pro.productsChecked = !pro.productsChecked;
  272. this.updateProductCheckedAllBtn(item);
  273. this.updateCheckAllBtn();
  274. },
  275. updateProductCheckedAllBtn(item) {// 单独每个供应商的勾选判断
  276. let productsList = item.productsList,
  277. productsCheckedLength = 0,
  278. disabledLength = 0;
  279. if(this.isshowDelbtn) {
  280. productsList.forEach(pros => {
  281. if(pros.productsChecked) {
  282. productsCheckedLength++;
  283. }
  284. })
  285. } else {
  286. productsList.forEach(pros => {
  287. if(pros.productsChecked && pros.validFlag != 2) {
  288. productsCheckedLength++;
  289. }
  290. if(pros.validFlag == 2) {
  291. disabledLength++;
  292. }
  293. })
  294. }
  295. item.checked = productsCheckedLength === productsList.length - disabledLength;
  296. },
  297. updateCheckAllBtn() {// 全选勾选判断
  298. let goodsCheckedLength = 0,
  299. disabledListLength = 0,
  300. goodsList = this.goodsList;
  301. goodsList.forEach(item => {
  302. if(item.checked) {
  303. goodsCheckedLength++;
  304. }
  305. if(item.isDisabled && !this.isshowDelbtn) {
  306. disabledListLength++;
  307. }
  308. })
  309. this.isCheckAll = goodsCheckedLength === goodsList.length - disabledListLength;
  310. },
  311. checkShop(item){//与单选商品类似
  312. item.checked = !item.checked;
  313. this.setProductChecked(item);
  314. this.updateCheckAllBtn();
  315. },
  316. setProductChecked(item) {
  317. let products = item.productsList;
  318. products.forEach(pros=>{
  319. if(item.checked) {
  320. if(pros.validFlag =='2'){
  321. // 无效
  322. this.isNnder = true;
  323. pros.productsChecked = this.isshowDelbtn ?true :false;
  324. }else{
  325. // 有效
  326. this.isNnder = false;
  327. pros.productsChecked = true;
  328. }
  329. } else {
  330. pros.productsChecked = false;
  331. }
  332. })
  333. },
  334. updateBothCheckBtn() {
  335. if(this.isshowDelbtn) {
  336. // 当管理删除按钮出现时,失效的商品可被选择
  337. this.goodsList.forEach((item)=>{
  338. item.checked = this.isCheckAll;
  339. this.setProductChecked(item);
  340. })
  341. } else {
  342. this.goodsList.forEach((item)=>{
  343. item.checked = this.isCheckAll && !item.isDisabled;
  344. this.setProductChecked(item);
  345. })
  346. }
  347. },
  348. checkAll(){//全选方法内调用方法
  349. this.isCheckAll = !this.isCheckAll;
  350. this.updateBothCheckBtn();
  351. },
  352. totalShopPeice(){//每次所属会所下的商品增减重新计算合计价格&减去含有下架的商品
  353. let prosPrice=0;
  354. let validPrice =0;
  355. let validList=[];
  356. let productsList=[];
  357. this.goodsList.map((item,index)=>{
  358. productsList=item.productsList;
  359. prosPrice=productsList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  360. productsList.forEach(pros =>{
  361. if(pros.validFlag =='2'){
  362. validList.push(pros)
  363. validPrice = validList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  364. item.totalPrice = prosPrice - validPrice
  365. }else{
  366. item.totalPrice = prosPrice
  367. }
  368. })
  369. })
  370. },
  371. //计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
  372. totalPeice(){
  373. this.allPrice = 0
  374. let prosPrice=0;
  375. let validPrice=0;
  376. let validList =[];
  377. let productsList =[];
  378. this.goodsList.forEach((item,index)=>{
  379. productsList=item.productsList;
  380. productsList.forEach(pros=>{
  381. if(pros.productsChecked){
  382. prosPrice+=pros.retailPrice*pros.productCount;
  383. if(pros.validFlag =='2'){
  384. validList.push(pros)
  385. validPrice = validList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  386. this.allPrice = prosPrice - validPrice
  387. }else{
  388. this.allPrice = prosPrice
  389. }
  390. }
  391. })
  392. })
  393. },
  394. totalCount(){//计算总数量
  395. this.allCount = 0
  396. let prosAllCount=0
  397. let validCount = 0
  398. let validList =[];
  399. let productsList =[];
  400. this.goodsList.forEach(item=>{
  401. productsList = item.productsList
  402. productsList.forEach(pros=>{
  403. if(pros.productsChecked){
  404. prosAllCount+=parseInt(pros.productCount);
  405. if(pros.validFlag =='2'){
  406. validList.push(pros)
  407. validList.forEach(val =>{
  408. validCount += val.productCount
  409. })
  410. this.allCount = prosAllCount - validCount
  411. }else{
  412. this.allCount = prosAllCount
  413. }
  414. }
  415. })
  416. })
  417. },
  418. changeCountAdd(item,pros){//商品数量加加
  419. let ladderPriceList = pros.productLadderPrices;
  420. if(pros.productCount>=pros.stock){
  421. pros.productCount= pros.stock
  422. this.isStock =true
  423. return
  424. }else{
  425. pros.productCount++
  426. if(pros.ladderPriceFlag == '1'){
  427. ladderPriceList.forEach((item,index)=>{
  428. if(pros.productCount>=item.buyNum){
  429. pros.retailPrice = item.buyPrice
  430. }
  431. })
  432. }
  433. this.isStock =false
  434. }
  435. this.updateShoppogNum(pros)
  436. this.totalShopPeice();
  437. },
  438. changeCountSub(item,pros){//商品数量减减
  439. let ladderPriceList = pros.productLadderPrices;
  440. if(pros.productCount<=pros.minBuyNumber){
  441. pros.productCount= pros.minBuyNumber
  442. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  443. return
  444. }else{
  445. pros.productCount--
  446. if(pros.ladderPriceFlag == '1'){
  447. ladderPriceList.forEach((item,index)=>{
  448. if(pros.productCount>=item.buyNum){
  449. pros.retailPrice = item.buyPrice
  450. }
  451. })
  452. }
  453. }
  454. this.updateShoppogNum(pros)
  455. this.totalShopPeice();
  456. },
  457. changeNnmber(e,item,pros){
  458. let _value = e.detail.value;
  459. if(!this.$api.isNumber(_value)){
  460. pros.productCount = pros.minBuyNumber
  461. }else if(_value < pros.minBuyNumber){
  462. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  463. pros.productCount = pros.minBuyNumber
  464. }else{
  465. pros.productCount = e.detail.value
  466. }
  467. this.updateShoppogNum(pros)
  468. this.totalShopPeice();
  469. },
  470. updateShoppogNum(pros){//加减购物车商品更新到后台
  471. this.$api.get('/shopping/update',
  472. {
  473. userID:this.userID,
  474. productID:pros.id,
  475. productCount:pros.productCount
  476. },
  477. response =>{
  478. if(response.code ==='1'){
  479. // console.log(response)
  480. this.isShowDelModal = false
  481. this.isshowDelbtn = false;
  482. this.initGetCartGoodsList();
  483. }
  484. }
  485. )
  486. },
  487. //跳转确认订单页面
  488. toConfirmation(){
  489. let setGoodsList=[];
  490. this.goodsList.forEach(res=>{
  491. let products = res.productsList
  492. products.forEach(pros=>{
  493. if(pros.productsChecked){
  494. setGoodsList.push(pros.id)
  495. }
  496. })
  497. })
  498. if(setGoodsList == ''){
  499. this.$util.msg("请先选择结算商品~",2000);
  500. return
  501. }else{
  502. /**
  503. * @获取勾选的商品ID拼接字符串逗号隔开,最后一个逗号去掉
  504. * @获取勾选的商品分类ID拼接字符串格式逗号隔开,最后一个逗号去掉
  505. */
  506. let productID = '';
  507. let classifyID ='';
  508. this.goodsList.forEach(el=>{
  509. el.productsList.forEach(pros=>{
  510. if(pros.productsChecked){
  511. productID += pros.id+','
  512. classifyID += pros.classifyID+','
  513. }
  514. })
  515. })
  516. let CartPramsData={
  517. allPrice:this.allPrice,
  518. allCount:this.allCount,
  519. id:productID.substring(0,productID.lastIndexOf(',')),
  520. productCount:'',
  521. classifyID:classifyID.substring(0,classifyID.lastIndexOf(',')),
  522. }
  523. this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({data:CartPramsData})}`)
  524. }
  525. },
  526. setOrderGoods(){//本地获取勾选商品信息***暂时丢弃***
  527. let setGoodData = {}
  528. let prosPrice =0;
  529. let prosCount =0;
  530. let goodsArr = this.goodsList.map(el => {
  531. el.productsList = el.productsList.filter(item => item.productsChecked)
  532. prosPrice=el.productsList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  533. el.productsList.forEach(pros=>{
  534. el.totalCount += pros.productCount;
  535. })
  536. el.totalPrice = prosPrice
  537. return el
  538. }).filter(el => el.productsList && el.productsList.length !==0);
  539. setGoodData = {
  540. allPrice:this.allPrice,
  541. allCount:this.allCount,
  542. goodList:goodsArr
  543. }
  544. return setGoodData
  545. },
  546. // 显示删除商品管理
  547. showDelManager(){
  548. this.isshowDelbtn = true;
  549. this.isNnder = true;
  550. if(this.isCheckAll) {
  551. this.updateBothCheckBtn();
  552. } else {
  553. // 失效也被勾选
  554. this.goodsList.forEach(item => {
  555. if(item.checked) {
  556. item.productsList.forEach(pros => {
  557. pros.productsChecked = true;
  558. })
  559. }
  560. })
  561. this.updateCheckAllBtn();
  562. }
  563. },
  564. hideDelManage(){
  565. this.isshowDelbtn = false;
  566. if(this.isCheckAll) {
  567. this.updateBothCheckBtn();
  568. } else {
  569. // 失效商品取消勾选
  570. this.goodsList.forEach(item => {
  571. if(item.isDisabled) {
  572. item.checked = false;
  573. }
  574. item.productsList.forEach(pros => {
  575. if(pros.validFlag == 2) {
  576. pros.productsChecked = false;
  577. }
  578. })
  579. })
  580. this.updateCheckAllBtn();
  581. }
  582. },
  583. // 删除商品
  584. deleteList(){
  585. this.delGoodsList=[];
  586. this.goodsList.forEach(delitem=>{
  587. let products = delitem.productsList
  588. products.forEach(pros=>{
  589. if(pros.productsChecked){
  590. this.delGoodsList += pros.id+','
  591. }
  592. })
  593. })
  594. // console.log(this.delGoodsList);
  595. if(this.delGoodsList.length == 0){
  596. this.$util.msg("请选择要删除的商品~",2000);
  597. return
  598. }else{
  599. this.isShowDelModal = true
  600. }
  601. },
  602. deleteCart(data){//删除购物车商品
  603. let self = this;
  604. this.$api.get('/shopping/delete',
  605. {
  606. userID:this.userID,
  607. productIDs:this.delGoodsList
  608. },
  609. response =>{
  610. if(response.code ==='1'){
  611. // console.log(response)
  612. this.$util.msg(response.msg,2000);
  613. this.isShowDelModal = false
  614. this.isshowDelbtn = false;
  615. setTimeout(function(){
  616. self.initGetCartGoodsList();
  617. },2000)
  618. }else{
  619. this.$util.msg(response.msg,3000);
  620. setTimeout(function(){
  621. uni.switchTab({
  622. url:'/pages/tabBar/home/home'
  623. })
  624. },1000)
  625. }
  626. }
  627. )
  628. },
  629. goIndex(){
  630. uni.switchTab({
  631. url: '/pages/tabBar/home/home'
  632. });
  633. },
  634. goNavto(url){
  635. uni.navigateTo ({
  636. url
  637. })
  638. },
  639. navToListPage(id){
  640. this.isModallayer = true;
  641. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  642. }
  643. },
  644. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  645. goodsList:{
  646. deep:true,
  647. handler(val,oldval){
  648. this.totalPeice()
  649. this.totalCount()
  650. }
  651. }
  652. },
  653. onReachBottom() {
  654. if(this.hasNextPage){
  655. this.loadding = true
  656. this.pullUpOn = true
  657. this.getOnReachBottomData()
  658. }
  659. },
  660. onPullDownRefresh() {//下拉刷新
  661. this.initGetCartGoodsList()
  662. uni.stopPullDownRefresh()
  663. },
  664. onShow(){
  665. this.$api.loginStatus().then((resolveData) => {
  666. if(resolveData){
  667. this.initData()
  668. }else{
  669. this.initLogin()
  670. }
  671. });
  672. },
  673. }
  674. </script>
  675. <style lang="scss">
  676. page{
  677. background: #f7f7f7;
  678. }
  679. .cart-content{
  680. position: relative;
  681. padding-bottom:74rpx;
  682. }
  683. .container-cart-main.none{
  684. display: none;
  685. }
  686. .container-cart-main.show{
  687. display: block;
  688. }
  689. .cart-content.empty.none{
  690. display: none;
  691. }
  692. .cart-content.empty.show{
  693. display: block;
  694. }
  695. .container-cart.show{
  696. display: block;
  697. }
  698. .container-cart.none{
  699. display: none;
  700. }
  701. .empty-container.none{
  702. display: none;
  703. }
  704. .empty-container.show{
  705. display: flex;
  706. }
  707. .checkbox-box{
  708. display: flex;
  709. align-items: center;
  710. .checkbox{
  711. display: flex;
  712. margin: 0;
  713. padding: 0;
  714. display: flex;
  715. flex-direction: column;
  716. align-items: center;
  717. box-sizing: border-box;
  718. text-align: center;
  719. text-decoration: none;
  720. border-radius: 0;
  721. -webkit-tap-highlight-color: transparent;
  722. overflow: hidden;
  723. background-color:#FFFFFF;
  724. font-size: 36rpx;
  725. color:$color-system;
  726. }
  727. &.disabled{
  728. .checkbox{
  729. color:#999999
  730. }
  731. }
  732. .text{
  733. font-size: $font-size-24;
  734. margin-left: 10rpx;
  735. }
  736. }
  737. .goods-list{
  738. width: 100%;
  739. height: auto;
  740. border-top: 1px solid #EBEBEB;
  741. background-color: #F7F7F7;
  742. .goods-item{
  743. width: 702rpx;
  744. padding: 0 24rpx;
  745. background: #FFFFFF;
  746. margin-bottom: 24rpx;
  747. }
  748. .shoptitle{
  749. display: flex;
  750. align-items: center;
  751. height: 80rpx;
  752. // border-bottom: 1px solid #EBEBEB;
  753. line-height: 80rpx;
  754. .checkbox-box{
  755. margin-left: 18rpx;
  756. }
  757. .text{
  758. margin-left: 37rpx;
  759. font-size: $font-size-28;
  760. color: $text-color;
  761. text-align: left;
  762. font-weight: bold;
  763. }
  764. }
  765. .goods-pros{
  766. width: 100%;
  767. height: auto;
  768. }
  769. .goods-pros-t{
  770. display: flex;
  771. align-items: center;
  772. width: 100%;
  773. height: 217rpx;
  774. padding:0 0 26rpx 0;
  775. .checkbox-box{
  776. margin-left: 22rpx;
  777. }
  778. .pros-img{
  779. width: 210rpx;
  780. height: 100%;
  781. border-radius: 10rpx;
  782. margin:0 26rpx 0 38rpx;
  783. border:1px solid #f3f3f3;
  784. image{
  785. width: 100%;
  786. height: 100%;
  787. border-radius: 10rpx;
  788. }
  789. }
  790. }
  791. .goods-pros-b{
  792. width:622rpx;
  793. margin-left: 84rpx;
  794. height: 40rpx;
  795. padding:0 0 26rpx 0;
  796. // border-top: 1px solid #EBEBEB;
  797. &.show{
  798. display: block;
  799. }
  800. &.none{
  801. display: none;
  802. }
  803. .sum{
  804. font-size: $font-size-28;
  805. line-height: 40rpx;
  806. color: $text-color;
  807. display: flex;
  808. justify-content: flex-end;
  809. .money{
  810. color: #FF2A2A;
  811. font-size: $font-size-28;
  812. }
  813. .money-sign{
  814. font-size: $font-size-24;
  815. color: #FF2A2A;
  816. }
  817. }
  818. }
  819. .pros-product{
  820. width: 386rpx;
  821. height: 100%;
  822. line-height: 36rpx;
  823. font-size: $font-size-26;
  824. position: relative;
  825. .producttitle{
  826. width: 100%;
  827. display: inline-block;
  828. height: auto;
  829. text-overflow:ellipsis;
  830. display: -webkit-box;
  831. word-break: break-all;
  832. -webkit-box-orient: vertical;
  833. -webkit-line-clamp: 2;
  834. overflow: hidden;
  835. margin-bottom: 8rpx;
  836. .no-text{
  837. display: inline-block;
  838. height:36rpx;
  839. padding: 0 12rpx;
  840. line-height: 36rpx;
  841. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  842. border-radius:18rpx;
  843. text-align: center;
  844. color: #FFFFFF;
  845. font-size: $font-size-24;
  846. margin-right: 24rpx;
  847. }
  848. }
  849. .productspec{
  850. height: 36rpx;
  851. color: #999999;
  852. }
  853. .productprice{
  854. height: 48rpx;
  855. position: absolute;
  856. width: 100%;
  857. bottom: 0;
  858. .price{
  859. line-height: 48rpx;
  860. font-size: $font-size-28;
  861. width: 48%;
  862. color: #FF2A2A;
  863. float: left;
  864. &.disabled{
  865. color: #999999;
  866. }
  867. .money-sign{
  868. font-size: $font-size-24;
  869. color: #FF2A2A;
  870. }
  871. }
  872. .count{
  873. height: 100%;
  874. float: right;
  875. position: relative;
  876. &.show{
  877. display: block;
  878. }
  879. &.none{
  880. display: none;
  881. }
  882. .number-box{
  883. display: flex;
  884. justify-content: center;
  885. align-items: center;
  886. .iconfont{
  887. font-size: $font-size-24;
  888. padding:0 20rpx;
  889. color: $text-color;
  890. text-align: center;
  891. line-height: 48rpx;
  892. font-weight: bold;
  893. }
  894. .btn-input{
  895. width: 62rpx;
  896. height: 48rpx;
  897. line-height: 48rpx;
  898. background: #F8F8F8;
  899. border-radius: 4rpx;
  900. text-align: center;
  901. font-size: $font-size-24;
  902. }
  903. }
  904. .uni-numbox{
  905. position: absolute;
  906. left: 45rpx;
  907. bottom: 0;
  908. .uni-numbox-minus, .uni-numbox-plus{
  909. width: 50rpx;
  910. line-height: 40rpx;
  911. }
  912. .uni-numbox-value {
  913. font-size: $font-size-28;
  914. width: 60rpx;
  915. }
  916. }
  917. }
  918. }
  919. }
  920. }
  921. .footer{
  922. width: 100%;
  923. background-color: #FFFFFF;
  924. height: 110rpx;
  925. position: fixed;
  926. bottom: 0rpx;
  927. z-index: 10;
  928. .footer-le{
  929. width: 490rpx;
  930. height: 100%;
  931. padding:0 30rpx;
  932. float: left;
  933. .text{
  934. font-weight: bold;
  935. }
  936. .foot-check{
  937. width: 100rpx;
  938. float: left;
  939. line-height: 110rpx;
  940. font-size: $font-size-24;
  941. .checkbox{
  942. width: 40rpx;
  943. text-align: center;
  944. }
  945. .text{
  946. width: 60rpx;
  947. float: right;
  948. }
  949. }
  950. .foot-check-delbtn{
  951. float: left;
  952. .delBtn{
  953. margin: 0;
  954. padding: 0;
  955. display: flex;
  956. flex-direction: column;
  957. align-items: center;
  958. box-sizing: border-box;
  959. font-size: $font-size-24;
  960. text-align: center;
  961. text-decoration: none;
  962. border-radius: 0;
  963. -webkit-tap-highlight-color: transparent;
  964. overflow: hidden;
  965. background-color:#FFFFFF;
  966. color: #FF2A2A;
  967. padding: 0 24rpx;
  968. display: flex;
  969. justify-content: center;
  970. align-items: center;
  971. line-height: 110rpx;
  972. font-weight: bold;
  973. &.none{
  974. display: none;
  975. }
  976. }
  977. }
  978. .sum{
  979. font-size: $font-size-28;
  980. line-height: 110rpx;
  981. color: $text-color;
  982. display: flex;
  983. justify-content: flex-end;
  984. .money{
  985. color: #FF2A2A;
  986. }
  987. .money-sign{
  988. font-size: $font-size-24;
  989. color: #FF2A2A;
  990. }
  991. }
  992. }
  993. .footer-ri{
  994. width: 200rpx;
  995. height: 100%;
  996. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  997. float: right;
  998. display: flex;
  999. justify-content: space-between;
  1000. align-items: center;
  1001. z-index: 999;
  1002. &.none{
  1003. display: none;
  1004. }
  1005. .btn{
  1006. width: 200rpx;
  1007. height: 100%;
  1008. font-size: $font-size-28;
  1009. line-height: 110rpx;
  1010. color: #FFFFFF;
  1011. display: flex;
  1012. justify-content: center;
  1013. align-items: center;
  1014. }
  1015. }
  1016. .footer-del{
  1017. width: 400rpx;
  1018. height: 100%;
  1019. position: absolute;
  1020. padding-left: 200rpx;
  1021. background: #FFFFFF;
  1022. right: 0;
  1023. top: 0;
  1024. z-index: 1000;
  1025. &.show{
  1026. animation: showDelbtn 0s linear both;
  1027. }
  1028. &.none{
  1029. animation: hideDelbtn 0s linear both;
  1030. }
  1031. .btn{
  1032. width: 50%;
  1033. height: 100%;
  1034. line-height: 110rpx;
  1035. font-size: $font-size-28;
  1036. color: #FFFFFF;
  1037. text-align: center;
  1038. float: left;
  1039. }
  1040. .btn.btn-cancel{
  1041. background:#EEC1AB;
  1042. }
  1043. .btn.btn-confirm{
  1044. background:#FF2A2A;
  1045. }
  1046. @keyframes showDelbtn {
  1047. 0% {
  1048. transform: translateX(0);
  1049. }
  1050. 100% {
  1051. transform: translateX(-100%);
  1052. }
  1053. }
  1054. @keyframes hideDelbtn {
  1055. 0% {
  1056. transform: translateX(-100%);
  1057. }
  1058. 100% {
  1059. transform: translateX(0);
  1060. }
  1061. }
  1062. }
  1063. }
  1064. </style>