cart.vue 35 KB

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