cart.vue 35 KB

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