cart.vue 35 KB

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