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