cart.vue 36 KB

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