cart.vue 36 KB

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