cart.vue 35 KB

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