cart.vue 37 KB

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