index.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  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" :style="{paddingTop:isshowDelbtn ? '0rpx':'80rpx'}">
  5. <view class="foot-check-delbtn" v-if="!isshowDelbtn && goodsList.length>0">
  6. <view class="foot-text">共<text>{{kindCount}}</text>件商品</view>
  7. <view class="delBtn" @tap.stop="showDelManager">删除</view>
  8. </view>
  9. <view v-if="!isEmpty" class="container-cart">
  10. <view class="cart-content" :style="{paddingBottom :isIphoneX ? '130rpx' : '100rpx'}">
  11. <view class="goods-list">
  12. <view v-for="(item, index) in goodsList" :key="index" class="goods-item clearfix">
  13. <view class="shoptitle">
  14. <!--选择商店的全部商品"-->
  15. <view class="checkbox-box" @click.stop="checkShop(item)">
  16. <view class="checkbox iconfont" :class="[item.checked ?'icon-xuanze':'icon-weixuanze']"></view>
  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.productList" :key="idx" >
  22. <view class="goods-pros-t">
  23. <!--选择商品-->
  24. <view class="checkbox-box" @click.stop="ischeck(item,pros)">
  25. <view class="checkbox iconfont" :class="[pros.productsChecked ? 'icon-xuanze':'icon-weixuanze']"></view>
  26. </view>
  27. <view class="pros-img" @click.stop="navToListPage(pros.productId)" ><image :src="pros.mainImage ? pros.mainImage:''" alt="" /></view>
  28. <view class="pros-product">
  29. <view class="producttitle" @click.stop="navToListPage(pros.productId)" >{{pros.productName}}</view>
  30. <view class="productspec">规格:{{pros.unit ? pros.unit : ''}}</view>
  31. <view class="floor-item-act" v-if="pros.activeStatus == 1">
  32. <view class="tag"@click.stop="clickPopupShow(pros,2)">活动价</view>
  33. </view>
  34. <view class="productprice">
  35. <!--使用过滤器对总价改变-->
  36. <view class="price"><text>¥</text>{{ pros.price | NumFormat }}</view>
  37. <view class="count">
  38. <view class="number-box">
  39. <view class="iconfont icon-jianhao" @click="changeCountSub(item,pros)"></view>
  40. <input class="btn-input" type="number" maxlength='4' v-model="pros.productCount" @blur="changeNnmber($event,item,pros)" @focus="changeInput(pros)">
  41. <view class="iconfont icon-jiahao" @click="changeCountAdd(item,pros)"></view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="goods-pros-b clearfix" :class="[isshowDelbtn ? 'none':'show']" >
  50. <view class="sum-none" v-if="item.reducedPrice>0">
  51. <text class="money-sign">¥</text>
  52. <text class="money">{{ item.totalOriginalPrice | NumFormat }}</text>
  53. <text class="money-reduced">减<text>¥{{ item.reducedPrice | NumFormat}}</text></text>
  54. </view>
  55. <view class="sum">合计:<text class="money"><text class="money-sign">¥</text>{{item.totalPrice | NumFormat}}</text></view>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="failure-list" v-if="failureList.length>0">
  60. <view class="failure-title">
  61. <view class="title-txt">失效商品<text>{{failureList.length}}件</text></view>
  62. <view class="title-btn" @click.stop="deletefailureList"><text class="butto">清空失效商品</text></view>
  63. </view>
  64. <view class="productlist">
  65. <view class="goods-pros" v-for="(failure,failureIdx) in failureList" :key="failureIdx" >
  66. <view class="goods-pros-t" @click.stop="navToListPage(failure)">
  67. <!--选择商品-->
  68. <view class="checkbox-box" @click.stop="ischeckFailure(failure)" v-if="isshowDelbtn">
  69. <button class="checkbox iconfont"
  70. :class="[ failure.productsChecked ? 'icon-xuanze':'icon-weixuanze']">
  71. </button>
  72. </view>
  73. <text class="img-tip">失效</text>
  74. <view class="pros-img">
  75. <image :src="failure.mainImage ? failure.mainImage:''" alt="" />
  76. </view>
  77. <view class="pros-product">
  78. <view class="producttitle">{{failure.name}}</view>
  79. <view class="productspec">规格:{{failure.unit ? failure.unit : ''}}</view>
  80. <view class="productstate">商品已下架</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 脚部菜单 -->
  88. <view class="footer">
  89. <view class="footer-le">
  90. <view class="foot-check checkbox-box" @tap.stop="checkAll()">
  91. <button class="checkbox iconfont" :class="[isCheckAll?'icon-xuanze':'icon-weixuanze']"></button>
  92. <view class="text">全选</view>
  93. </view>
  94. <view class="sum">
  95. <view v-if="!isshowDelbtn" class="sum-price">
  96. 总价:<text class="money-sign">¥</text><text class="money">{{allPrice | NumFormat}}</text>
  97. </view>
  98. </view>
  99. </view>
  100. <view v-if="!isshowDelbtn" class="footer-ri" >
  101. <view class="btn hanld-btn" @tap="toConfirmation">去结算({{allCount}})</view>
  102. </view>
  103. <view v-else class="footer-del">
  104. <view class="btn btn-cancel" @tap.stop="hideDelManage">取消</view>
  105. <view class="btn btn-confirm" @tap.stop="deleteList">删除</view>
  106. </view>
  107. </view>
  108. </view>
  109. <view v-else class="cart-content empty">
  110. <view class="empty-container">
  111. <image class="empty-container-image" :src="StaticUrl+'icon-empty-cart.png'" mode="aspectFit"></image>
  112. <text class="error-text">购物车空空的,快去逛逛吧~</text>
  113. </view>
  114. </view>
  115. </view>
  116. <!-- 操作弹窗 -->
  117. <tui-modal :show="modal" @click="handleClick" @cancel="hideMobel" :content="contentModalText" color="#333" :size="32" shape="circle" :maskClosable="false"></tui-modal>
  118. <!-- 促销活动弹窗 -->
  119. <activi-popup :product="handlerPros" :popupShow="popupShow"></activi-popup>
  120. <!-- 透明模态层 -->
  121. <modal-layer v-if='modallayer'></modal-layer>
  122. </view>
  123. </template>
  124. <script>
  125. import authorize from '@/common/config/authorize.js'
  126. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  127. import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
  128. import tuiNomore from "@/components/tui-components/nomore/nomore"
  129. import activiPopup from "@/components/cm-module/productDetails/cm-activipopu"
  130. import modalLayer from "@/components/modal-layer"
  131. import { mapState,mapMutations } from 'vuex';
  132. export default{
  133. components:{
  134. tuiSkeleton,
  135. tuiLoadmore,
  136. tuiNomore,
  137. activiPopup,
  138. modalLayer
  139. },
  140. data(){
  141. return{
  142. StaticUrl:this.$Static,
  143. CustomBar:this.CustomBar,// 顶部导航栏高度
  144. isIphoneX:this.$store.state.isIphoneX,
  145. userId:'',
  146. popupShow:false,
  147. handlerPros:{},//监听单挑促销商品
  148. failureList:[], //失效商品列表
  149. goodsList:[], //购物车的商品
  150. delGoodsList:'',//要删除的商品
  151. setGoodData:'', //确认订单的商品
  152. isCheckAll:false,//是否全选
  153. kindCount:0,//购物车宝贝数量
  154. allPrice:0,//所有价格
  155. totalOriginalPrice:0,//所有原价价
  156. reducedPrice:0,//满减
  157. allCount:0,//被选中的产品数量
  158. isModallayer:false,
  159. skeletonShow:true,
  160. isshowDelbtn:false,
  161. isDisabled: false, // 供应商/店铺全选是否禁用状态
  162. isEmpty:false,//显示空购物车
  163. scrollHeight: 'auto',
  164. nomoreText: '上拉显示更多',
  165. hasNextPage: false,
  166. loadding: false,
  167. pullUpOn: true,
  168. pullFlag: true,
  169. pageSize: 10,
  170. pageNum: 1,
  171. submitIds:[],
  172. modal:false,
  173. contentModalText:'',
  174. deleteType:0,
  175. }
  176. },
  177. onLoad(){
  178. this.setScrollHeight();
  179. },
  180. computed: {
  181. ...mapState(['hasLogin','userInfo'])
  182. },
  183. filters:{
  184. NumFormat(value) {//处理金额
  185. return Number(value).toFixed(2);
  186. },
  187. totalprice(val,count){//单件商品的价格 × 数量
  188. return (val * count).toFixed(2)
  189. }
  190. },
  191. methods:{
  192. initData(){
  193. this.isModallayer = false //遮罩层 防止多次点击
  194. this.isCheckAll=false//是否全选
  195. this.submitIds = []
  196. this.$api.getStorage().then((resolve) => {
  197. this.userId = resolve.userId ? resolve.userId : 0;
  198. this.InitGetCartGoodsList();
  199. })
  200. },
  201. clickPopupShow(pros,type){
  202. this.popupShow = true;
  203. this.handlerPros = pros;
  204. },
  205. setScrollHeight() {
  206. // 窗口高度-footer高度
  207. const {windowHeight, pixelRatio} = uni.getSystemInfoSync();
  208. setTimeout(()=> {
  209. const query = uni.createSelectorQuery().in(this);
  210. query.selectAll('.footer').boundingClientRect();
  211. query.exec(res => {
  212. this.windowHeight = windowHeight;
  213. if(res[0][0]) {
  214. this.scrollHeight = windowHeight - res[0][0].height;
  215. }
  216. })
  217. }, 500)
  218. },
  219. InitGetCartGoodsList(){//初始化购物车 index:1
  220. this.ProductService.QueryShoppingCartList({userId:this.userId}).then(response =>{
  221. this.skeletonShow = false
  222. let data = response.data
  223. this.kindCount = data.cartQuantity
  224. if( data.shopList.length > 0 || data.products.length > 0){
  225. this.isEmpty =false
  226. }else{
  227. this.isEmpty =true
  228. }
  229. if(data.shopList && data.shopList.length > 0 ){
  230. this.goodsList = data.shopList;
  231. console.log(this.goodsList)
  232. this.totalShopPeice()
  233. } else {
  234. this.goodsList = [];
  235. }
  236. if( data.products && data.products.length > 0){
  237. this.failureList = data.products
  238. } else {
  239. this.failureList = [];
  240. }
  241. }).catch(error =>{
  242. this.$util.msg(error.msg,2000);
  243. })
  244. },
  245. ischeckFailure(failure){
  246. failure.productsChecked = !failure.productsChecked
  247. this.updateCheckAllBtn()
  248. },
  249. ischeck(item,pro){//为未选中的时候改变为true,反之为true
  250. pro.productsChecked = !pro.productsChecked;
  251. if(pro.productsChecked) {
  252. if(!this.submitIds.includes(pro.productID*1)){
  253. this.submitIds.push(pro.productID);
  254. }
  255. } else {
  256. var lent = this.submitIds.indexOf(pro.productID*1);
  257. if(lent >=0 ){
  258. this.submitIds.splice(lent, 1);
  259. }
  260. }
  261. this.updateProductCheckedAllBtn(item);
  262. this.updateCheckAllBtn();
  263. },
  264. updateProductCheckedAllBtn(item) {// 单独每个供应商的勾选判断
  265. let productList = item.productList,
  266. productsCheckedLength = 0,
  267. disabledLength = 0;
  268. if(this.isshowDelbtn) {
  269. productList.forEach(pros => {
  270. if(pros.productsChecked) {
  271. productsCheckedLength++;
  272. }
  273. })
  274. } else {
  275. productList.forEach(pros => {
  276. if(pros.productsChecked) {
  277. productsCheckedLength++;
  278. }
  279. })
  280. }
  281. item.checked = productsCheckedLength === productList.length;
  282. },
  283. updateCheckAllBtn() {// 全选勾选判断
  284. let goodsCheckedLength = 0,
  285. goodsList = this.goodsList,
  286. failureList = this.failureList;
  287. goodsList.forEach(item => {
  288. if(item.checked) {
  289. goodsCheckedLength++;
  290. }
  291. })
  292. failureList.forEach(failureItem=>{
  293. if(failureItem.productsChecked){
  294. goodsCheckedLength++;
  295. }
  296. })
  297. if(this.isshowDelbtn){
  298. this.isCheckAll = goodsCheckedLength === goodsList.length + failureList.length;
  299. }else{
  300. this.isCheckAll = goodsCheckedLength === goodsList.length;
  301. }
  302. },
  303. checkShop(item){//与单选商品类似
  304. item.checked = !item.checked;
  305. this.setProductChecked(item);
  306. this.updateCheckAllBtn();
  307. },
  308. setProductChecked(item) {
  309. item.productList.forEach(pros=>{
  310. if(item.checked) {
  311. pros.productsChecked = true;
  312. if(!this.submitIds.includes(pros.productId*1)){
  313. this.submitIds.push(pros.productId);
  314. }
  315. } else {
  316. pros.productsChecked = false;
  317. var lent = this.submitIds.indexOf(pros.productId*1);
  318. if(lent >=0 ){
  319. this.submitIds.splice(lent, 1);
  320. }
  321. }
  322. })
  323. },
  324. updateBothCheckBtn() {
  325. if(this.isshowDelbtn) {
  326. // 当管理删除按钮出现时,失效的商品可被选择
  327. this.goodsList.forEach((item)=>{
  328. item.checked = this.isCheckAll;
  329. this.setProductChecked(item);
  330. })
  331. //删除按钮 全选包括失效商品勾选
  332. this.failureList.forEach(failureItem=>{
  333. failureItem.productsChecked = this.isCheckAll;
  334. })
  335. } else {
  336. this.goodsList.forEach((item)=>{
  337. item.checked = this.isCheckAll && !item.isDisabled;
  338. this.setProductChecked(item);
  339. })
  340. }
  341. },
  342. checkAll(){//全选方法内调用方法
  343. this.isCheckAll = !this.isCheckAll;
  344. this.updateBothCheckBtn();
  345. },
  346. totalShopPeice(){//每次所属会所下的商品增减重新计算合计价格&减去含有下架的商品
  347. let touchPrice = 0;
  348. let reducedPrice = 0;//商铺合计满减价
  349. this.goodsList.map((item,index)=>{
  350. let _totalPrice = 0;
  351. let _reducedPrice = 0;
  352. let _totalOriginalPrice =0;
  353. item.productList.forEach(pros=>{
  354. let _price = pros.price*pros.productCount
  355. _totalOriginalPrice += pros.price*pros.productCount;
  356. if(pros.promotion && pros.promotion.type != 2 && pros.promotion.mode == 2){
  357. if(_price >= pros.promotion.touchPrice){
  358. _price = _price - pros.promotion.reducedPrice
  359. _reducedPrice += pros.promotion.reducedPrice
  360. }
  361. _totalPrice += _price
  362. }else{
  363. _reducedPrice = 0;
  364. _totalPrice += pros.price*pros.productCount;
  365. }
  366. })
  367. item.reducedPrice = _reducedPrice
  368. item.totalOriginalPrice = _totalOriginalPrice
  369. item.totalPrice = _totalPrice
  370. })
  371. },
  372. totalPeice(){//计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
  373. let totalPrice = 0;
  374. let reducedPrice = 0;
  375. let originalPrice = 0;
  376. this.goodsList.forEach((item,index)=>{
  377. let supplierPrice = 0;
  378. let supplierReducedPrice = 0;
  379. item.totalprice = 0;
  380. item.reducedprice = 0;
  381. item.originalprice = 0;
  382. item.productList.forEach(pros=>{
  383. if(pros.productsChecked){
  384. supplierPrice += pros.price*pros.productCount;
  385. // 单品满减
  386. if(pros.promotion && pros.promotion.type*1===1 && pros.promotion.mode*1===2){
  387. // 单品满减-重新计算供应商总价/满减金额
  388. if(pros.price*pros.productCount >= pros.promotion.touchPrice){
  389. supplierPrice -= pros.promotion.reducedPrice;
  390. supplierReducedPrice += pros.promotion.reducedPrice;
  391. }
  392. }
  393. }
  394. })
  395. item.totalprice = supplierPrice;
  396. item.reducedprice = supplierReducedPrice;
  397. item.originalprice = (supplierPrice+supplierReducedPrice);
  398. totalPrice += item.totalprice;
  399. reducedPrice += item.reducedprice;
  400. originalPrice += item.originalprice;
  401. })
  402. //最后统计商品原价
  403. this.totalOriginalPrice = originalPrice;
  404. //最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
  405. this.reducedPrice = reducedPrice;
  406. //最终合计价格 = 店铺满减合计 + 单品满减 + 正常合计 + 凑单满减
  407. this.allPrice = totalPrice ;
  408. },
  409. totalCount(){//计算总数量
  410. this.allCount = 0
  411. let prosAllCount=0
  412. let validCount = 0
  413. let validList =[];
  414. let productList =[];
  415. this.goodsList.forEach(item=>{
  416. productList = item.productList
  417. productList.forEach(pros=>{
  418. if(pros.productsChecked){
  419. prosAllCount+=parseInt(pros.productCount);
  420. this.allCount = prosAllCount
  421. }
  422. })
  423. })
  424. },
  425. changeCountAdd(item,pros){//商品数量加加
  426. pros.productCount++
  427. this.processActivityPrice(pros)
  428. this.updateShoppogNum(pros)
  429. this.totalShopPeice();
  430. },
  431. changeCountSub(item,pros){//商品数量减减
  432. if(pros.productCount<=1){
  433. pros.productCount= 1
  434. this.$util.msg(`购买数量不能少于1`,2000);
  435. return
  436. }else{
  437. pros.productCount--
  438. this.processActivityPrice(pros)
  439. }
  440. this.updateShoppogNum(pros)
  441. this.totalShopPeice();
  442. },
  443. changeInput(pros){//输入商品数量更新
  444. },
  445. changeNnmber(e,item,pros){//输入商品数量更新
  446. let _value = Number(e.detail.value);
  447. if(!this.$api.isNumber(_value)){
  448. pros.productCount = 1
  449. }else if(_value <= 1){
  450. this.$util.msg(`购买数量不能少于1`,2000);
  451. pros.productCount = 1
  452. }else{
  453. pros.productCount = e.detail.value
  454. this.processActivityPrice(pros)
  455. }
  456. this.updateShoppogNum(pros)
  457. this.totalShopPeice();
  458. },
  459. processActivityPrice(pros){//单独处理活动价格和阶梯价格
  460. if(pros.activeStatus == 1){
  461. pros.ladderList.forEach((item,index)=>{
  462. if(pros.productCount>=item.buyNum){
  463. pros.price = item.buyPrice
  464. }
  465. })
  466. }else{
  467. pros.price = pros.price
  468. }
  469. },
  470. updateShoppogNum(pros){//加减购物车商品更新到后台
  471. this.ProductService.ShoppingCartUpdate(
  472. {
  473. cartId:pros.cartId,
  474. productCount:pros.productCount,
  475. }
  476. )
  477. .then(response =>{
  478. this.isshowDelbtn = false;
  479. this.InitGetCartGoodsList();
  480. })
  481. .catch(error =>{
  482. this.$util.msg(error.msg,2000);
  483. })
  484. },
  485. toConfirmation(){//跳转确认订单页面
  486. let setGoodsList=[];
  487. this.goodsList.forEach(res=>{
  488. let products = res.productList
  489. products.forEach(pros=>{
  490. if(pros.productsChecked){
  491. setGoodsList.push(pros.productId)
  492. }
  493. })
  494. })
  495. if(setGoodsList == ''){
  496. this.$util.msg("请先选择结算商品~",2000);
  497. return
  498. }
  499. let cartIds = '';
  500. this.goodsList.forEach(el=>{//获取勾选的商品ID拼接字符串逗号隔开,最后一个逗号去掉
  501. el.productList.forEach(pros=>{
  502. if(pros.productsChecked){
  503. cartIds += pros.cartId+','
  504. }
  505. })
  506. })
  507. let cartPramsData={
  508. allPrice:this.allPrice,
  509. allCount:this.allCount,
  510. cartIds:cartIds.substring(0,cartIds.lastIndexOf(',')),
  511. productCount:''
  512. }
  513. this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({data:cartPramsData})}`)
  514. },
  515. showDelManager(){//显示删除商品管理
  516. this.isshowDelbtn = true;
  517. if(this.isCheckAll) {
  518. this.updateBothCheckBtn();
  519. } else {
  520. this.goodsList.forEach(item => {
  521. if(item.checked) {
  522. item.productList.forEach(pros => {
  523. pros.productsChecked = true;
  524. })
  525. }
  526. })
  527. this.updateCheckAllBtn();
  528. }
  529. // 失效也被勾选
  530. this.failureList.forEach(failureItem => {
  531. if(failureItem.isFailureLayer){
  532. failureItem.isFailureLayer = false
  533. }
  534. })
  535. },
  536. hideDelManage(){//隐藏删除商品管理
  537. this.isshowDelbtn = false;
  538. let isFailureLayer,newFailureList =[];
  539. if(this.isCheckAll) {
  540. this.updateBothCheckBtn();
  541. } else {
  542. // 失效商品取消勾选
  543. this.goodsList.forEach(item => {
  544. if(item.isDisabled) {
  545. item.checked = false;
  546. }
  547. item.productList.forEach(pros => {
  548. if(pros.validFlag == 3) {
  549. pros.productsChecked = false;
  550. }
  551. })
  552. })
  553. this.updateCheckAllBtn();
  554. }
  555. this.failureList.forEach((failure,index) => {
  556. if(failure.failureState == 1 || failure.failureState == 2) {
  557. isFailureLayer = true
  558. }else{
  559. isFailureLayer = false
  560. }
  561. newFailureList.push(Object.assign({},failure,{isFailureLayer:isFailureLayer}))
  562. })
  563. this.failureList = newFailureList;
  564. },
  565. deleteList(){//删除购物车商品
  566. this.delGoodsList=[];
  567. this.goodsList.forEach(delitem=>{
  568. let products = delitem.productList
  569. products.forEach(pros=>{
  570. if(pros.productsChecked){
  571. this.delGoodsList += pros.cartId+','
  572. }
  573. })
  574. })
  575. this.failureList.forEach(failure=>{
  576. if(failure.productsChecked){
  577. this.delGoodsList += failure.cartId+','
  578. }
  579. })
  580. if(this.delGoodsList.length == 0){
  581. this.$util.msg("请选择要删除的商品~",2000);
  582. return
  583. }else{
  584. this.modal = true;
  585. this.contentModalText = '确定删除选中的商品吗?';
  586. this.deleteType = 1
  587. }
  588. },
  589. deletefailureList(){
  590. this.delGoodsList = ''
  591. this.failureList.forEach(failure=>{ this.delGoodsList += failure.cartId+',' })
  592. this.modal = true;
  593. this.contentModalText = '确定清除所有失效商品吗?';
  594. this.deleteType = 2
  595. },
  596. handleClick(e) {//用户操作订单
  597. let index = e.index;
  598. if(index == 1){
  599. this.ProductService.ShoppingCartDelete(
  600. {
  601. cartIds:this.delGoodsList,
  602. }
  603. )
  604. .then(response =>{
  605. this.$util.msg('删除成功',2000);
  606. setTimeout(()=>{
  607. this.isshowDelbtn = false;
  608. this.InitGetCartGoodsList();
  609. },1000)
  610. }).catch(error =>{
  611. this.$util.msg(error.msg,2000)
  612. })
  613. }
  614. this.modal = false;
  615. },
  616. hideMobel(){
  617. this.modal = false;
  618. },
  619. navToListPage(item){
  620. this.isModallayer = true;
  621. this.$api.navigateTo(`/pages/goods/product?productId=${item.productId}`)
  622. },
  623. setHeaderBtnPosi(){
  624. // 获得胶囊按钮位置信息
  625. let headerBtnPosi = uni.getMenuButtonBoundingClientRect();
  626. return headerBtnPosi
  627. },
  628. setSysteminfo(){
  629. let systeminfo;
  630. uni.getSystemInfo({ // 获取设备信息
  631. success: (res) => {
  632. systeminfo = res
  633. },
  634. })
  635. return systeminfo
  636. },
  637. PromotionsFormat(promo){//促销活动类型数据处理
  638. if(promo!=null){
  639. if(promo.type == 1 && promo.mode == 1){
  640. return true
  641. }else{
  642. return false
  643. }
  644. }
  645. return false
  646. }
  647. },
  648. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  649. goodsList:{
  650. deep:true,
  651. handler(val,oldval){
  652. this.totalPeice()
  653. this.totalCount()
  654. }
  655. }
  656. },
  657. onPullDownRefresh() {//下拉刷新
  658. this.InitGetCartGoodsList()
  659. uni.stopPullDownRefresh()
  660. },
  661. onShow(){
  662. if(this.hasLogin){
  663. this.initData()
  664. }else{
  665. this.$api.redirectTo('/pages/login/login')
  666. }
  667. },
  668. }
  669. </script>
  670. <style lang="scss">
  671. page{
  672. background: #f7f7f7;
  673. height: auto;
  674. }
  675. .cart-content{
  676. position: relative;
  677. }
  678. .container-cart-main.none{
  679. display: none;
  680. }
  681. .container-cart-main.show{
  682. display: block;
  683. }
  684. .cart-content.empty.none{
  685. display: none;
  686. }
  687. .cart-content.empty.show{
  688. display: block;
  689. }
  690. .container-cart.show{
  691. display: block;
  692. }
  693. .container-cart.none{
  694. display: none;
  695. }
  696. .empty-container.none{
  697. display: none;
  698. }
  699. .empty-container.show{
  700. display: flex;
  701. }
  702. .foot-check-delbtn{
  703. width: 100%;
  704. height: 80rpx;
  705. position: fixed;
  706. top: 0;
  707. left: 0;
  708. box-sizing: border-box;
  709. padding: 15rpx 24rpx;
  710. background-color: #F7F7F7;
  711. z-index: 990;
  712. .foot-text{
  713. font-size: $font-size-26;
  714. height: 50rpx;
  715. line-height: 50rpx;
  716. color:#666666;
  717. float: left;
  718. padding-left: 10rpx;
  719. text{
  720. margin: 0 6rpx;
  721. }
  722. }
  723. .delBtn{
  724. width: 100rpx;
  725. display: inline-block;
  726. padding: 0 15rpx;
  727. font-size: $font-size-26;
  728. height: 50rpx;
  729. line-height: 50rpx;
  730. border-radius: 30rpx;
  731. background:#FFFFFF;
  732. border: 1px solid #ff457b;
  733. color: #ff457b;
  734. float: right;
  735. text-align: center;
  736. &.none{
  737. display: none;
  738. }
  739. }
  740. }
  741. .checkbox-box{
  742. display: flex;
  743. align-items: center;
  744. .checkbox{
  745. display: flex;
  746. margin: 0;
  747. padding:0 5rpx;
  748. display: flex;
  749. flex-direction: column;
  750. align-items: center;
  751. box-sizing: border-box;
  752. text-align: center;
  753. text-decoration: none;
  754. border-radius: 0;
  755. -webkit-tap-highlight-color: transparent;
  756. overflow: hidden;
  757. background-color:#FFFFFF;
  758. font-size: 36rpx;
  759. color:#999999;
  760. &.icon-xuanze{
  761. color: $color-system;
  762. }
  763. }
  764. &.disabled{
  765. .checkbox{
  766. color:#999999
  767. }
  768. }
  769. .text{
  770. font-size: $font-size-24;
  771. margin-left: 10rpx;
  772. }
  773. }
  774. .goods-list{
  775. width: 100%;
  776. height: auto;
  777. background-color: #F7F7F7;
  778. .goods-item{
  779. width: 702rpx;
  780. padding: 0 24rpx;
  781. background: #FFFFFF;
  782. margin-bottom: 24rpx;
  783. }
  784. .shoptitle{
  785. display: flex;
  786. align-items: center;
  787. height: 80rpx;
  788. line-height: 80rpx;
  789. .checkbox-box{
  790. padding: 10rpx;
  791. }
  792. .text{
  793. width: 450rpx;
  794. display: block;
  795. overflow: hidden;
  796. text-overflow:ellipsis;
  797. white-space: nowrap;
  798. margin-left: 20rpx;
  799. font-size: $font-size-28;
  800. color: $text-color;
  801. text-align: left;
  802. font-weight: bold;
  803. }
  804. }
  805. .goods-pros{
  806. width: 100%;
  807. height: auto;
  808. margin-bottom: 20rpx;
  809. }
  810. .goods-pros-t{
  811. display: flex;
  812. align-items: center;
  813. width: 100%;
  814. height: 210rpx;
  815. padding:0 0 26rpx 0;
  816. .checkbox-box{
  817. padding: 10rpx;
  818. }
  819. .pros-img{
  820. width: 210rpx;
  821. height: 100%;
  822. border-radius: 10rpx;
  823. margin:0 20rpx;
  824. border:1px solid #f3f3f3;
  825. image{
  826. width: 100%;
  827. height: 100%;
  828. border-radius: 10rpx;
  829. }
  830. }
  831. }
  832. .goods-pros-b{
  833. width:100%;
  834. height: auto;
  835. padding:0 0 24rpx 0;
  836. box-sizing: border-box;
  837. &.show{
  838. display: block;
  839. }
  840. &.none{
  841. display: none;
  842. }
  843. .sum-none{
  844. width: 100%;
  845. height: 48rpx;
  846. line-height: 48rpx;
  847. color: $text-color;
  848. float: left;
  849. text-align: right;
  850. .money{
  851. font-size: $font-size-26;
  852. color: #999999;
  853. text-decoration: line-through;
  854. }
  855. .money-sign{
  856. font-size: $font-size-26;
  857. color: #999999;
  858. text-decoration: line-through;
  859. }
  860. .money-reduced{
  861. margin-left: 10rpx;
  862. font-size: $font-size-26;
  863. color: $color-system;
  864. .iconfont{
  865. font-size: $font-size-34;
  866. }
  867. }
  868. }
  869. .sum{
  870. width: 100%;
  871. height: 40rpx;
  872. font-size: $font-size-26;
  873. line-height: 40rpx;
  874. color: $text-color;
  875. float: left;
  876. display: flex;
  877. justify-content: flex-end;
  878. font-weight: bold;
  879. .money{
  880. color: $color-system;
  881. font-size: $font-size-26;
  882. }
  883. .money-sign{
  884. font-size: $font-size-24;
  885. color: $color-system;
  886. }
  887. }
  888. }
  889. .pros-product{
  890. width: 416rpx;
  891. height: 100%;
  892. line-height: 36rpx;
  893. font-size: $font-size-28;
  894. position: relative;
  895. .producttitle{
  896. width: 100%;
  897. display: inline-block;
  898. height: auto;
  899. text-overflow:ellipsis;
  900. display: -webkit-box;
  901. word-break: break-all;
  902. -webkit-box-orient: vertical;
  903. -webkit-line-clamp: 2;
  904. overflow: hidden;
  905. margin-bottom: 15rpx;
  906. .no-text{
  907. display: inline-block;
  908. height:36rpx;
  909. padding: 0 12rpx;
  910. line-height: 36rpx;
  911. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  912. border-radius:18rpx;
  913. text-align: center;
  914. color: #FFFFFF;
  915. font-size:$font-size-28;
  916. margin-right: 24rpx;
  917. }
  918. }
  919. .productspec{
  920. height: 36rpx;
  921. color: #999999;
  922. font-size: $font-size-26;
  923. }
  924. .productprice{
  925. position: absolute;
  926. bottom: 0;
  927. width: 100%;
  928. height: 48rpx;
  929. margin: 30rpx 0 0 0;
  930. .price{
  931. line-height: 48rpx;
  932. font-size: $font-size-26;
  933. width: 48%;
  934. color: $color-system;
  935. float: left;
  936. font-weight: bold;
  937. &.disabled{
  938. color: #999999;
  939. text-decoration: line-through;
  940. }
  941. .money-sign{
  942. font-size: $font-size-24;
  943. color: $color-system;
  944. }
  945. }
  946. .count{
  947. height: 100%;
  948. float: right;
  949. position: relative;
  950. &.show{
  951. display: block;
  952. }
  953. &.none{
  954. display: none;
  955. }
  956. .count-tips{
  957. width: auto;
  958. display: inline-block;
  959. padding: 0 15rpx;
  960. line-height: 44rpx;
  961. height: 44rpx;
  962. border-radius: 22rpx;
  963. background: $btn-confirm;
  964. font-size: $font-size-24;
  965. text-align: center;
  966. color: #FFFFFF;
  967. position: absolute;
  968. top:-60rpx;
  969. left: -5rpx;
  970. z-index: 5;
  971. &.step{
  972. left:-217rpx
  973. }
  974. &::before{
  975. content: "";
  976. position: absolute;
  977. bottom: -30rpx;
  978. right: 15rpx;
  979. z-index:1;
  980. width: 0;
  981. height: 0;
  982. border-width: 18rpx;
  983. border-style: solid;
  984. border-color:$color-system transparent transparent transparent;
  985. }
  986. }
  987. .number-box {
  988. display: flex;
  989. justify-content: center;
  990. align-items: center;
  991. border: 2rpx solid #e1e1e1;
  992. border-radius: 30rpx;
  993. height: 48rpx;
  994. margin-left: 20rpx;
  995. .iconfont {
  996. font-size: $font-size-24;
  997. padding: 0 14rpx;
  998. color: #666666;
  999. text-align: center;
  1000. line-height: 48rpx;
  1001. font-weight: bold;
  1002. background: #ffffff;
  1003. &.icon-jianhao {
  1004. border-radius: 30rpx 0 0 30rpx;
  1005. }
  1006. &.icon-jiahao {
  1007. border-radius: 0 30rpx 30rpx 0;
  1008. }
  1009. }
  1010. .btn-input {
  1011. width: 56rpx;
  1012. height: 44rpx;
  1013. line-height: 44rpx;
  1014. border-radius: 4rpx;
  1015. text-align: center;
  1016. font-size: $font-size-24;
  1017. color: #333333;
  1018. background-color: #f7f7f7;
  1019. }
  1020. }
  1021. .uni-numbox{
  1022. position: absolute;
  1023. left: 45rpx;
  1024. bottom: 0;
  1025. .uni-numbox-minus, .uni-numbox-plus{
  1026. width: 50rpx;
  1027. line-height: 40rpx;
  1028. }
  1029. .uni-numbox-value {
  1030. font-size: $font-size-28;
  1031. width: 60rpx;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. .floor-item-act{
  1037. width: 100%;
  1038. height: 30rpx;
  1039. margin-top: 8rpx;
  1040. float: left;
  1041. .tag{
  1042. display: inline-block;
  1043. width: 80rpx;
  1044. height: 30rpx;
  1045. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png)top center no-repeat;
  1046. background-size: contain;
  1047. font-size: 22rpx;
  1048. line-height: 30rpx;
  1049. text-align: center;
  1050. color: #f83c6c;
  1051. float: left;
  1052. }
  1053. }
  1054. }
  1055. }
  1056. .failure-list{
  1057. width: 702rpx;
  1058. height: auto;
  1059. padding: 0 24rpx;
  1060. margin-top: 20rpx;
  1061. background: #FFFFFF;
  1062. .failure-title{
  1063. width: 100%;
  1064. height: 82rpx;
  1065. line-height: 82rpx;
  1066. font-size: $font-size-28;
  1067. border-bottom: 1px solid #EBEBEB;
  1068. .title-txt{
  1069. float: left;
  1070. color:#666666;
  1071. text-align: left;
  1072. }
  1073. .title-btn{
  1074. float: right;
  1075. color: $color-system;
  1076. text-align: right;
  1077. line-height: 80rpx;
  1078. .butto{
  1079. display: inline-block;
  1080. padding: 0 15rpx;
  1081. font-size: $font-size-26;
  1082. height: 50rpx;
  1083. line-height: 50rpx;
  1084. border-radius: 30rpx;
  1085. background:#fff8fd;
  1086. border: 1px solid #ff457b;
  1087. color: #ff457b;
  1088. margin-top: 15rpx;
  1089. }
  1090. }
  1091. }
  1092. .productlist{
  1093. padding-top: 10rpx;
  1094. .goods-pros{
  1095. width: 100%;
  1096. height: auto;
  1097. padding: 20rpx 0;
  1098. }
  1099. .goods-pros-t{
  1100. display: flex;
  1101. align-items: center;
  1102. width: 100%;
  1103. height: 210rpx;
  1104. position: relative;
  1105. .img-tip{
  1106. display: block;
  1107. width: 72rpx;
  1108. height: 36rpx;
  1109. line-height: 36rpx;
  1110. font-size: $font-size-24;
  1111. text-align: center;
  1112. color: #FFFFFF;
  1113. border-radius: 24rpx;
  1114. background:rgba(51,51,51,0.3);
  1115. // position: absolute;
  1116. // left: 0;
  1117. // top: 0;
  1118. }
  1119. .checkbox-box{
  1120. padding: 10rpx;
  1121. }
  1122. .pros-img{
  1123. width: 180rpx;
  1124. height: 100%;
  1125. border-radius: 10rpx;
  1126. margin:0 20rpx;
  1127. border:1px solid #f3f3f3;
  1128. position: relative;
  1129. image{
  1130. width: 100%;
  1131. height: 100%;
  1132. border-radius: 10rpx;
  1133. }
  1134. }
  1135. .pros-marks{
  1136. width: 730rpx; height: 250rpx;
  1137. z-index: 90;
  1138. background: rgba(0,0,0,.05);
  1139. position: absolute;
  1140. left:-20rpx;
  1141. top: -20rpx;
  1142. }
  1143. }
  1144. .goods-pros-b{
  1145. width:622rpx;
  1146. margin-left: 84rpx;
  1147. height: 40rpx;
  1148. padding:0 0 26rpx 0;
  1149. // border-top: 1px solid #EBEBEB;
  1150. &.show{
  1151. display: block;
  1152. }
  1153. &.none{
  1154. display: none;
  1155. }
  1156. .sum{
  1157. font-size: $font-size-28;
  1158. line-height: 40rpx;
  1159. color: $text-color;
  1160. display: flex;
  1161. justify-content: flex-end;
  1162. .money{
  1163. color: #FF2A2A;
  1164. font-size: $font-size-28;
  1165. }
  1166. .money-sign{
  1167. font-size: $font-size-24;
  1168. color: #FF2A2A;
  1169. }
  1170. }
  1171. }
  1172. .pros-product{
  1173. width: 402rpx;
  1174. height: 100%;
  1175. line-height: 36rpx;
  1176. font-size: $font-size-28;
  1177. position: relative;
  1178. .producttitle{
  1179. width: 100%;
  1180. display: inline-block;
  1181. height: auto;
  1182. text-overflow:ellipsis;
  1183. display: -webkit-box;
  1184. word-break: break-all;
  1185. -webkit-box-orient: vertical;
  1186. -webkit-line-clamp: 2;
  1187. overflow: hidden;
  1188. margin-bottom: 8rpx;
  1189. .no-text{
  1190. display: inline-block;
  1191. height:36rpx;
  1192. padding: 0 12rpx;
  1193. line-height: 36rpx;
  1194. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  1195. border-radius:18rpx;
  1196. text-align: center;
  1197. color: #FFFFFF;
  1198. font-size: $font-size-28;
  1199. margin-right: 24rpx;
  1200. }
  1201. }
  1202. .productspec{
  1203. height: 36rpx;
  1204. color: #999999;
  1205. font-size: $font-size-26;
  1206. margin-top: 20rpx;
  1207. }
  1208. .productstate{
  1209. font-size: $font-size-28;
  1210. height: 44rpx;
  1211. color: #FF2A2A;
  1212. position: absolute;
  1213. bottom: 0;
  1214. left: 0;
  1215. }
  1216. }
  1217. }
  1218. }
  1219. .footer{
  1220. width: 100%;
  1221. background-color: #FFFFFF;
  1222. height: 100rpx;
  1223. position: fixed;
  1224. bottom: 0rpx;
  1225. z-index: 100;
  1226. .footer-le{
  1227. width: 520rpx;
  1228. height: 100%;
  1229. padding:10rpx 24rpx;
  1230. float: left;
  1231. box-sizing: border-box;
  1232. .foot-check{
  1233. width: 100rpx;
  1234. float: left;
  1235. line-height: 80rpx;
  1236. font-size: $font-size-24;
  1237. .checkbox{
  1238. width: 40rpx;
  1239. text-align: center;
  1240. }
  1241. .text{
  1242. width: 60rpx;
  1243. float: right;
  1244. }
  1245. }
  1246. .sum{
  1247. width: 360rpx;
  1248. height: 100%;
  1249. float: right;
  1250. box-sizing: border-box;
  1251. padding:0 10rpx;
  1252. .sum-price{
  1253. text-align: right;
  1254. width: 100%;
  1255. height: 80rpx;
  1256. line-height: 80rpx;
  1257. font-size: $font-size-30;
  1258. color: $text-color;
  1259. float: left;
  1260. font-weight: normal;
  1261. .money{
  1262. color: $color-system;
  1263. }
  1264. .money-sign{
  1265. font-size: $font-size-24;
  1266. color: $color-system;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. .footer-ri{
  1272. width: 230rpx;
  1273. height: 100%;
  1274. float: right;
  1275. display: flex;
  1276. justify-content: space-between;
  1277. align-items: center;
  1278. z-index: 999;
  1279. box-sizing: border-box;
  1280. padding: 13rpx 15rpx;
  1281. &.none{
  1282. display: none;
  1283. }
  1284. .btn{
  1285. width: 200rpx;
  1286. height: 100%;
  1287. background:$btn-confirm;
  1288. font-size: $font-size-28;
  1289. line-height: 80rpx;
  1290. color: #FFFFFF;
  1291. display: flex;
  1292. border-radius: 40rpx;
  1293. justify-content: center;
  1294. align-items: center;
  1295. }
  1296. }
  1297. .footer-del{
  1298. width: 420rpx;
  1299. height: 100rpx;
  1300. position: absolute;
  1301. padding-left: 200rpx;
  1302. background: #FFFFFF;
  1303. right: 0;
  1304. top: 0;
  1305. z-index: 1000;
  1306. box-sizing: border-box;
  1307. padding: 10rpx 0;
  1308. display: flex;
  1309. &.show{
  1310. animation: showDelbtn 0s linear both;
  1311. }
  1312. &.none{
  1313. animation: hideDelbtn 0s linear both;
  1314. }
  1315. .btn{
  1316. flex: 1;
  1317. margin: 0 8rpx;
  1318. height: 100%;
  1319. line-height: 80rpx;
  1320. font-size: $font-size-28;
  1321. color: #FFFFFF;
  1322. text-align: center;
  1323. float: left;
  1324. border-radius: 40rpx;
  1325. }
  1326. .btn.btn-cancel{
  1327. background:#f7f7f7;
  1328. color: #B2B2B2;
  1329. }
  1330. .btn.btn-confirm{
  1331. background:$btn-confirm;
  1332. color: #FFFFFF;
  1333. }
  1334. @keyframes showDelbtn {
  1335. 0% {
  1336. transform: translateX(0);
  1337. }
  1338. 100% {
  1339. transform: translateX(-100%);
  1340. }
  1341. }
  1342. @keyframes hideDelbtn {
  1343. 0% {
  1344. transform: translateX(-100%);
  1345. }
  1346. 100% {
  1347. transform: translateX(0);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. </style>