cart.vue 36 KB

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