cart.vue 35 KB

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