cart.vue 35 KB

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