cart.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. <template>
  2. <view class="container cart clearfix" v-if="hasLogin">
  3. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  4. <view class="container-cart-main tui-skeleton">
  5. <view v-if="!isEmpty" class="container-cart">
  6. <scroll-view class="cart-content" scroll-y @scrolltolower="toLower" :style="{paddingBottom :isIphoneX ? (68+100)+'rpx' : '100rpx'}">
  7. <view class="goods-list">
  8. <view v-for="(item, index) in goodsList" :key="index" class="goods-item">
  9. <view class="shoptitle">
  10. <!--选择商店的全部商品"-->
  11. <view class="checkbox-box" @click.stop="checkShop(item)">
  12. <button class="checkbox iconfont"
  13. :class="[item.checked ?'icon-gouxuanl':'icon-weigouxuan']"
  14. :disabled="item.isDisabled && !isshowDelbtn">
  15. </button>
  16. </view>
  17. <view class="text">{{item.name}}</view>
  18. </view>
  19. <view class="productlist">
  20. <view class="goods-pros" v-for="(pros,idx) in item.productsList" :key="idx" >
  21. <view class="goods-pros-t">
  22. <!--选择商品-->
  23. <view class="checkbox-box" @click.stop="ischeck(item,pros)" :class="[pros.validFlag == '3' && !isshowDelbtn ?'disabled' : '']">
  24. <button class="checkbox iconfont"
  25. :disabled="pros.validFlag == '3' && !isshowDelbtn"
  26. :class="[pros.productsChecked ?'icon-gouxuanl':'icon-weigouxuan']">
  27. </button>
  28. </view>
  29. <view class="pros-img" @click.stop="navToListPage(pros.productID)" ><image :src="pros.mainImage ? pros.mainImage:''" alt="" /></view>
  30. <view class="pros-product">
  31. <view class="producttitle" @click.stop="navToListPage(pros.productID)" >
  32. <text v-if="pros.validFlag == '3'" class="no-text">商品已下架</text>{{pros.name}}
  33. </view>
  34. <view class="productspec">规格:{{pros.unit ? pros.unit : ''}}</view>
  35. <view class="productprice">
  36. <!--使用过滤器对总价改变-->
  37. <view class="price" :class="[pros.validFlag == '3' ?'disabled' : '']">
  38. <text :class="[pros.validFlag == '3' ?'disabled' : 'money-sign']">¥</text>
  39. {{pros.retailPrice?pros.retailPrice.toFixed(2):''}}
  40. </view>
  41. <view class="count" v-if="pros.validFlag == '2'" :class="[isshowDelbtn ? 'none':'show']">
  42. <view class="number-box">
  43. <view class="iconfont icon-jianhao" :class="[pros.validFlag == '3'?'disabled':'']" @click="changeCountSub(item,pros)"></view>
  44. <input class="btn-input" type="number" maxlength='4' v-model="pros.productCount" @blur="changeNnmber($event,item,pros)">
  45. <view class="iconfont icon-jiahao" :class="[pros.validFlag == '3'?'disabled':'']" @click="changeCountAdd(item,pros)"></view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="goods-pros-b" :class="[isshowDelbtn ? 'none':'show']" >
  54. <view class="sum">合计:<text class="money"><text class="money-sign">¥</text>{{item.totalPrice.toFixed(2)}}</text></view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="failure-list" v-if="failureList.length>0">
  59. <view class="failure-title">
  60. <view class="title-txt">失效商品<text>{{failureList.length}}件</text></view>
  61. <view class="title-btn" @click.stop="deletefailureList">清空失效商品</view>
  62. </view>
  63. <view class="productlist">
  64. <view class="goods-pros" v-for="(failure,failureIdx) in failureList" :key="failureIdx" >
  65. <view class="goods-pros-t" @click.stop="failureToProduct(failure)">
  66. <!--选择商品-->
  67. <view class="checkbox-box" @click.stop="ischeckFailure(failure)" v-if="isshowDelbtn">
  68. <button class="checkbox iconfont"
  69. :disabled="!isshowDelbtn"
  70. :class="[failure.productsChecked ?'icon-gouxuanl':'icon-weigouxuan']">
  71. </button>
  72. </view>
  73. <view class="pros-img">
  74. <image :src="failure.mainImage ? failure.mainImage:''" alt="" />
  75. <text class="img-tip">失效</text>
  76. </view>
  77. <view class="pros-product">
  78. <view class="producttitle">{{failure.name}}</view>
  79. <view class="productspec">规格:{{failure.unit ? failure.unit : ''}}</view>
  80. <view class="productstate">{{failureStateText(failure.failureState)}}</view>
  81. </view>
  82. <view class="pros-marks" v-if="failure.isFailureLayer"></view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </scroll-view>
  88. <!-- 脚部菜单 -->
  89. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  90. <view class="footer-le">
  91. <view class="foot-check checkbox-box" @tap.stop="checkAll()">
  92. <button class="checkbox iconfont" :class="[isCheckAll?'icon-gouxuan':'icon-weigouxuan']"></button>
  93. <view class="text">全选</view>
  94. </view>
  95. <view class="foot-check-delbtn">
  96. <button class="delBtn" @tap.stop="showDelManager">删除</button>
  97. </view>
  98. <view class="sum">总价:<text class="money-sign">¥</text><text class="money">{{allPrice.toFixed(2)}}</text></view>
  99. </view>
  100. <view v-if="!isshowDelbtn" class="footer-ri" >
  101. <view class="btn" @tap="toConfirmation">去结算({{allCount}})</view>
  102. </view>
  103. <view v-else class="footer-del">
  104. <view class="btn btn-cancel" @tap.stop="hideDelManage">取消</view>
  105. <view class="btn btn-confirm" @tap.stop="deleteList">删除</view>
  106. </view>
  107. </view>
  108. </view>
  109. <view v-if="isEmpty" class="cart-content empty">
  110. <view class="empty-container">
  111. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  112. <text class="error-text">购物车空空如也,快去商城逛逛吧~</text>
  113. <view class="login-btn" @click="goIndex">去商城</view>
  114. </view>
  115. </view>
  116. </view>
  117. <!-- 透明模态层 -->
  118. <modal-layer v-if='modallayer'></modal-layer>
  119. </view>
  120. </template>
  121. <script>
  122. import authorize from '@/common/config/authorize.js'
  123. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  124. import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
  125. import tuiNomore from "@/components/tui-components/nomore/nomore"
  126. import modalLayer from "@/components/modal-layer"
  127. import { mapState,mapMutations } from 'vuex';
  128. import { queryShoppingCartList,shoppingCartUpdate,shoppingCartDelete } from "@/api/cart.js"
  129. export default{
  130. components:{
  131. tuiSkeleton,
  132. tuiLoadmore,
  133. tuiNomore,
  134. modalLayer
  135. },
  136. data(){
  137. return{
  138. nvabarData: {//顶部自定义导航
  139. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  140. showSearch: 0,
  141. title: '购物车', // 导航栏 中间的标题
  142. haveBack:true,
  143. textLeft:this.$store.state.isIphone,
  144. },
  145. CustomBar:this.CustomBar,// 顶部导航栏高度
  146. isIphoneX:this.$store.state.isIphoneX,
  147. userID:'',
  148. alertType:'',
  149. isStock:'',
  150. failureList:[], //失效商品列表
  151. goodsList:[], //购物车的商品
  152. delGoodsList:'',//要删除的商品
  153. setGoodData:'', //确认订单的商品
  154. isCheckAll:false,//是否全选
  155. allPrice:0,//所有价格
  156. allCount:0,//被选中的产品数量
  157. isNnder:true,
  158. isModallayer:false,
  159. skeletonShow:true,
  160. isshowDelbtn:false,
  161. isDisabled: false, // 供应商/店铺全选是否禁用状态
  162. isEmpty:false,//显示空购物车
  163. scrollHeight: 'auto',
  164. nomoreText: '上拉显示更多',
  165. hasNextPage: false,
  166. loadding: false,
  167. pullUpOn: true,
  168. pullFlag: true,
  169. pageSize: 10,
  170. pageNum: 1,
  171. }
  172. },
  173. onLoad(){
  174. this.setScrollHeight();
  175. },
  176. computed: {
  177. ...mapState(['hasLogin','userInfo'])
  178. },
  179. filters:{//单件商品的价格 × 数量
  180. totalprice(val,count){
  181. return (val * count).toFixed(2)
  182. }
  183. },
  184. methods:{
  185. initData(){
  186. this.isModallayer = false //遮罩层 防止多次点击
  187. this.skeletonShow = true //预加载圆圈
  188. this.isCheckAll=false//是否全选
  189. this.$api.getStorage().then((resolve) => {
  190. this.userID = resolve.userID;
  191. this.initGetCartGoodsList();
  192. })
  193. },
  194. initLogin(){
  195. authorize.getSetting().then(wxResponse =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  196. if(wxResponse == 1){
  197. this.$api.redirectTo('/pages/login/login?type=4')
  198. }else{
  199. this.$api.navigateTo('/pages/authorization/authorization?type=0')
  200. }
  201. })
  202. },
  203. setScrollHeight() {
  204. // 窗口高度-footer高度
  205. const {windowHeight, pixelRatio} = uni.getSystemInfoSync();
  206. setTimeout(()=> {
  207. const query = uni.createSelectorQuery().in(this);
  208. query.selectAll('.footer').boundingClientRect();
  209. query.exec(res => {
  210. this.windowHeight = windowHeight;
  211. if(res[0][0]) {
  212. this.scrollHeight = windowHeight - res[0][0].height;
  213. }
  214. })
  215. }, 500)
  216. },
  217. initGetCartGoodsList(){//初始化购物车 index:1
  218. let params = {userID:this.userID,pageNum:1,pageSize:this.pageSize}
  219. queryShoppingCartList(params).then(response =>{
  220. this.skeletonShow = false
  221. this.$store.commit('updateAllNum',response.data.cartQuantity)
  222. const responseData = response.data
  223. if(responseData.pageDate.length > 0 && responseData.failureList.length > 0){
  224. this.isEmpty =false
  225. } else {
  226. this.isEmpty =true
  227. }
  228. if( responseData.pageDate.length > 0){
  229. this.goodsList = responseData.pageDate;
  230. this.goodsList.forEach((item,index) => {
  231. let productsListLength = item.productsList.length,
  232. invalidLength = 0;
  233. item.productsList.forEach(pros => {
  234. pros.shopID = item.shopID;
  235. if(pros.validFlag == '3' ) {invalidLength++;}
  236. })
  237. item.isDisabled = invalidLength === productsListLength;
  238. })
  239. } else {
  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. }
  655. Object.keys(stateTextObject).forEach(key => {
  656. if(key == state){
  657. stateText = stateTextObject[key]
  658. }
  659. })
  660. return stateText;
  661. }
  662. },
  663. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  664. goodsList:{
  665. deep:true,
  666. handler(val,oldval){
  667. this.totalPeice()
  668. this.totalCount()
  669. }
  670. }
  671. },
  672. // onReachBottom() {
  673. // if(this.hasNextPage){
  674. // this.loadding = true
  675. // this.pullUpOn = true
  676. // this.getOnReachBottomData()
  677. // }
  678. // },
  679. onPullDownRefresh() {//下拉刷新
  680. this.initGetCartGoodsList()
  681. uni.stopPullDownRefresh()
  682. },
  683. onShow(){
  684. if(this.hasLogin){
  685. this.initData()
  686. }else{
  687. this.initLogin()
  688. }
  689. },
  690. }
  691. </script>
  692. <style lang="scss">
  693. page{
  694. background: #f7f7f7;
  695. height: auto;
  696. }
  697. .cart-content{
  698. position: relative;
  699. }
  700. .container-cart-main.none{
  701. display: none;
  702. }
  703. .container-cart-main.show{
  704. display: block;
  705. }
  706. .cart-content.empty.none{
  707. display: none;
  708. }
  709. .cart-content.empty.show{
  710. display: block;
  711. }
  712. .container-cart.show{
  713. display: block;
  714. }
  715. .container-cart.none{
  716. display: none;
  717. }
  718. .empty-container.none{
  719. display: none;
  720. }
  721. .empty-container.show{
  722. display: flex;
  723. }
  724. .checkbox-box{
  725. display: flex;
  726. align-items: center;
  727. .checkbox{
  728. display: flex;
  729. margin: 0;
  730. padding: 0;
  731. display: flex;
  732. flex-direction: column;
  733. align-items: center;
  734. box-sizing: border-box;
  735. text-align: center;
  736. text-decoration: none;
  737. border-radius: 0;
  738. -webkit-tap-highlight-color: transparent;
  739. overflow: hidden;
  740. background-color:#FFFFFF;
  741. font-size: 36rpx;
  742. color:$color-system;
  743. }
  744. &.disabled{
  745. .checkbox{
  746. color:#999999
  747. }
  748. }
  749. .text{
  750. font-size: $font-size-24;
  751. margin-left: 10rpx;
  752. }
  753. }
  754. .goods-list{
  755. width: 100%;
  756. height: auto;
  757. border-top: 1px solid #EBEBEB;
  758. background-color: #F7F7F7;
  759. .goods-item{
  760. width: 702rpx;
  761. padding: 0 24rpx;
  762. background: #FFFFFF;
  763. margin-bottom: 24rpx;
  764. }
  765. .shoptitle{
  766. display: flex;
  767. align-items: center;
  768. height: 80rpx;
  769. // border-bottom: 1px solid #EBEBEB;
  770. line-height: 80rpx;
  771. .checkbox-box{
  772. padding: 10rpx;
  773. }
  774. .text{
  775. margin-left: 37rpx;
  776. font-size: $font-size-28;
  777. color: $text-color;
  778. text-align: left;
  779. font-weight: bold;
  780. }
  781. }
  782. .goods-pros{
  783. width: 100%;
  784. height: auto;
  785. }
  786. .goods-pros-t{
  787. display: flex;
  788. align-items: center;
  789. width: 100%;
  790. height: 210rpx;
  791. padding:0 0 26rpx 0;
  792. .checkbox-box{
  793. padding: 10rpx;
  794. }
  795. .pros-img{
  796. width: 210rpx;
  797. height: 100%;
  798. border-radius: 10rpx;
  799. margin:0 20rpx;
  800. border:1px solid #f3f3f3;
  801. image{
  802. width: 100%;
  803. height: 100%;
  804. border-radius: 10rpx;
  805. }
  806. }
  807. }
  808. .goods-pros-b{
  809. width:622rpx;
  810. margin-left: 84rpx;
  811. height: 40rpx;
  812. padding:0 0 26rpx 0;
  813. // border-top: 1px solid #EBEBEB;
  814. &.show{
  815. display: block;
  816. }
  817. &.none{
  818. display: none;
  819. }
  820. .sum{
  821. font-size: $font-size-28;
  822. line-height: 40rpx;
  823. color: $text-color;
  824. display: flex;
  825. justify-content: flex-end;
  826. .money{
  827. color: #FF2A2A;
  828. font-size: $font-size-28;
  829. }
  830. .money-sign{
  831. font-size: $font-size-24;
  832. color: #FF2A2A;
  833. }
  834. }
  835. }
  836. .pros-product{
  837. width: 402rpx;
  838. height: 100%;
  839. line-height: 36rpx;
  840. font-size: $font-size-28;
  841. position: relative;
  842. .producttitle{
  843. width: 100%;
  844. display: inline-block;
  845. height: auto;
  846. text-overflow:ellipsis;
  847. display: -webkit-box;
  848. word-break: break-all;
  849. -webkit-box-orient: vertical;
  850. -webkit-line-clamp: 2;
  851. overflow: hidden;
  852. margin-bottom: 8rpx;
  853. .no-text{
  854. display: inline-block;
  855. height:36rpx;
  856. padding: 0 12rpx;
  857. line-height: 36rpx;
  858. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  859. border-radius:18rpx;
  860. text-align: center;
  861. color: #FFFFFF;
  862. font-size:$font-size-28;
  863. margin-right: 24rpx;
  864. }
  865. }
  866. .productspec{
  867. height: 36rpx;
  868. color: #999999;
  869. font-size: $font-size-26;
  870. }
  871. .productprice{
  872. height: 48rpx;
  873. position: absolute;
  874. width: 100%;
  875. bottom: 0;
  876. .price{
  877. line-height: 48rpx;
  878. font-size: $font-size-28;
  879. width: 48%;
  880. color: #FF2A2A;
  881. float: left;
  882. &.disabled{
  883. color: #999999;
  884. }
  885. .money-sign{
  886. font-size: $font-size-24;
  887. color: #FF2A2A;
  888. }
  889. }
  890. .count{
  891. height: 100%;
  892. float: right;
  893. position: relative;
  894. &.show{
  895. display: block;
  896. }
  897. &.none{
  898. display: none;
  899. }
  900. .number-box{
  901. display: flex;
  902. justify-content: center;
  903. align-items: center;
  904. .iconfont{
  905. font-size: $font-size-24;
  906. padding:0 20rpx;
  907. color: $text-color;
  908. text-align: center;
  909. line-height: 48rpx;
  910. font-weight: bold;
  911. }
  912. .btn-input{
  913. width: 62rpx;
  914. height: 48rpx;
  915. line-height: 48rpx;
  916. background: #F8F8F8;
  917. border-radius: 4rpx;
  918. text-align: center;
  919. font-size: $font-size-24;
  920. }
  921. }
  922. .uni-numbox{
  923. position: absolute;
  924. left: 45rpx;
  925. bottom: 0;
  926. .uni-numbox-minus, .uni-numbox-plus{
  927. width: 50rpx;
  928. line-height: 40rpx;
  929. }
  930. .uni-numbox-value {
  931. font-size: $font-size-28;
  932. width: 60rpx;
  933. }
  934. }
  935. }
  936. }
  937. }
  938. }
  939. .failure-list{
  940. width: 702rpx;
  941. height: auto;
  942. padding: 0 24rpx;
  943. margin-top: 20rpx;
  944. background: #FFFFFF;
  945. .failure-title{
  946. width: 100%;
  947. height: 80rpx;
  948. line-height: 80rpx;
  949. font-size: $font-size-28;
  950. border-bottom: 1px solid #EBEBEB;
  951. .title-txt{
  952. float: left;
  953. color: $text-color;
  954. text-align: left;
  955. }
  956. .title-btn{
  957. float: right;
  958. color: $color-system;
  959. text-align: right;
  960. }
  961. }
  962. .productlist{
  963. padding-top: 10rpx;
  964. .goods-pros{
  965. width: 100%;
  966. height: auto;
  967. padding: 20rpx 0;
  968. }
  969. .goods-pros-t{
  970. display: flex;
  971. align-items: center;
  972. width: 100%;
  973. height: 210rpx;
  974. position: relative;
  975. .checkbox-box{
  976. padding: 10rpx;
  977. }
  978. .pros-img{
  979. width: 210rpx;
  980. height: 100%;
  981. border-radius: 10rpx;
  982. margin:0 20rpx;
  983. border:1px solid #f3f3f3;
  984. position: relative;
  985. .img-tip{
  986. display: block;
  987. width: 72rpx;
  988. height: 36rpx;
  989. line-height: 36rpx;
  990. font-size: $font-size-24;
  991. text-align: center;
  992. color: #FFFFFF;
  993. border-radius: 10rpx 0 10rpx 0;
  994. background:linear-gradient(34deg,rgba(255,149,42,1) 0%,rgba(225,86,22,1) 100%);
  995. position: absolute;
  996. left: 0;
  997. top: 0;
  998. }
  999. image{
  1000. width: 100%;
  1001. height: 100%;
  1002. border-radius: 10rpx;
  1003. }
  1004. }
  1005. .pros-marks{
  1006. width: 722rpx; height: 250rpx;
  1007. z-index: 8888;
  1008. background: rgba(0,0,0,.05);
  1009. position: absolute;
  1010. left:0;
  1011. top: -20rpx;
  1012. }
  1013. }
  1014. .goods-pros-b{
  1015. width:622rpx;
  1016. margin-left: 84rpx;
  1017. height: 40rpx;
  1018. padding:0 0 26rpx 0;
  1019. // border-top: 1px solid #EBEBEB;
  1020. &.show{
  1021. display: block;
  1022. }
  1023. &.none{
  1024. display: none;
  1025. }
  1026. .sum{
  1027. font-size: $font-size-28;
  1028. line-height: 40rpx;
  1029. color: $text-color;
  1030. display: flex;
  1031. justify-content: flex-end;
  1032. .money{
  1033. color: #FF2A2A;
  1034. font-size: $font-size-28;
  1035. }
  1036. .money-sign{
  1037. font-size: $font-size-24;
  1038. color: #FF2A2A;
  1039. }
  1040. }
  1041. }
  1042. .pros-product{
  1043. width: 402rpx;
  1044. height: 100%;
  1045. line-height: 36rpx;
  1046. font-size: $font-size-28;
  1047. position: relative;
  1048. .producttitle{
  1049. width: 100%;
  1050. display: inline-block;
  1051. height: auto;
  1052. text-overflow:ellipsis;
  1053. display: -webkit-box;
  1054. word-break: break-all;
  1055. -webkit-box-orient: vertical;
  1056. -webkit-line-clamp: 2;
  1057. overflow: hidden;
  1058. margin-bottom: 8rpx;
  1059. .no-text{
  1060. display: inline-block;
  1061. height:36rpx;
  1062. padding: 0 12rpx;
  1063. line-height: 36rpx;
  1064. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  1065. border-radius:18rpx;
  1066. text-align: center;
  1067. color: #FFFFFF;
  1068. font-size: $font-size-28;
  1069. margin-right: 24rpx;
  1070. }
  1071. }
  1072. .productspec{
  1073. height: 36rpx;
  1074. color: #999999;
  1075. font-size: $font-size-26;
  1076. }
  1077. .productstate{
  1078. font-size: $font-size-28;
  1079. height: 44rpx;
  1080. color: #FF2A2A;
  1081. position: absolute;
  1082. bottom: 0;
  1083. left: 0;
  1084. }
  1085. }
  1086. }
  1087. }
  1088. .footer{
  1089. width: 100%;
  1090. background-color: #FFFFFF;
  1091. height: 110rpx;
  1092. position: fixed;
  1093. bottom: 0rpx;
  1094. z-index: 10;
  1095. .footer-le{
  1096. width: 490rpx;
  1097. height: 100%;
  1098. padding:0 30rpx;
  1099. float: left;
  1100. .text{
  1101. font-weight: bold;
  1102. }
  1103. .foot-check{
  1104. width: 100rpx;
  1105. float: left;
  1106. line-height: 110rpx;
  1107. font-size: $font-size-24;
  1108. .checkbox{
  1109. width: 40rpx;
  1110. text-align: center;
  1111. }
  1112. .text{
  1113. width: 60rpx;
  1114. float: right;
  1115. }
  1116. }
  1117. .foot-check-delbtn{
  1118. float: left;
  1119. .delBtn{
  1120. margin: 0;
  1121. padding: 0;
  1122. display: flex;
  1123. flex-direction: column;
  1124. align-items: center;
  1125. box-sizing: border-box;
  1126. font-size: $font-size-24;
  1127. text-align: center;
  1128. text-decoration: none;
  1129. border-radius: 0;
  1130. -webkit-tap-highlight-color: transparent;
  1131. overflow: hidden;
  1132. background-color:#FFFFFF;
  1133. color: #FF2A2A;
  1134. padding: 0 24rpx;
  1135. display: flex;
  1136. justify-content: center;
  1137. align-items: center;
  1138. line-height: 110rpx;
  1139. font-weight: bold;
  1140. &.none{
  1141. display: none;
  1142. }
  1143. }
  1144. }
  1145. .sum{
  1146. font-size: $font-size-28;
  1147. line-height: 110rpx;
  1148. color: $text-color;
  1149. display: flex;
  1150. justify-content: flex-end;
  1151. .money{
  1152. color: #FF2A2A;
  1153. }
  1154. .money-sign{
  1155. font-size: $font-size-24;
  1156. color: #FF2A2A;
  1157. }
  1158. }
  1159. }
  1160. .footer-ri{
  1161. width: 200rpx;
  1162. height: 100%;
  1163. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  1164. float: right;
  1165. display: flex;
  1166. justify-content: space-between;
  1167. align-items: center;
  1168. z-index: 999;
  1169. &.none{
  1170. display: none;
  1171. }
  1172. .btn{
  1173. width: 200rpx;
  1174. height: 100%;
  1175. font-size: $font-size-28;
  1176. line-height: 110rpx;
  1177. color: #FFFFFF;
  1178. display: flex;
  1179. justify-content: center;
  1180. align-items: center;
  1181. }
  1182. }
  1183. .footer-del{
  1184. width: 400rpx;
  1185. height: 110rpx;
  1186. position: absolute;
  1187. padding-left: 200rpx;
  1188. background: #FFFFFF;
  1189. right: 0;
  1190. top: 0;
  1191. z-index: 1000;
  1192. &.show{
  1193. animation: showDelbtn 0s linear both;
  1194. }
  1195. &.none{
  1196. animation: hideDelbtn 0s linear both;
  1197. }
  1198. .btn{
  1199. width: 50%;
  1200. height: 100%;
  1201. line-height: 110rpx;
  1202. font-size: $font-size-28;
  1203. color: #FFFFFF;
  1204. text-align: center;
  1205. float: left;
  1206. }
  1207. .btn.btn-cancel{
  1208. background:#EEC1AB;
  1209. }
  1210. .btn.btn-confirm{
  1211. background:#FF2A2A;
  1212. }
  1213. @keyframes showDelbtn {
  1214. 0% {
  1215. transform: translateX(0);
  1216. }
  1217. 100% {
  1218. transform: translateX(-100%);
  1219. }
  1220. }
  1221. @keyframes hideDelbtn {
  1222. 0% {
  1223. transform: translateX(-100%);
  1224. }
  1225. 100% {
  1226. transform: translateX(0);
  1227. }
  1228. }
  1229. }
  1230. }
  1231. </style>