cart.vue 35 KB

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