cart.vue 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. <template>
  2. <view class="container cart clearfix" v-if="hasLogin" :style="{paddingTop:CustomBar+'px'}">
  3. <cu-custom :navbar-data='nvabarData' @navigateBack="hanldNavigateBack"></cu-custom>
  4. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  5. <view class="container-cart-main tui-skeleton">
  6. <view v-if="!isEmpty" class="container-cart">
  7. <scroll-view class="cart-content" scroll-y @scrolltolower="toLower">
  8. <view class="goods-list">
  9. <view v-for="(item, index) in goodsList" :key="index" class="goods-item">
  10. <view class="shoptitle">
  11. <!--选择商店的全部商品"-->
  12. <view class="checkbox-box" @click.stop="checkShop(item)">
  13. <button class="checkbox iconfont"
  14. :class="[item.checked ?'icon-gouxuanl':'icon-weigouxuan']"
  15. :disabled="item.isDisabled && !isshowDelbtn">
  16. </button>
  17. </view>
  18. <view class="text">{{item.name}}</view>
  19. </view>
  20. <view class="productlist">
  21. <view class="goods-pros" v-for="(pros,idx) in item.productsList" :key="idx" >
  22. <view class="goods-pros-t">
  23. <!--选择商品-->
  24. <view class="checkbox-box" @click.stop="ischeck(item,pros,idx)" :class="[pros.validFlag == '3' && !isshowDelbtn ?'disabled' : '']">
  25. <button class="checkbox iconfont"
  26. :disabled="pros.validFlag == '3' && !isshowDelbtn"
  27. :class="[pros.productsChecked ?'icon-gouxuanl':'icon-weigouxuan']">
  28. </button>
  29. </view>
  30. <view class="pros-img" @click.stop="navToListPage(pros.productID)" ><image :src="pros.mainImage ? pros.mainImage:''" alt="" /></view>
  31. <view class="pros-product">
  32. <view class="producttitle" @click.stop="navToListPage(pros.productID)" >
  33. <text v-if="pros.validFlag == '3'" class="no-text">商品已下架</text>{{pros.name}}
  34. </view>
  35. <view class="productspec">规格:{{pros.unit ? pros.unit : ''}}</view>
  36. <view class="productprice">
  37. <!--使用过滤器对总价改变-->
  38. <view class="price" :class="[pros.validFlag == '3' ?'disabled' : '']">
  39. <text :class="[pros.validFlag == '3' ?'disabled' : 'money-sign']">¥</text>
  40. {{pros.retailPrice?pros.retailPrice.toFixed(2):''}}
  41. </view>
  42. <view class="count" v-if="pros.validFlag == '2'" :class="[isshowDelbtn ? 'none':'show']">
  43. <view class="number-box">
  44. <view class="iconfont icon-jianhao" :class="[pros.validFlag == '3'?'disabled':'']" @click="changeCountSub(item,pros)"></view>
  45. <input class="btn-input" type="number" maxlength='4' v-model="pros.productCount" @blur="changeNnmber($event,item,pros)">
  46. <view class="iconfont icon-jiahao" :class="[pros.validFlag == '3'?'disabled':'']" @click="changeCountAdd(item,pros)"></view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="goods-pros-b" :class="[isshowDelbtn ? 'none':'show']" >
  55. <view class="sum">合计:<text class="money"><text class="money-sign">¥</text>{{item.totalPrice.toFixed(2)}}</text></view>
  56. </view>
  57. </view>
  58. </view>
  59. <!--加载loadding-->
  60. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  61. <tui-nomore :visible="!pullUpOn" bgcolor="#F7F7F7" :text='nomoreText'></tui-nomore>
  62. <!--加载loadding-->
  63. </scroll-view>
  64. <!-- 脚部菜单 -->
  65. <view class="footer">
  66. <view class="footer-le">
  67. <view class="foot-check checkbox-box" @tap.stop="checkAll()">
  68. <button class="checkbox iconfont" :class="[isCheckAll?'icon-gouxuan':'icon-weigouxuan']"></button>
  69. <view class="text">全选</view>
  70. </view>
  71. <view class="foot-check-delbtn">
  72. <button class="delBtn" @tap.stop="showDelManager">删除</button>
  73. </view>
  74. <view class="sum">总价:<text class="money-sign">¥</text><text class="money">{{allPrice.toFixed(2)}}</text></view>
  75. </view>
  76. <view v-if="!isshowDelbtn" class="footer-ri" >
  77. <view class="btn" @tap="toConfirmation">去结算({{allCount}})</view>
  78. </view>
  79. <view v-else class="footer-del">
  80. <view class="btn btn-cancel" @tap.stop="hideDelManage">取消</view>
  81. <view class="btn btn-confirm" @tap.stop="deleteList">删除</view>
  82. </view>
  83. </view>
  84. </view>
  85. <view v-if="isEmpty" class="cart-content empty">
  86. <view class="empty-container">
  87. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  88. <text class="error-text">购物车空空如也,快去商城逛逛吧~</text>
  89. <view class="login-btn" @click="goIndex">去商城</view>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 透明模态层 -->
  94. <modal-layer v-if='modallayer'></modal-layer>
  95. </view>
  96. </template>
  97. <script>
  98. import authorize from '@/common/config/authorize.js'
  99. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  100. import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
  101. import tuiNomore from "@/components/tui-components/nomore/nomore"
  102. import modalLayer from "@/components/modal-layer"
  103. import { mapState,mapMutations } from 'vuex';
  104. import { queryShoppingCartList,shoppingCartUpdate,shoppingCartDelete } from "@/api/cart.js"
  105. export default{
  106. components:{
  107. tuiSkeleton,
  108. tuiLoadmore,
  109. tuiNomore,
  110. modalLayer
  111. },
  112. data(){
  113. return{
  114. nvabarData: {//顶部自定义导航
  115. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  116. showSearch: 0,
  117. title: '购物车', // 导航栏 中间的标题
  118. haveBack:true,
  119. textLeft:this.$store.state.isIphone,
  120. },
  121. CustomBar:this.CustomBar,// 顶部导航栏高度
  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. hanldNavigateBack(){
  579. console.log(this.pathType)
  580. switch(this.pathType){
  581. case 'product':
  582. this.$api.navigateTo(`/pages/goods/product?id=${this.pathProductID}`)
  583. break;
  584. case 'buyagain':
  585. this.$api.navigateTo('/pages/user/regularPurchase/regularPurchase')
  586. break;
  587. }
  588. }
  589. },
  590. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  591. goodsList:{
  592. deep:true,
  593. handler(val,oldval){
  594. this.totalPeice()
  595. this.totalCount()
  596. }
  597. }
  598. },
  599. onReachBottom() {
  600. if(this.hasNextPage){
  601. this.loadding = true
  602. this.pullUpOn = true
  603. this.getOnReachBottomData()
  604. }
  605. },
  606. onPullDownRefresh() {//下拉刷新
  607. this.initGetCartGoodsList()
  608. uni.stopPullDownRefresh()
  609. },
  610. onShow(){
  611. if(this.hasLogin){
  612. this.initData()
  613. }else{
  614. this.initLogin()
  615. }
  616. },
  617. }
  618. </script>
  619. <style lang="scss">
  620. page{
  621. background: #f7f7f7;
  622. }
  623. .cart-content{
  624. position: relative;
  625. padding-bottom:74rpx;
  626. }
  627. .container-cart-main.none{
  628. display: none;
  629. }
  630. .container-cart-main.show{
  631. display: block;
  632. }
  633. .cart-content.empty.none{
  634. display: none;
  635. }
  636. .cart-content.empty.show{
  637. display: block;
  638. }
  639. .container-cart.show{
  640. display: block;
  641. }
  642. .container-cart.none{
  643. display: none;
  644. }
  645. .empty-container.none{
  646. display: none;
  647. }
  648. .empty-container.show{
  649. display: flex;
  650. }
  651. .checkbox-box{
  652. display: flex;
  653. align-items: center;
  654. .checkbox{
  655. display: flex;
  656. margin: 0;
  657. padding: 0;
  658. display: flex;
  659. flex-direction: column;
  660. align-items: center;
  661. box-sizing: border-box;
  662. text-align: center;
  663. text-decoration: none;
  664. border-radius: 0;
  665. -webkit-tap-highlight-color: transparent;
  666. overflow: hidden;
  667. background-color:#FFFFFF;
  668. font-size: 36rpx;
  669. color:$color-system;
  670. }
  671. &.disabled{
  672. .checkbox{
  673. color:#999999
  674. }
  675. }
  676. .text{
  677. font-size: $font-size-24;
  678. margin-left: 10rpx;
  679. }
  680. }
  681. .goods-list{
  682. width: 100%;
  683. height: auto;
  684. border-top: 1px solid #EBEBEB;
  685. background-color: #F7F7F7;
  686. .goods-item{
  687. width: 702rpx;
  688. padding: 0 24rpx;
  689. background: #FFFFFF;
  690. margin-bottom: 24rpx;
  691. }
  692. .shoptitle{
  693. display: flex;
  694. align-items: center;
  695. height: 80rpx;
  696. // border-bottom: 1px solid #EBEBEB;
  697. line-height: 80rpx;
  698. .checkbox-box{
  699. padding: 10rpx;
  700. }
  701. .text{
  702. margin-left: 37rpx;
  703. font-size: $font-size-28;
  704. color: $text-color;
  705. text-align: left;
  706. font-weight: bold;
  707. }
  708. }
  709. .goods-pros{
  710. width: 100%;
  711. height: auto;
  712. }
  713. .goods-pros-t{
  714. display: flex;
  715. align-items: center;
  716. width: 100%;
  717. height: 217rpx;
  718. padding:0 0 26rpx 0;
  719. .checkbox-box{
  720. padding: 10rpx;
  721. }
  722. .pros-img{
  723. width: 210rpx;
  724. height: 100%;
  725. border-radius: 10rpx;
  726. margin:0 26rpx 0 38rpx;
  727. border:1px solid #f3f3f3;
  728. image{
  729. width: 100%;
  730. height: 100%;
  731. border-radius: 10rpx;
  732. }
  733. }
  734. }
  735. .goods-pros-b{
  736. width:622rpx;
  737. margin-left: 84rpx;
  738. height: 40rpx;
  739. padding:0 0 26rpx 0;
  740. // border-top: 1px solid #EBEBEB;
  741. &.show{
  742. display: block;
  743. }
  744. &.none{
  745. display: none;
  746. }
  747. .sum{
  748. font-size: $font-size-28;
  749. line-height: 40rpx;
  750. color: $text-color;
  751. display: flex;
  752. justify-content: flex-end;
  753. .money{
  754. color: #FF2A2A;
  755. font-size: $font-size-28;
  756. }
  757. .money-sign{
  758. font-size: $font-size-24;
  759. color: #FF2A2A;
  760. }
  761. }
  762. }
  763. .pros-product{
  764. width: 386rpx;
  765. height: 100%;
  766. line-height: 36rpx;
  767. font-size: $font-size-26;
  768. position: relative;
  769. .producttitle{
  770. width: 100%;
  771. display: inline-block;
  772. height: auto;
  773. text-overflow:ellipsis;
  774. display: -webkit-box;
  775. word-break: break-all;
  776. -webkit-box-orient: vertical;
  777. -webkit-line-clamp: 2;
  778. overflow: hidden;
  779. margin-bottom: 8rpx;
  780. .no-text{
  781. display: inline-block;
  782. height:36rpx;
  783. padding: 0 12rpx;
  784. line-height: 36rpx;
  785. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  786. border-radius:18rpx;
  787. text-align: center;
  788. color: #FFFFFF;
  789. font-size: $font-size-24;
  790. margin-right: 24rpx;
  791. }
  792. }
  793. .productspec{
  794. height: 36rpx;
  795. color: #999999;
  796. }
  797. .productprice{
  798. height: 48rpx;
  799. position: absolute;
  800. width: 100%;
  801. bottom: 0;
  802. .price{
  803. line-height: 48rpx;
  804. font-size: $font-size-28;
  805. width: 48%;
  806. color: #FF2A2A;
  807. float: left;
  808. &.disabled{
  809. color: #999999;
  810. }
  811. .money-sign{
  812. font-size: $font-size-24;
  813. color: #FF2A2A;
  814. }
  815. }
  816. .count{
  817. height: 100%;
  818. float: right;
  819. position: relative;
  820. &.show{
  821. display: block;
  822. }
  823. &.none{
  824. display: none;
  825. }
  826. .number-box{
  827. display: flex;
  828. justify-content: center;
  829. align-items: center;
  830. .iconfont{
  831. font-size: $font-size-24;
  832. padding:0 20rpx;
  833. color: $text-color;
  834. text-align: center;
  835. line-height: 48rpx;
  836. font-weight: bold;
  837. }
  838. .btn-input{
  839. width: 62rpx;
  840. height: 48rpx;
  841. line-height: 48rpx;
  842. background: #F8F8F8;
  843. border-radius: 4rpx;
  844. text-align: center;
  845. font-size: $font-size-24;
  846. }
  847. }
  848. .uni-numbox{
  849. position: absolute;
  850. left: 45rpx;
  851. bottom: 0;
  852. .uni-numbox-minus, .uni-numbox-plus{
  853. width: 50rpx;
  854. line-height: 40rpx;
  855. }
  856. .uni-numbox-value {
  857. font-size: $font-size-28;
  858. width: 60rpx;
  859. }
  860. }
  861. }
  862. }
  863. }
  864. }
  865. .footer{
  866. width: 100%;
  867. background-color: #FFFFFF;
  868. height: 110rpx;
  869. position: fixed;
  870. bottom: 0rpx;
  871. z-index: 10;
  872. .footer-le{
  873. width: 490rpx;
  874. height: 100%;
  875. padding:0 30rpx;
  876. float: left;
  877. .text{
  878. font-weight: bold;
  879. }
  880. .foot-check{
  881. width: 100rpx;
  882. float: left;
  883. line-height: 110rpx;
  884. font-size: $font-size-24;
  885. .checkbox{
  886. width: 40rpx;
  887. text-align: center;
  888. }
  889. .text{
  890. width: 60rpx;
  891. float: right;
  892. }
  893. }
  894. .foot-check-delbtn{
  895. float: left;
  896. .delBtn{
  897. margin: 0;
  898. padding: 0;
  899. display: flex;
  900. flex-direction: column;
  901. align-items: center;
  902. box-sizing: border-box;
  903. font-size: $font-size-24;
  904. text-align: center;
  905. text-decoration: none;
  906. border-radius: 0;
  907. -webkit-tap-highlight-color: transparent;
  908. overflow: hidden;
  909. background-color:#FFFFFF;
  910. color: #FF2A2A;
  911. padding: 0 24rpx;
  912. display: flex;
  913. justify-content: center;
  914. align-items: center;
  915. line-height: 110rpx;
  916. font-weight: bold;
  917. &.none{
  918. display: none;
  919. }
  920. }
  921. }
  922. .sum{
  923. font-size: $font-size-28;
  924. line-height: 110rpx;
  925. color: $text-color;
  926. display: flex;
  927. justify-content: flex-end;
  928. .money{
  929. color: #FF2A2A;
  930. }
  931. .money-sign{
  932. font-size: $font-size-24;
  933. color: #FF2A2A;
  934. }
  935. }
  936. }
  937. .footer-ri{
  938. width: 200rpx;
  939. height: 100%;
  940. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  941. float: right;
  942. display: flex;
  943. justify-content: space-between;
  944. align-items: center;
  945. z-index: 999;
  946. &.none{
  947. display: none;
  948. }
  949. .btn{
  950. width: 200rpx;
  951. height: 100%;
  952. font-size: $font-size-28;
  953. line-height: 110rpx;
  954. color: #FFFFFF;
  955. display: flex;
  956. justify-content: center;
  957. align-items: center;
  958. }
  959. }
  960. .footer-del{
  961. width: 400rpx;
  962. height: 100%;
  963. position: absolute;
  964. padding-left: 200rpx;
  965. background: #FFFFFF;
  966. right: 0;
  967. top: 0;
  968. z-index: 1000;
  969. &.show{
  970. animation: showDelbtn 0s linear both;
  971. }
  972. &.none{
  973. animation: hideDelbtn 0s linear both;
  974. }
  975. .btn{
  976. width: 50%;
  977. height: 100%;
  978. line-height: 110rpx;
  979. font-size: $font-size-28;
  980. color: #FFFFFF;
  981. text-align: center;
  982. float: left;
  983. }
  984. .btn.btn-cancel{
  985. background:#EEC1AB;
  986. }
  987. .btn.btn-confirm{
  988. background:#FF2A2A;
  989. }
  990. @keyframes showDelbtn {
  991. 0% {
  992. transform: translateX(0);
  993. }
  994. 100% {
  995. transform: translateX(-100%);
  996. }
  997. }
  998. @keyframes hideDelbtn {
  999. 0% {
  1000. transform: translateX(-100%);
  1001. }
  1002. 100% {
  1003. transform: translateX(0);
  1004. }
  1005. }
  1006. }
  1007. }
  1008. </style>