cart.vue 36 KB

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