cart.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  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)" @focus="changeInput(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. pros.isStep = false
  238. if(pros.validFlag == '3' ) {invalidLength++;}
  239. })
  240. item.isDisabled = invalidLength === productsListLength;
  241. })
  242. } else {
  243. this.goodsList = [];
  244. }
  245. if( responseData.failureList && 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. this.updateCheckAllBtn()
  287. },
  288. ischeck(item,pro){//为未选中的时候改变为true,反之为true
  289. pro.productsChecked = !pro.productsChecked;
  290. this.updateProductCheckedAllBtn(item);
  291. this.updateCheckAllBtn();
  292. },
  293. updateProductCheckedAllBtn(item) {// 单独每个供应商的勾选判断
  294. let productsList = item.productsList,
  295. productsCheckedLength = 0,
  296. disabledLength = 0;
  297. if(this.isshowDelbtn) {
  298. productsList.forEach(pros => {
  299. if(pros.productsChecked) {
  300. productsCheckedLength++;
  301. }
  302. })
  303. } else {
  304. productsList.forEach(pros => {
  305. if(pros.productsChecked && pros.validFlag != '3') {
  306. productsCheckedLength++;
  307. }
  308. if(pros.validFlag == '3') {disabledLength++;}
  309. })
  310. }
  311. item.checked = productsCheckedLength === productsList.length - disabledLength;
  312. },
  313. updateCheckAllBtn() {// 全选勾选判断
  314. let goodsCheckedLength = 0,
  315. disabledListLength = 0,
  316. goodsList = this.goodsList,
  317. failureList = this.failureList;
  318. goodsList.forEach(item => {
  319. if(item.checked) {
  320. goodsCheckedLength++;
  321. }
  322. if(item.isDisabled && !this.isshowDelbtn) {
  323. disabledListLength++;
  324. }
  325. })
  326. failureList.forEach(failureItem=>{
  327. if(failureItem.productsChecked){
  328. goodsCheckedLength++;
  329. }
  330. })
  331. this.isCheckAll = goodsCheckedLength === goodsList.length+failureList.length - disabledListLength;
  332. },
  333. checkShop(item){//与单选商品类似
  334. item.checked = !item.checked;
  335. this.setProductChecked(item);
  336. this.updateCheckAllBtn();
  337. },
  338. setProductChecked(item) {
  339. let products = item.productsList;
  340. products.forEach(pros=>{
  341. if(item.checked) {
  342. if(pros.validFlag =='3'){
  343. // 无效
  344. this.isNnder = true;
  345. pros.productsChecked = this.isshowDelbtn ?true :false;
  346. }else{
  347. // 有效
  348. this.isNnder = false;
  349. pros.productsChecked = true;
  350. }
  351. } else {
  352. pros.productsChecked = false;
  353. }
  354. })
  355. },
  356. updateBothCheckBtn() {
  357. if(this.isshowDelbtn) {
  358. // 当管理删除按钮出现时,失效的商品可被选择
  359. this.goodsList.forEach((item)=>{
  360. item.checked = this.isCheckAll;
  361. this.setProductChecked(item);
  362. })
  363. //删除按钮 全选包括失效商品勾选
  364. this.failureList.forEach(failureItem=>{
  365. failureItem.productsChecked = this.isCheckAll;
  366. })
  367. } else {
  368. this.goodsList.forEach((item)=>{
  369. item.checked = this.isCheckAll && !item.isDisabled;
  370. this.setProductChecked(item);
  371. })
  372. }
  373. },
  374. checkAll(){//全选方法内调用方法
  375. this.isCheckAll = !this.isCheckAll;
  376. this.updateBothCheckBtn();
  377. },
  378. totalShopPeice(){//每次所属会所下的商品增减重新计算合计价格&减去含有下架的商品
  379. let prosPrice=0;
  380. let validPrice =0;
  381. let validList=[];
  382. let productsList=[];
  383. this.goodsList.map((item,index)=>{
  384. productsList=item.productsList;
  385. prosPrice=productsList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  386. productsList.forEach(pros =>{
  387. if(pros.validFlag =='3'){
  388. validList.push(pros)
  389. validPrice = validList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  390. item.totalPrice = prosPrice - validPrice
  391. }else{
  392. item.totalPrice = prosPrice
  393. }
  394. })
  395. })
  396. },
  397. totalPeice(){ //计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
  398. this.allPrice = 0
  399. let prosPrice=0;
  400. let validPrice=0;
  401. let validList =[];
  402. let productsList =[];
  403. this.goodsList.forEach((item,index)=>{
  404. productsList=item.productsList;
  405. productsList.forEach(pros=>{
  406. if(pros.productsChecked){
  407. prosPrice+=pros.retailPrice*pros.productCount;
  408. if(pros.validFlag =='3'){
  409. validList.push(pros)
  410. validPrice = validList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  411. this.allPrice = prosPrice - validPrice
  412. }else{
  413. this.allPrice = prosPrice
  414. }
  415. }
  416. })
  417. })
  418. },
  419. totalCount(){//计算总数量
  420. this.allCount = 0
  421. let prosAllCount=0
  422. let validCount = 0
  423. let validList =[];
  424. let productsList =[];
  425. this.goodsList.forEach(item=>{
  426. productsList = item.productsList
  427. productsList.forEach(pros=>{
  428. if(pros.productsChecked){
  429. prosAllCount+=parseInt(pros.productCount);
  430. if(pros.validFlag =='3'){
  431. validList.push(pros)
  432. validList.forEach(val =>{
  433. validCount += val.productCount
  434. })
  435. this.allCount = prosAllCount - validCount
  436. }else{
  437. this.allCount = prosAllCount
  438. }
  439. }
  440. })
  441. })
  442. },
  443. changeCountAdd(item,pros){//商品数量加加
  444. if(pros.step === 2){
  445. pros.productCount += pros.minBuyNumber
  446. this.processActivityPrice(pros)
  447. this.isStock = false
  448. }else{
  449. pros.productCount++
  450. this.processActivityPrice(pros)
  451. this.isStock = false
  452. }
  453. this.updateShoppogNum(pros)
  454. this.totalShopPeice();
  455. },
  456. changeCountSub(item,pros){//商品数量减减
  457. if(pros.productCount<=pros.minBuyNumber){
  458. pros.productCount= pros.minBuyNumber
  459. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  460. return
  461. }else{
  462. if(pros.step === 2){
  463. pros.productCount -= pros.minBuyNumber
  464. }else{
  465. pros.productCount--
  466. }
  467. this.processActivityPrice(pros)
  468. }
  469. this.updateShoppogNum(pros)
  470. this.totalShopPeice();
  471. },
  472. changeInput(pros){//输入商品数量更新
  473. pros.isStep = false
  474. },
  475. changeNnmber(e,item,pros){//输入商品数量更新
  476. let _value = e.detail.value;
  477. if(!this.$api.isNumber(_value)){
  478. pros.productCount = pros.minBuyNumber
  479. }else if(_value < pros.minBuyNumber){
  480. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  481. pros.productCount = pros.minBuyNumber
  482. }else if(_value % pros.minBuyNumber != 0){
  483. pros.isStep = true
  484. pros.productCount = pros.minBuyNumber
  485. }else{
  486. pros.isStep = false
  487. pros.productCount = e.detail.value
  488. this.processActivityPrice(pros)
  489. }
  490. this.updateShoppogNum(pros)
  491. this.totalShopPeice();
  492. },
  493. processActivityPrice(pros){//单独处理活动价格和阶梯价格
  494. let ladderPriceList = pros.ladderPriceList;
  495. if(pros.ladderPriceFlag == '0' || pros.actStatus == 1){
  496. pros.retailPrice = pros.retailPrice
  497. }else{
  498. ladderPriceList.forEach((item,index)=>{
  499. if(pros.productCount>=item.buyNum){
  500. pros.retailPrice = item.buyPrice
  501. }
  502. })
  503. }
  504. },
  505. updateShoppogNum(pros){//加减购物车商品更新到后台
  506. let params ={userID:this.userID,productID:pros.productID,productCount:pros.productCount}
  507. shoppingCartUpdate(params).then(response =>{
  508. this.isshowDelbtn = false;
  509. this.initGetCartGoodsList();
  510. }).catch(error =>{
  511. this.$util.msg(error.msg,2000);
  512. })
  513. },
  514. toConfirmation(){//跳转确认订单页面
  515. let setGoodsList=[];
  516. this.goodsList.forEach(res=>{
  517. let products = res.productsList
  518. products.forEach(pros=>{
  519. if(pros.productsChecked){
  520. setGoodsList.push(pros.productID)
  521. }
  522. })
  523. })
  524. if(setGoodsList == ''){
  525. this.$util.msg("请先选择结算商品~",2000);
  526. return
  527. }else{
  528. this.isNoConfim = false
  529. this.goodsList.forEach(el=>{
  530. el.productsList.forEach(pros=>{
  531. if(pros.productsChecked){
  532. if(pros.productCount<pros.minBuyNumber){
  533. this.isNoConfim = true
  534. }
  535. }
  536. })
  537. })
  538. if(this.isNoConfim){
  539. this.$util.modal('','有商品的购买量没达到最小起订量,请修改数量后再次提交结算','去修改','',false,() =>{})
  540. return;
  541. }else{
  542. let productID = '';
  543. this.goodsList.forEach(el=>{//获取勾选的商品ID拼接字符串逗号隔开,最后一个逗号去掉
  544. el.productsList.forEach(pros=>{
  545. if(pros.productsChecked){
  546. productID += pros.productID+','
  547. }
  548. })
  549. })
  550. let cartPramsData={
  551. allPrice:this.allPrice,
  552. allCount:this.allCount,
  553. productID:productID.substring(0,productID.lastIndexOf(',')),
  554. productCount:''
  555. }
  556. this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({data:cartPramsData})}`)
  557. }
  558. }
  559. },
  560. showDelManager(){//显示删除商品管理
  561. this.isshowDelbtn = true;
  562. this.isNnder = true;
  563. if(this.isCheckAll) {
  564. this.updateBothCheckBtn();
  565. } else {
  566. this.goodsList.forEach(item => {
  567. if(item.checked) {
  568. item.productsList.forEach(pros => {
  569. pros.productsChecked = true;
  570. })
  571. }
  572. })
  573. this.updateCheckAllBtn();
  574. }
  575. // 失效也被勾选
  576. this.failureList.forEach(failureItem => {
  577. if(failureItem.isFailureLayer){
  578. failureItem.isFailureLayer = false
  579. }
  580. })
  581. },
  582. hideDelManage(){//隐藏删除商品管理
  583. this.isshowDelbtn = false;
  584. let isFailureLayer,newFailureList =[];
  585. if(this.isCheckAll) {
  586. this.updateBothCheckBtn();
  587. } else {
  588. // 失效商品取消勾选
  589. this.goodsList.forEach(item => {
  590. if(item.isDisabled) {
  591. item.checked = false;
  592. }
  593. item.productsList.forEach(pros => {
  594. if(pros.validFlag == '3') {
  595. pros.productsChecked = false;
  596. }
  597. })
  598. })
  599. this.updateCheckAllBtn();
  600. }
  601. this.failureList.forEach((failure,index) => {
  602. if(failure.failureState == 1 || failure.failureState == 2) {
  603. isFailureLayer = true
  604. }else{
  605. isFailureLayer = false
  606. }
  607. newFailureList.push(Object.assign({},failure,{isFailureLayer:isFailureLayer}))
  608. })
  609. this.failureList = newFailureList;
  610. },
  611. deleteList(){//删除购物车商品
  612. this.delGoodsList=[];
  613. this.goodsList.forEach(delitem=>{
  614. let products = delitem.productsList
  615. products.forEach(pros=>{
  616. if(pros.productsChecked){
  617. this.delGoodsList += pros.productID+','
  618. }
  619. })
  620. })
  621. this.failureList.forEach(failure=>{
  622. if(failure.productsChecked){
  623. this.delGoodsList += failure.productID+','
  624. }
  625. })
  626. if(this.delGoodsList.length == 0){
  627. this.$util.msg("请选择要删除的商品~",2000);
  628. return
  629. }else{
  630. this.$util.modal('','确定删除选中的商品吗?','确定','取消',true,() =>{
  631. shoppingCartDelete({userID:this.userID,productIDs:this.delGoodsList}).then(response =>{
  632. this.$util.msg('删除成功',2000);
  633. setTimeout(()=>{
  634. this.isshowDelbtn = false;
  635. this.initGetCartGoodsList();
  636. },2000)
  637. }).catch(error =>{
  638. this.$util.msg(error.msg,2000)
  639. })
  640. })
  641. }
  642. },
  643. deletefailureList(){
  644. this.failureList.forEach(failure=>{ this.delGoodsList += failure.productID+',' })
  645. this.$util.modal('','确定清空全部失效商品吗?','确定','取消',true,() =>{
  646. shoppingCartDelete({userID:this.userID,productIDs:this.delGoodsList}).then(response =>{
  647. this.$util.msg('删除成功',2000);
  648. setTimeout(()=>{
  649. this.isshowDelbtn = false;
  650. this.initGetCartGoodsList();
  651. },2000)
  652. }).catch(error =>{
  653. this.$util.msg(error.msg,2000)
  654. })
  655. })
  656. },
  657. goIndex(){
  658. uni.switchTab({
  659. url: '/pages/tabBar/home/home'
  660. });
  661. },
  662. goNavto(url){
  663. uni.navigateTo ({
  664. url
  665. })
  666. },
  667. navToListPage(id){
  668. this.isModallayer = true;
  669. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  670. },
  671. failureToProduct(failure){
  672. if(failure.failureState == 1){
  673. this.$util.msg('商品已丢失,不能查看',2000)
  674. return
  675. }else if(failure.failureState == 2){
  676. this.$util.msg('商品已停售,不能查看',2000)
  677. return
  678. }else{
  679. this.isModallayer = true;
  680. this.$api.navigateTo(`/pages/goods/product?id=${failure.productID}`)
  681. }
  682. },
  683. failureStateText(state){
  684. let stateText = '',
  685. stateTextObject={
  686. 1:'商品已丢失',
  687. 2:'商品已停售',
  688. 3:'商品已下架',
  689. 4:'商品已售罄',
  690. 5:'价格仅会员可见,您不能购买',
  691. 6:'未公开价格',
  692. 7:'库存不足'
  693. }
  694. Object.keys(stateTextObject).forEach(key => {
  695. if(key == state){
  696. stateText = stateTextObject[key]
  697. }
  698. })
  699. return stateText;
  700. },
  701. setHeaderBtnPosi(){
  702. // 获得胶囊按钮位置信息
  703. let headerBtnPosi = uni.getMenuButtonBoundingClientRect();
  704. return headerBtnPosi
  705. },
  706. setSysteminfo(){
  707. let systeminfo;
  708. uni.getSystemInfo({ // 获取设备信息
  709. success: (res) => {
  710. systeminfo = res
  711. },
  712. })
  713. return systeminfo
  714. }
  715. },
  716. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  717. goodsList:{
  718. deep:true,
  719. handler(val,oldval){
  720. this.totalPeice()
  721. this.totalCount()
  722. }
  723. }
  724. },
  725. onPullDownRefresh() {//下拉刷新
  726. this.initGetCartGoodsList()
  727. uni.stopPullDownRefresh()
  728. },
  729. onShow(){
  730. if(this.hasLogin){
  731. this.initData()
  732. }else{
  733. this.initLogin()
  734. }
  735. },
  736. }
  737. </script>
  738. <style lang="scss">
  739. page{
  740. background: #f7f7f7;
  741. height: auto;
  742. }
  743. .cart-content{
  744. position: relative;
  745. }
  746. .container-cart-main.none{
  747. display: none;
  748. }
  749. .container-cart-main.show{
  750. display: block;
  751. }
  752. .cart-content.empty.none{
  753. display: none;
  754. }
  755. .cart-content.empty.show{
  756. display: block;
  757. }
  758. .container-cart.show{
  759. display: block;
  760. }
  761. .container-cart.none{
  762. display: none;
  763. }
  764. .empty-container.none{
  765. display: none;
  766. }
  767. .empty-container.show{
  768. display: flex;
  769. }
  770. .checkbox-box{
  771. display: flex;
  772. align-items: center;
  773. .checkbox{
  774. display: flex;
  775. margin: 0;
  776. padding: 0;
  777. display: flex;
  778. flex-direction: column;
  779. align-items: center;
  780. box-sizing: border-box;
  781. text-align: center;
  782. text-decoration: none;
  783. border-radius: 0;
  784. -webkit-tap-highlight-color: transparent;
  785. overflow: hidden;
  786. background-color:#FFFFFF;
  787. font-size: 36rpx;
  788. color:$color-system;
  789. }
  790. &.disabled{
  791. .checkbox{
  792. color:#999999
  793. }
  794. }
  795. .text{
  796. font-size: $font-size-24;
  797. margin-left: 10rpx;
  798. }
  799. }
  800. .goods-list{
  801. width: 100%;
  802. height: auto;
  803. background-color: #F7F7F7;
  804. .goods-item{
  805. width: 702rpx;
  806. padding: 0 24rpx;
  807. background: #FFFFFF;
  808. margin-bottom: 24rpx;
  809. }
  810. .shoptitle{
  811. display: flex;
  812. align-items: center;
  813. height: 80rpx;
  814. // border-bottom: 1px solid #EBEBEB;
  815. line-height: 80rpx;
  816. .checkbox-box{
  817. padding: 10rpx;
  818. }
  819. .text{
  820. margin-left: 37rpx;
  821. font-size: $font-size-28;
  822. color: $text-color;
  823. text-align: left;
  824. font-weight: bold;
  825. }
  826. }
  827. .goods-pros{
  828. width: 100%;
  829. height: auto;
  830. }
  831. .goods-pros-t{
  832. display: flex;
  833. align-items: center;
  834. width: 100%;
  835. height: 210rpx;
  836. padding:0 0 26rpx 0;
  837. .checkbox-box{
  838. padding: 10rpx;
  839. }
  840. .pros-img{
  841. width: 210rpx;
  842. height: 100%;
  843. border-radius: 10rpx;
  844. margin:0 20rpx;
  845. border:1px solid #f3f3f3;
  846. image{
  847. width: 100%;
  848. height: 100%;
  849. border-radius: 10rpx;
  850. }
  851. }
  852. }
  853. .goods-pros-b{
  854. width:622rpx;
  855. margin-left: 84rpx;
  856. height: 40rpx;
  857. padding:0 0 26rpx 0;
  858. // border-top: 1px solid #EBEBEB;
  859. &.show{
  860. display: block;
  861. }
  862. &.none{
  863. display: none;
  864. }
  865. .sum{
  866. font-size: $font-size-28;
  867. line-height: 40rpx;
  868. color: $text-color;
  869. display: flex;
  870. justify-content: flex-end;
  871. .money{
  872. color: #FF2A2A;
  873. font-size: $font-size-28;
  874. }
  875. .money-sign{
  876. font-size: $font-size-24;
  877. color: #FF2A2A;
  878. }
  879. }
  880. }
  881. .pros-product{
  882. width: 402rpx;
  883. height: 100%;
  884. line-height: 36rpx;
  885. font-size: $font-size-28;
  886. position: relative;
  887. .producttitle{
  888. width: 100%;
  889. display: inline-block;
  890. height: auto;
  891. text-overflow:ellipsis;
  892. display: -webkit-box;
  893. word-break: break-all;
  894. -webkit-box-orient: vertical;
  895. -webkit-line-clamp: 2;
  896. overflow: hidden;
  897. margin-bottom: 8rpx;
  898. .no-text{
  899. display: inline-block;
  900. height:36rpx;
  901. padding: 0 12rpx;
  902. line-height: 36rpx;
  903. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  904. border-radius:18rpx;
  905. text-align: center;
  906. color: #FFFFFF;
  907. font-size:$font-size-28;
  908. margin-right: 24rpx;
  909. }
  910. }
  911. .productspec{
  912. height: 36rpx;
  913. color: #999999;
  914. font-size: $font-size-26;
  915. }
  916. .productprice{
  917. height: 48rpx;
  918. position: absolute;
  919. width: 100%;
  920. bottom: 0;
  921. .price{
  922. line-height: 48rpx;
  923. font-size: $font-size-28;
  924. width: 48%;
  925. color: #FF2A2A;
  926. float: left;
  927. &.disabled{
  928. color: #999999;
  929. }
  930. .money-sign{
  931. font-size: $font-size-24;
  932. color: #FF2A2A;
  933. }
  934. }
  935. .count{
  936. height: 100%;
  937. float: right;
  938. position: relative;
  939. &.show{
  940. display: block;
  941. }
  942. &.none{
  943. display: none;
  944. }
  945. .number-box{
  946. display: flex;
  947. justify-content: center;
  948. align-items: center;
  949. .iconfont{
  950. font-size: $font-size-24;
  951. padding:0 20rpx;
  952. color: $text-color;
  953. text-align: center;
  954. line-height: 48rpx;
  955. font-weight: bold;
  956. }
  957. .btn-input{
  958. width: 62rpx;
  959. height: 48rpx;
  960. line-height: 48rpx;
  961. background: #F8F8F8;
  962. border-radius: 4rpx;
  963. text-align: center;
  964. font-size: $font-size-24;
  965. }
  966. }
  967. .uni-numbox{
  968. position: absolute;
  969. left: 45rpx;
  970. bottom: 0;
  971. .uni-numbox-minus, .uni-numbox-plus{
  972. width: 50rpx;
  973. line-height: 40rpx;
  974. }
  975. .uni-numbox-value {
  976. font-size: $font-size-28;
  977. width: 60rpx;
  978. }
  979. }
  980. }
  981. }
  982. }
  983. }
  984. .failure-list{
  985. width: 702rpx;
  986. height: auto;
  987. padding: 0 24rpx;
  988. margin-top: 20rpx;
  989. background: #FFFFFF;
  990. .failure-title{
  991. width: 100%;
  992. height: 80rpx;
  993. line-height: 80rpx;
  994. font-size: $font-size-28;
  995. border-bottom: 1px solid #EBEBEB;
  996. .title-txt{
  997. float: left;
  998. color: $text-color;
  999. text-align: left;
  1000. }
  1001. .title-btn{
  1002. float: right;
  1003. color: $color-system;
  1004. text-align: right;
  1005. }
  1006. }
  1007. .productlist{
  1008. padding-top: 10rpx;
  1009. .goods-pros{
  1010. width: 100%;
  1011. height: auto;
  1012. padding: 20rpx 0;
  1013. }
  1014. .goods-pros-t{
  1015. display: flex;
  1016. align-items: center;
  1017. width: 100%;
  1018. height: 210rpx;
  1019. position: relative;
  1020. .checkbox-box{
  1021. padding: 10rpx;
  1022. }
  1023. .pros-img{
  1024. width: 210rpx;
  1025. height: 100%;
  1026. border-radius: 10rpx;
  1027. margin:0 20rpx;
  1028. border:1px solid #f3f3f3;
  1029. position: relative;
  1030. .img-tip{
  1031. display: block;
  1032. width: 72rpx;
  1033. height: 36rpx;
  1034. line-height: 36rpx;
  1035. font-size: $font-size-24;
  1036. text-align: center;
  1037. color: #FFFFFF;
  1038. border-radius: 10rpx 0 10rpx 0;
  1039. background:linear-gradient(34deg,rgba(255,149,42,1) 0%,rgba(225,86,22,1) 100%);
  1040. position: absolute;
  1041. left: 0;
  1042. top: 0;
  1043. }
  1044. image{
  1045. width: 100%;
  1046. height: 100%;
  1047. border-radius: 10rpx;
  1048. }
  1049. }
  1050. .pros-marks{
  1051. width: 722rpx; height: 250rpx;
  1052. z-index: 90;
  1053. background: rgba(0,0,0,.05);
  1054. position: absolute;
  1055. left:0;
  1056. top: -20rpx;
  1057. }
  1058. }
  1059. .goods-pros-b{
  1060. width:622rpx;
  1061. margin-left: 84rpx;
  1062. height: 40rpx;
  1063. padding:0 0 26rpx 0;
  1064. // border-top: 1px solid #EBEBEB;
  1065. &.show{
  1066. display: block;
  1067. }
  1068. &.none{
  1069. display: none;
  1070. }
  1071. .sum{
  1072. font-size: $font-size-28;
  1073. line-height: 40rpx;
  1074. color: $text-color;
  1075. display: flex;
  1076. justify-content: flex-end;
  1077. .money{
  1078. color: #FF2A2A;
  1079. font-size: $font-size-28;
  1080. }
  1081. .money-sign{
  1082. font-size: $font-size-24;
  1083. color: #FF2A2A;
  1084. }
  1085. }
  1086. }
  1087. .pros-product{
  1088. width: 402rpx;
  1089. height: 100%;
  1090. line-height: 36rpx;
  1091. font-size: $font-size-28;
  1092. position: relative;
  1093. .producttitle{
  1094. width: 100%;
  1095. display: inline-block;
  1096. height: auto;
  1097. text-overflow:ellipsis;
  1098. display: -webkit-box;
  1099. word-break: break-all;
  1100. -webkit-box-orient: vertical;
  1101. -webkit-line-clamp: 2;
  1102. overflow: hidden;
  1103. margin-bottom: 8rpx;
  1104. .no-text{
  1105. display: inline-block;
  1106. height:36rpx;
  1107. padding: 0 12rpx;
  1108. line-height: 36rpx;
  1109. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  1110. border-radius:18rpx;
  1111. text-align: center;
  1112. color: #FFFFFF;
  1113. font-size: $font-size-28;
  1114. margin-right: 24rpx;
  1115. }
  1116. }
  1117. .productspec{
  1118. height: 36rpx;
  1119. color: #999999;
  1120. font-size: $font-size-26;
  1121. }
  1122. .productstate{
  1123. font-size: $font-size-28;
  1124. height: 44rpx;
  1125. color: #FF2A2A;
  1126. position: absolute;
  1127. bottom: 0;
  1128. left: 0;
  1129. }
  1130. }
  1131. }
  1132. }
  1133. .footer{
  1134. width: 100%;
  1135. background-color: #FFFFFF;
  1136. height: 110rpx;
  1137. position: fixed;
  1138. bottom: 0rpx;
  1139. z-index: 100;
  1140. .footer-le{
  1141. width: 490rpx;
  1142. height: 100%;
  1143. padding:0 30rpx;
  1144. float: left;
  1145. .text{
  1146. font-weight: bold;
  1147. }
  1148. .foot-check{
  1149. width: 100rpx;
  1150. float: left;
  1151. line-height: 110rpx;
  1152. font-size: $font-size-24;
  1153. .checkbox{
  1154. width: 40rpx;
  1155. text-align: center;
  1156. }
  1157. .text{
  1158. width: 60rpx;
  1159. float: right;
  1160. }
  1161. }
  1162. .foot-check-delbtn{
  1163. float: left;
  1164. .delBtn{
  1165. margin: 0;
  1166. padding: 0;
  1167. display: flex;
  1168. flex-direction: column;
  1169. align-items: center;
  1170. box-sizing: border-box;
  1171. font-size: $font-size-24;
  1172. text-align: center;
  1173. text-decoration: none;
  1174. border-radius: 0;
  1175. -webkit-tap-highlight-color: transparent;
  1176. overflow: hidden;
  1177. background-color:#FFFFFF;
  1178. color: #FF2A2A;
  1179. padding: 0 24rpx;
  1180. display: flex;
  1181. justify-content: center;
  1182. align-items: center;
  1183. line-height: 110rpx;
  1184. font-weight: bold;
  1185. &.none{
  1186. display: none;
  1187. }
  1188. }
  1189. }
  1190. .sum{
  1191. font-size: $font-size-28;
  1192. line-height: 110rpx;
  1193. color: $text-color;
  1194. display: flex;
  1195. justify-content: flex-end;
  1196. .money{
  1197. color: #FF2A2A;
  1198. }
  1199. .money-sign{
  1200. font-size: $font-size-24;
  1201. color: #FF2A2A;
  1202. }
  1203. }
  1204. }
  1205. .footer-ri{
  1206. width: 200rpx;
  1207. height: 100%;
  1208. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  1209. float: right;
  1210. display: flex;
  1211. justify-content: space-between;
  1212. align-items: center;
  1213. z-index: 999;
  1214. &.none{
  1215. display: none;
  1216. }
  1217. .btn{
  1218. width: 200rpx;
  1219. height: 100%;
  1220. font-size: $font-size-28;
  1221. line-height: 110rpx;
  1222. color: #FFFFFF;
  1223. display: flex;
  1224. justify-content: center;
  1225. align-items: center;
  1226. }
  1227. }
  1228. .footer-del{
  1229. width: 400rpx;
  1230. height: 110rpx;
  1231. position: absolute;
  1232. padding-left: 200rpx;
  1233. background: #FFFFFF;
  1234. right: 0;
  1235. top: 0;
  1236. z-index: 1000;
  1237. &.show{
  1238. animation: showDelbtn 0s linear both;
  1239. }
  1240. &.none{
  1241. animation: hideDelbtn 0s linear both;
  1242. }
  1243. .btn{
  1244. width: 50%;
  1245. height: 100%;
  1246. line-height: 110rpx;
  1247. font-size: $font-size-28;
  1248. color: #FFFFFF;
  1249. text-align: center;
  1250. float: left;
  1251. }
  1252. .btn.btn-cancel{
  1253. background:#EEC1AB;
  1254. }
  1255. .btn.btn-confirm{
  1256. background:#FF2A2A;
  1257. }
  1258. @keyframes showDelbtn {
  1259. 0% {
  1260. transform: translateX(0);
  1261. }
  1262. 100% {
  1263. transform: translateX(-100%);
  1264. }
  1265. }
  1266. @keyframes hideDelbtn {
  1267. 0% {
  1268. transform: translateX(-100%);
  1269. }
  1270. 100% {
  1271. transform: translateX(0);
  1272. }
  1273. }
  1274. }
  1275. }
  1276. </style>