cart.vue 27 KB

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