cart.vue 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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. if(pros.productCount>=pros.stock){
  420. pros.productCount= pros.stock
  421. this.isStock =true
  422. return
  423. }else{
  424. pros.productCount++
  425. this.isStock =false
  426. }
  427. this.updateShoppogNum(pros)
  428. this.totalShopPeice();
  429. },
  430. changeCountSub(item,pros){//商品数量减减
  431. if(pros.productCount<=pros.minBuyNumber){
  432. pros.productCount= pros.minBuyNumber
  433. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  434. return
  435. }else{
  436. pros.productCount--
  437. }
  438. this.updateShoppogNum(pros)
  439. this.totalShopPeice();
  440. },
  441. changeNnmber(e,item,pros){
  442. let _value = e.detail.value;
  443. if(!this.$api.isNumber(_value)){
  444. pros.productCount = pros.minBuyNumber
  445. }else if(_value < pros.minBuyNumber){
  446. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  447. pros.productCount = pros.minBuyNumber
  448. }else{
  449. pros.productCount = e.detail.value
  450. }
  451. this.updateShoppogNum(pros)
  452. this.totalShopPeice();
  453. },
  454. updateShoppogNum(pros){//加减购物车商品更新到后台
  455. this.$api.get('/shopping/update',
  456. {
  457. userID:this.userID,
  458. productID:pros.id,
  459. productCount:pros.productCount
  460. },
  461. response =>{
  462. if(response.code ==='1'){
  463. // console.log(response)
  464. this.isShowDelModal = false
  465. this.isshowDelbtn = false;
  466. this.initGetCartGoodsList();
  467. }
  468. }
  469. )
  470. },
  471. //跳转确认订单页面
  472. toConfirmation(){
  473. let setGoodsList=[];
  474. this.goodsList.forEach(res=>{
  475. let products = res.productsList
  476. products.forEach(pros=>{
  477. if(pros.productsChecked){
  478. setGoodsList.push(pros.id)
  479. }
  480. })
  481. })
  482. if(setGoodsList == ''){
  483. this.$util.msg("请先选择结算商品~",2000);
  484. return
  485. }else{
  486. /**
  487. * @获取勾选的商品ID拼接字符串逗号隔开,最后一个逗号去掉
  488. * @获取勾选的商品分类ID拼接字符串格式逗号隔开,最后一个逗号去掉
  489. */
  490. let productID = '';
  491. let classifyID ='';
  492. this.goodsList.forEach(el=>{
  493. el.productsList.forEach(pros=>{
  494. if(pros.productsChecked){
  495. productID += pros.id+','
  496. classifyID += pros.classifyID+','
  497. }
  498. })
  499. })
  500. let CartPramsData={
  501. allPrice:this.allPrice,
  502. allCount:this.allCount,
  503. id:productID.substring(0,productID.lastIndexOf(',')),
  504. productCount:'',
  505. classifyID:classifyID.substring(0,classifyID.lastIndexOf(',')),
  506. }
  507. this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({data:CartPramsData})}`)
  508. }
  509. },
  510. setOrderGoods(){//本地获取勾选商品信息***暂时丢弃***
  511. let setGoodData = {}
  512. let prosPrice =0;
  513. let prosCount =0;
  514. let goodsArr = this.goodsList.map(el => {
  515. el.productsList = el.productsList.filter(item => item.productsChecked)
  516. prosPrice=el.productsList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  517. el.productsList.forEach(pros=>{
  518. el.totalCount += pros.productCount;
  519. })
  520. el.totalPrice = prosPrice
  521. return el
  522. }).filter(el => el.productsList && el.productsList.length !==0);
  523. setGoodData = {
  524. allPrice:this.allPrice,
  525. allCount:this.allCount,
  526. goodList:goodsArr
  527. }
  528. return setGoodData
  529. },
  530. // 显示删除商品管理
  531. showDelManager(){
  532. this.isshowDelbtn = true;
  533. this.isNnder = true;
  534. if(this.isCheckAll) {
  535. this.updateBothCheckBtn();
  536. } else {
  537. // 失效也被勾选
  538. this.goodsList.forEach(item => {
  539. if(item.checked) {
  540. item.productsList.forEach(pros => {
  541. pros.productsChecked = true;
  542. })
  543. }
  544. })
  545. this.updateCheckAllBtn();
  546. }
  547. },
  548. hideDelManage(){
  549. this.isshowDelbtn = false;
  550. if(this.isCheckAll) {
  551. this.updateBothCheckBtn();
  552. } else {
  553. // 失效商品取消勾选
  554. this.goodsList.forEach(item => {
  555. if(item.isDisabled) {
  556. item.checked = false;
  557. }
  558. item.productsList.forEach(pros => {
  559. if(pros.validFlag == 2) {
  560. pros.productsChecked = false;
  561. }
  562. })
  563. })
  564. this.updateCheckAllBtn();
  565. }
  566. },
  567. // 删除商品
  568. deleteList(){
  569. this.delGoodsList=[];
  570. this.goodsList.forEach(delitem=>{
  571. let products = delitem.productsList
  572. products.forEach(pros=>{
  573. if(pros.productsChecked){
  574. this.delGoodsList += pros.id+','
  575. }
  576. })
  577. })
  578. // console.log(this.delGoodsList);
  579. if(this.delGoodsList.length == 0){
  580. this.$util.msg("请选择要删除的商品~",2000);
  581. return
  582. }else{
  583. this.isShowDelModal = true
  584. }
  585. },
  586. deleteCart(data){//删除购物车商品
  587. let self = this;
  588. this.$api.get('/shopping/delete',
  589. {
  590. userID:this.userID,
  591. productIDs:this.delGoodsList
  592. },
  593. response =>{
  594. if(response.code ==='1'){
  595. // console.log(response)
  596. this.$util.msg(response.msg,2000);
  597. this.isShowDelModal = false
  598. this.isshowDelbtn = false;
  599. setTimeout(function(){
  600. self.initGetCartGoodsList();
  601. },2000)
  602. }else{
  603. this.$util.msg(response.msg,3000);
  604. setTimeout(function(){
  605. uni.switchTab({
  606. url:'/pages/tabBar/home/home'
  607. })
  608. },1000)
  609. }
  610. }
  611. )
  612. },
  613. goIndex(){
  614. uni.switchTab({
  615. url: '/pages/tabBar/home/home'
  616. });
  617. },
  618. goNavto(url){
  619. uni.navigateTo ({
  620. url
  621. })
  622. },
  623. navToListPage(id){
  624. this.isModallayer = true;
  625. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  626. }
  627. },
  628. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  629. goodsList:{
  630. deep:true,
  631. handler(val,oldval){
  632. this.totalPeice()
  633. this.totalCount()
  634. }
  635. }
  636. },
  637. onReachBottom() {
  638. if(this.hasNextPage){
  639. this.loadding = true
  640. this.pullUpOn = true
  641. this.getOnReachBottomData()
  642. }
  643. },
  644. onPullDownRefresh() {//下拉刷新
  645. this.initGetCartGoodsList()
  646. uni.stopPullDownRefresh()
  647. },
  648. onShow(){
  649. this.$api.loginStatus().then((resolveData) => {
  650. if(resolveData){
  651. this.initData()
  652. }else{
  653. this.initLogin()
  654. }
  655. });
  656. },
  657. }
  658. </script>
  659. <style lang="scss">
  660. page{
  661. background: #f7f7f7;
  662. }
  663. .cart-content{
  664. position: relative;
  665. padding-bottom:74rpx;
  666. }
  667. .container-cart-main.none{
  668. display: none;
  669. }
  670. .container-cart-main.show{
  671. display: block;
  672. }
  673. .cart-content.empty.none{
  674. display: none;
  675. }
  676. .cart-content.empty.show{
  677. display: block;
  678. }
  679. .container-cart.show{
  680. display: block;
  681. }
  682. .container-cart.none{
  683. display: none;
  684. }
  685. .empty-container.none{
  686. display: none;
  687. }
  688. .empty-container.show{
  689. display: flex;
  690. }
  691. .checkbox-box{
  692. display: flex;
  693. align-items: center;
  694. .checkbox{
  695. display: flex;
  696. margin: 0;
  697. padding: 0;
  698. display: flex;
  699. flex-direction: column;
  700. align-items: center;
  701. box-sizing: border-box;
  702. text-align: center;
  703. text-decoration: none;
  704. border-radius: 0;
  705. -webkit-tap-highlight-color: transparent;
  706. overflow: hidden;
  707. background-color:#FFFFFF;
  708. font-size: 36rpx;
  709. color:#E15616;
  710. }
  711. &.disabled{
  712. .checkbox{
  713. color:#999999
  714. }
  715. }
  716. .text{
  717. font-size: $font-size-sm;
  718. margin-left: 10rpx;
  719. }
  720. }
  721. .goods-list{
  722. width: 100%;
  723. height: auto;
  724. border-top: 1px solid #EBEBEB;
  725. background-color: #F7F7F7;
  726. .goods-item{
  727. width: 702rpx;
  728. padding: 0 24rpx;
  729. background: #FFFFFF;
  730. margin-bottom: 24rpx;
  731. }
  732. .shoptitle{
  733. display: flex;
  734. align-items: center;
  735. height: 80rpx;
  736. // border-bottom: 1px solid #EBEBEB;
  737. line-height: 80rpx;
  738. .checkbox-box{
  739. margin-left: 18rpx;
  740. }
  741. .text{
  742. margin-left: 37rpx;
  743. font-size: $font-size-base;
  744. color: $text-color;
  745. text-align: left;
  746. font-weight: bold;
  747. }
  748. }
  749. .goods-pros{
  750. width: 100%;
  751. height: auto;
  752. }
  753. .goods-pros-t{
  754. display: flex;
  755. align-items: center;
  756. width: 100%;
  757. height: 217rpx;
  758. padding:0 0 26rpx 0;
  759. .checkbox-box{
  760. margin-left: 22rpx;
  761. }
  762. .pros-img{
  763. width: 210rpx;
  764. height: 100%;
  765. border-radius: 10rpx;
  766. margin:0 26rpx 0 38rpx;
  767. border:1px solid #f3f3f3;
  768. image{
  769. width: 100%;
  770. height: 100%;
  771. border-radius: 10rpx;
  772. }
  773. }
  774. }
  775. .goods-pros-b{
  776. width:622rpx;
  777. margin-left: 84rpx;
  778. height: 40rpx;
  779. padding:0 0 26rpx 0;
  780. // border-top: 1px solid #EBEBEB;
  781. &.show{
  782. display: block;
  783. }
  784. &.none{
  785. display: none;
  786. }
  787. .sum{
  788. font-size: $font-size-base;
  789. line-height: 40rpx;
  790. color: $text-color;
  791. display: flex;
  792. justify-content: flex-end;
  793. .money{
  794. color: #FF2A2A;
  795. font-size: $font-size-base;
  796. }
  797. .money-sign{
  798. font-size: $font-size-sm;
  799. color: #FF2A2A;
  800. }
  801. }
  802. }
  803. .pros-product{
  804. width: 386rpx;
  805. height: 100%;
  806. line-height: 36rpx;
  807. font-size: $font-size-sb;
  808. position: relative;
  809. .producttitle{
  810. width: 100%;
  811. display: inline-block;
  812. height: auto;
  813. text-overflow:ellipsis;
  814. display: -webkit-box;
  815. word-break: break-all;
  816. -webkit-box-orient: vertical;
  817. -webkit-line-clamp: 2;
  818. overflow: hidden;
  819. margin-bottom: 8rpx;
  820. .no-text{
  821. display: inline-block;
  822. height:36rpx;
  823. padding: 0 12rpx;
  824. line-height: 36rpx;
  825. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  826. border-radius:18rpx;
  827. text-align: center;
  828. color: #FFFFFF;
  829. font-size: $font-size-sm;
  830. margin-right: 24rpx;
  831. }
  832. }
  833. .productspec{
  834. height: 36rpx;
  835. color: #999999;
  836. }
  837. .productprice{
  838. height: 48rpx;
  839. position: absolute;
  840. width: 100%;
  841. bottom: 0;
  842. .price{
  843. line-height: 48rpx;
  844. font-size: $font-size-base;
  845. width: 48%;
  846. color: #FF2A2A;
  847. float: left;
  848. &.disabled{
  849. color: #999999;
  850. }
  851. .money-sign{
  852. font-size: $font-size-sm;
  853. color: #FF2A2A;
  854. }
  855. }
  856. .count{
  857. height: 100%;
  858. float: right;
  859. position: relative;
  860. &.show{
  861. display: block;
  862. }
  863. &.none{
  864. display: none;
  865. }
  866. .number-box{
  867. display: flex;
  868. justify-content: center;
  869. align-items: center;
  870. .iconfont{
  871. font-size: $font-size-sm;
  872. padding:0 20rpx;
  873. color: $text-color;
  874. text-align: center;
  875. line-height: 48rpx;
  876. font-weight: bold;
  877. }
  878. .btn-input{
  879. width: 62rpx;
  880. height: 48rpx;
  881. line-height: 48rpx;
  882. background: #F8F8F8;
  883. border-radius: 4rpx;
  884. text-align: center;
  885. font-size: $font-size-sm;
  886. }
  887. }
  888. .uni-numbox{
  889. position: absolute;
  890. left: 45rpx;
  891. bottom: 0;
  892. .uni-numbox-minus, .uni-numbox-plus{
  893. width: 50rpx;
  894. line-height: 40rpx;
  895. }
  896. .uni-numbox-value {
  897. font-size: $font-size-base;
  898. width: 60rpx;
  899. }
  900. }
  901. }
  902. }
  903. }
  904. }
  905. .footer{
  906. width: 100%;
  907. background-color: #FFFFFF;
  908. height: 110rpx;
  909. position: fixed;
  910. bottom: 0rpx;
  911. z-index: 10;
  912. .footer-le{
  913. width: 490rpx;
  914. height: 100%;
  915. padding:0 30rpx;
  916. float: left;
  917. .text{
  918. font-weight: bold;
  919. }
  920. .foot-check{
  921. width: 100rpx;
  922. float: left;
  923. line-height: 110rpx;
  924. font-size: $font-size-sm;
  925. .checkbox{
  926. width: 40rpx;
  927. text-align: center;
  928. }
  929. .text{
  930. width: 60rpx;
  931. float: right;
  932. }
  933. }
  934. .foot-check-delbtn{
  935. float: left;
  936. .delBtn{
  937. margin: 0;
  938. padding: 0;
  939. display: flex;
  940. flex-direction: column;
  941. align-items: center;
  942. box-sizing: border-box;
  943. font-size: $font-size-sm;
  944. text-align: center;
  945. text-decoration: none;
  946. border-radius: 0;
  947. -webkit-tap-highlight-color: transparent;
  948. overflow: hidden;
  949. background-color:#FFFFFF;
  950. color: #FF2A2A;
  951. padding: 0 24rpx;
  952. display: flex;
  953. justify-content: center;
  954. align-items: center;
  955. line-height: 110rpx;
  956. font-weight: bold;
  957. &.none{
  958. display: none;
  959. }
  960. }
  961. }
  962. .sum{
  963. font-size: $font-size-base;
  964. line-height: 110rpx;
  965. color: $text-color;
  966. display: flex;
  967. justify-content: flex-end;
  968. .money{
  969. color: #FF2A2A;
  970. }
  971. .money-sign{
  972. font-size: $font-size-sm;
  973. color: #FF2A2A;
  974. }
  975. }
  976. }
  977. .footer-ri{
  978. width: 200rpx;
  979. height: 100%;
  980. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  981. float: right;
  982. display: flex;
  983. justify-content: space-between;
  984. align-items: center;
  985. z-index: 999;
  986. &.none{
  987. display: none;
  988. }
  989. .btn{
  990. width: 200rpx;
  991. height: 100%;
  992. font-size: $font-size-base;
  993. line-height: 110rpx;
  994. color: #FFFFFF;
  995. display: flex;
  996. justify-content: center;
  997. align-items: center;
  998. }
  999. }
  1000. .footer-del{
  1001. width: 400rpx;
  1002. height: 100%;
  1003. position: absolute;
  1004. padding-left: 200rpx;
  1005. background: #FFFFFF;
  1006. right: 0;
  1007. top: 0;
  1008. z-index: 1000;
  1009. &.show{
  1010. animation: showDelbtn 0s linear both;
  1011. }
  1012. &.none{
  1013. animation: hideDelbtn 0s linear both;
  1014. }
  1015. .btn{
  1016. width: 50%;
  1017. height: 100%;
  1018. line-height: 110rpx;
  1019. font-size: $font-size-base;
  1020. color: #FFFFFF;
  1021. text-align: center;
  1022. float: left;
  1023. }
  1024. .btn.btn-cancel{
  1025. background: #000000;
  1026. }
  1027. .btn.btn-confirm{
  1028. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  1029. }
  1030. @keyframes showDelbtn {
  1031. 0% {
  1032. transform: translateX(0);
  1033. }
  1034. 100% {
  1035. transform: translateX(-100%);
  1036. }
  1037. }
  1038. @keyframes hideDelbtn {
  1039. 0% {
  1040. transform: translateX(-100%);
  1041. }
  1042. 100% {
  1043. transform: translateX(0);
  1044. }
  1045. }
  1046. }
  1047. }
  1048. </style>