cart.vue 36 KB

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