cart.vue 35 KB

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