cart.vue 36 KB

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