index.vue 36 KB

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