cart.vue 35 KB

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