cart.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  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">
  6. <view v-if="!isEmpty" class="container-cart">
  7. <scroll-view class="cart-content" scroll-y @scrolltolower="toLower">
  8. <view class="goods-list">
  9. <view v-for="(item, index) in goodsList" :key="index" class="goods-item">
  10. <view class="shoptitle">
  11. <!--选择商店的全部商品"-->
  12. <view class="checkbox-box" @click.stop="checkShop(item)">
  13. <button class="checkbox iconfont"
  14. :class="[item.checked ?'icon-gouxuanl':'icon-weigouxuan']"
  15. :disabled="item.isDisabled && !isshowDelbtn">
  16. </button>
  17. </view>
  18. <view class="text">{{item.name}}</view>
  19. </view>
  20. <view class="productlist">
  21. <view class="goods-pros" v-for="(pros,idx) in item.productsList" :key="idx" >
  22. <view class="goods-pros-t">
  23. <!--选择商品-->
  24. <view class="checkbox-box" @click.stop="ischeck(item,pros,idx)" :class="[pros.validFlag == '3' && !isshowDelbtn ?'disabled' : '']">
  25. <button class="checkbox iconfont"
  26. :disabled="pros.validFlag == '3' && !isshowDelbtn"
  27. :class="[pros.productsChecked ?'icon-gouxuanl':'icon-weigouxuan']">
  28. </button>
  29. </view>
  30. <view class="pros-img" @click.stop="navToListPage(pros.productID)" ><image :src="pros.mainImage ? pros.mainImage:''" alt="" /></view>
  31. <view class="pros-product">
  32. <view class="producttitle" @click.stop="navToListPage(pros.productID)" >
  33. <text v-if="pros.validFlag == '3'" class="no-text">商品已下架</text>{{pros.name}}
  34. </view>
  35. <view class="productspec">规格:{{pros.unit ? pros.unit : ''}}</view>
  36. <view class="productprice">
  37. <!--使用过滤器对总价改变-->
  38. <view class="price" :class="[pros.validFlag == '3' ?'disabled' : '']">
  39. <text :class="[pros.validFlag == '3' ?'disabled' : 'money-sign']">¥</text>
  40. {{pros.retailPrice?pros.retailPrice.toFixed(2):''}}
  41. </view>
  42. <view class="count" v-if="pros.validFlag == '2'" :class="[isshowDelbtn ? 'none':'show']">
  43. <view class="number-box">
  44. <view class="iconfont icon-jianhao" :class="[pros.validFlag == '3'?'disabled':'']" @click="changeCountSub(item,pros)"></view>
  45. <input class="btn-input" type="number" maxlength='4' v-model="pros.productCount" @blur="changeNnmber($event,item,pros)">
  46. <view class="iconfont icon-jiahao" :class="[pros.validFlag == '3'?'disabled':'']" @click="changeCountAdd(item,pros)"></view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="goods-pros-b" :class="[isshowDelbtn ? 'none':'show']" >
  55. <view class="sum">合计:<text class="money"><text class="money-sign">¥</text>{{item.totalPrice.toFixed(2)}}</text></view>
  56. </view>
  57. </view>
  58. </view>
  59. <!--加载loadding-->
  60. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  61. <tui-nomore :visible="!pullUpOn" bgcolor="#F7F7F7" :text='nomoreText'></tui-nomore>
  62. <!--加载loadding-->
  63. </scroll-view>
  64. <!-- 脚部菜单 -->
  65. <view class="footer" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
  66. <view class="footer-le">
  67. <view class="foot-check checkbox-box" @tap.stop="checkAll()">
  68. <button class="checkbox iconfont" :class="[isCheckAll?'icon-gouxuan':'icon-weigouxuan']"></button>
  69. <view class="text">全选</view>
  70. </view>
  71. <view class="foot-check-delbtn">
  72. <button class="delBtn" @tap.stop="showDelManager">删除</button>
  73. </view>
  74. <view class="sum">总价:<text class="money-sign">¥</text><text class="money">{{allPrice.toFixed(2)}}</text></view>
  75. </view>
  76. <view v-if="!isshowDelbtn" class="footer-ri" >
  77. <view class="btn" @tap="toConfirmation">去结算({{allCount}})</view>
  78. </view>
  79. <view v-else class="footer-del">
  80. <view class="btn btn-cancel" @tap.stop="hideDelManage">取消</view>
  81. <view class="btn btn-confirm" @tap.stop="deleteList">删除</view>
  82. </view>
  83. </view>
  84. </view>
  85. <view v-if="isEmpty" class="cart-content empty">
  86. <view class="empty-container">
  87. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  88. <text class="error-text">购物车空空如也,快去商城逛逛吧~</text>
  89. <view class="login-btn" @click="goIndex">去商城</view>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 透明模态层 -->
  94. <modal-layer v-if='modallayer'></modal-layer>
  95. </view>
  96. </template>
  97. <script>
  98. import authorize from '@/common/config/authorize.js'
  99. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  100. import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
  101. import tuiNomore from "@/components/tui-components/nomore/nomore"
  102. import headerNavbar from "@/components/cm-module/headerNavbar/headerNavbar.vue" //顶部自定义胶囊'
  103. import modalLayer from "@/components/modal-layer"
  104. import { mapState,mapMutations } from 'vuex';
  105. import { queryShoppingCartList,shoppingCartUpdate,shoppingCartDelete } from "@/api/cart.js"
  106. export default{
  107. components:{
  108. headerNavbar,
  109. tuiSkeleton,
  110. tuiLoadmore,
  111. tuiNomore,
  112. modalLayer
  113. },
  114. data(){
  115. return{
  116. nvabarData: {//顶部自定义导航
  117. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  118. showSearch: 0,
  119. title: '购物车', // 导航栏 中间的标题
  120. },
  121. headerBtnPosi: this.setHeaderBtnPosi(),//获取设备顶部胶囊高度
  122. systeminfo:this.setSysteminfo(), //获取设备信息
  123. CustomBar:this.CustomBar,// 顶部导航栏高度
  124. isIphoneX:this.$store.state.isIphoneX,
  125. pathType:'',
  126. pathProductID:'',
  127. userID:'',
  128. alertType:'',
  129. isStock:'',
  130. goodsList:[], //购物车的商品
  131. delGoodsList:'',//要删除的商品
  132. setGoodData:'', //确认订单的商品
  133. isCheckAll:false,//是否全选
  134. allPrice:0,//所有价格
  135. allCount:0,//被选中的产品数量
  136. isNnder:true,
  137. isModallayer:false,
  138. skeletonShow:true,
  139. isshowDelbtn:false,
  140. isDisabled: false, // 供应商/店铺全选是否禁用状态
  141. isEmpty:false,//显示空购物车
  142. scrollHeight: 'auto',
  143. nomoreText: '上拉显示更多',
  144. hasNextPage: false,
  145. loadding: false,
  146. pullUpOn: true,
  147. pullFlag: true,
  148. pageSize: 10,
  149. pageNum: 1,
  150. }
  151. },
  152. onLoad(){
  153. this.pathType = this.$getStorage("cartPathType");
  154. this.pathProductID = this.$getStorage("cartPathId");
  155. if(this.pathType){
  156. this.nvabarData.haveBack = true
  157. }else{
  158. this.nvabarData.haveBack = false
  159. }
  160. this.setScrollHeight();
  161. },
  162. computed: {
  163. ...mapState(['hasLogin','userInfo'])
  164. },
  165. filters:{//单件商品的价格 × 数量
  166. totalprice(val,count){
  167. return (val * count).toFixed(2)
  168. }
  169. },
  170. methods:{
  171. initData(){
  172. this.isModallayer = false //遮罩层 防止多次点击
  173. this.skeletonShow = true //预加载圆圈
  174. this.isCheckAll=false//是否全选
  175. this.$api.getStorage().then((resolve) => {
  176. this.userID = resolve.userID;
  177. this.initGetCartGoodsList();
  178. })
  179. },
  180. initLogin(){
  181. authorize.getSetting().then(wxResponse =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  182. if(wxResponse == 1){
  183. this.$api.redirectTo('/pages/login/login?type=4')
  184. }else{
  185. this.$api.navigateTo('/pages/authorization/authorization?type=0')
  186. }
  187. })
  188. },
  189. setScrollHeight() {
  190. // 窗口高度-footer高度
  191. const {windowHeight, pixelRatio} = uni.getSystemInfoSync();
  192. setTimeout(()=> {
  193. const query = uni.createSelectorQuery().in(this);
  194. query.selectAll('.footer').boundingClientRect();
  195. query.exec(res => {
  196. this.windowHeight = windowHeight;
  197. if(res[0][0]) {
  198. this.scrollHeight = windowHeight - res[0][0].height;
  199. }
  200. })
  201. }, 500)
  202. },
  203. setHeaderBtnPosi(){
  204. // 获得胶囊按钮位置信息
  205. let headerBtnPosi = uni.getMenuButtonBoundingClientRect();
  206. return headerBtnPosi
  207. },
  208. setSysteminfo(){
  209. let systeminfo;
  210. uni.getSystemInfo({ // 获取设备信息
  211. success: (res) => {
  212. systeminfo = res
  213. },
  214. })
  215. return systeminfo
  216. },
  217. initGetCartGoodsList(){//初始化购物车 index:1
  218. let params = {userID:this.userID,pageNum:1,pageSize:this.pageSize}
  219. queryShoppingCartList(params).then(response =>{
  220. this.skeletonShow = false
  221. this.$store.commit('updateAllNum',response.data.cartQuantity)
  222. const resultsData = response.data.pageDate;
  223. if(resultsData.results&&resultsData.results.length > 0){
  224. this.isEmpty =false
  225. this.hasNextPage = resultsData.hasNextPage;
  226. this.goodsList = resultsData.results;
  227. this.goodsList.forEach((item,index) => {
  228. let productsListLength = item.productsList.length,
  229. invalidLength = 0;
  230. item.productsList.forEach(pros => {
  231. pros.shopID = item.shopID;
  232. if(pros.validFlag == '3' ) {invalidLength++;}
  233. })
  234. item.isDisabled = invalidLength === productsListLength;
  235. })
  236. this.pullFlag = false;
  237. setTimeout(()=>{this.pullFlag = true;},500)
  238. if(this.hasNextPage){
  239. this.pullUpOn = false
  240. this.nomoreText = '上拉显示更多'
  241. }else{
  242. if(this.goodsList.length < 4){
  243. this.pullUpOn = true
  244. }else{
  245. this.pullUpOn = false
  246. this.nomoreText = '已至底部'
  247. }
  248. }
  249. } else {
  250. this.goodsList = [];
  251. this.isEmpty =true
  252. }
  253. }).catch(error =>{
  254. this.$util.msg(error.msg,2000);
  255. })
  256. },
  257. getOnReachBottomData(){//上拉加载
  258. this.pageNum+=1
  259. let params = {userID:this.userID,pageNum:this.pageNum,pageSize:this.pageSize}
  260. queryShoppingCartList(params).then(response =>{
  261. let resultsData = response.data.pageDate
  262. this.hasNextPage = resultsData.hasNextPage;
  263. this.goodsList = this.goodsList.concat(resultsData.results)
  264. this.pullFlag = false;// 防上拉暴滑
  265. setTimeout(()=>{this.pullFlag = true;},500)
  266. if(this.hasNextPage){
  267. this.pullUpOn = false
  268. this.nomoreText = '上拉显示更多'
  269. }else{
  270. this.loadding = false
  271. this.pullUpOn = false
  272. this.nomoreText = '已至底部'
  273. }
  274. }).catch(error =>{
  275. this.$util.msg(error.msg,2000);
  276. })
  277. },
  278. ischeck(item,pro){//为未选中的时候改变为true,反之为true
  279. pro.productsChecked = !pro.productsChecked;
  280. this.updateProductCheckedAllBtn(item);
  281. this.updateCheckAllBtn();
  282. },
  283. updateProductCheckedAllBtn(item) {// 单独每个供应商的勾选判断
  284. let productsList = item.productsList,
  285. productsCheckedLength = 0,
  286. disabledLength = 0;
  287. if(this.isshowDelbtn) {
  288. productsList.forEach(pros => {
  289. if(pros.productsChecked) {
  290. productsCheckedLength++;
  291. }
  292. })
  293. } else {
  294. productsList.forEach(pros => {
  295. if(pros.productsChecked && pros.validFlag != '3') {
  296. productsCheckedLength++;
  297. }
  298. if(pros.validFlag == '3') {disabledLength++;}
  299. })
  300. }
  301. item.checked = productsCheckedLength === productsList.length - disabledLength;
  302. },
  303. updateCheckAllBtn() {// 全选勾选判断
  304. let goodsCheckedLength = 0,
  305. disabledListLength = 0,
  306. goodsList = this.goodsList;
  307. goodsList.forEach(item => {
  308. if(item.checked) {
  309. goodsCheckedLength++;
  310. }
  311. if(item.isDisabled && !this.isshowDelbtn) {
  312. disabledListLength++;
  313. }
  314. })
  315. this.isCheckAll = goodsCheckedLength === goodsList.length - disabledListLength;
  316. },
  317. checkShop(item){//与单选商品类似
  318. item.checked = !item.checked;
  319. this.setProductChecked(item);
  320. this.updateCheckAllBtn();
  321. },
  322. setProductChecked(item) {
  323. let products = item.productsList;
  324. products.forEach(pros=>{
  325. if(item.checked) {
  326. if(pros.validFlag =='3'){
  327. // 无效
  328. this.isNnder = true;
  329. pros.productsChecked = this.isshowDelbtn ?true :false;
  330. }else{
  331. // 有效
  332. this.isNnder = false;
  333. pros.productsChecked = true;
  334. }
  335. } else {
  336. pros.productsChecked = false;
  337. }
  338. })
  339. },
  340. updateBothCheckBtn() {
  341. if(this.isshowDelbtn) {
  342. // 当管理删除按钮出现时,失效的商品可被选择
  343. this.goodsList.forEach((item)=>{
  344. item.checked = this.isCheckAll;
  345. this.setProductChecked(item);
  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 prosPrice=0;
  360. let validPrice =0;
  361. let validList=[];
  362. let productsList=[];
  363. this.goodsList.map((item,index)=>{
  364. productsList=item.productsList;
  365. prosPrice=productsList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  366. productsList.forEach(pros =>{
  367. if(pros.validFlag =='3'){
  368. validList.push(pros)
  369. validPrice = validList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  370. item.totalPrice = prosPrice - validPrice
  371. }else{
  372. item.totalPrice = prosPrice
  373. }
  374. })
  375. })
  376. },
  377. totalPeice(){ //计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
  378. this.allPrice = 0
  379. let prosPrice=0;
  380. let validPrice=0;
  381. let validList =[];
  382. let productsList =[];
  383. this.goodsList.forEach((item,index)=>{
  384. productsList=item.productsList;
  385. productsList.forEach(pros=>{
  386. if(pros.productsChecked){
  387. prosPrice+=pros.retailPrice*pros.productCount;
  388. if(pros.validFlag =='3'){
  389. validList.push(pros)
  390. validPrice = validList.reduce((p,e)=>p+e.retailPrice*e.productCount,0);
  391. this.allPrice = prosPrice - validPrice
  392. }else{
  393. this.allPrice = prosPrice
  394. }
  395. }
  396. })
  397. })
  398. },
  399. totalCount(){//计算总数量
  400. this.allCount = 0
  401. let prosAllCount=0
  402. let validCount = 0
  403. let validList =[];
  404. let productsList =[];
  405. this.goodsList.forEach(item=>{
  406. productsList = item.productsList
  407. productsList.forEach(pros=>{
  408. if(pros.productsChecked){
  409. prosAllCount+=parseInt(pros.productCount);
  410. if(pros.validFlag =='3'){
  411. validList.push(pros)
  412. validList.forEach(val =>{
  413. validCount += val.productCount
  414. })
  415. this.allCount = prosAllCount - validCount
  416. }else{
  417. this.allCount = prosAllCount
  418. }
  419. }
  420. })
  421. })
  422. },
  423. changeCountAdd(item,pros){//商品数量加加
  424. if(pros.productCount>=pros.stock){
  425. pros.productCount= pros.stock
  426. this.isStock =true
  427. return
  428. }else{
  429. pros.productCount++
  430. this.processActivityPrice(pros)
  431. this.isStock =false
  432. }
  433. this.updateShoppogNum(pros)
  434. this.totalShopPeice();
  435. },
  436. changeCountSub(item,pros){//商品数量减减
  437. if(pros.productCount<=pros.minBuyNumber){
  438. pros.productCount= pros.minBuyNumber
  439. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  440. return
  441. }else{
  442. pros.productCount--
  443. this.processActivityPrice(pros)
  444. }
  445. this.updateShoppogNum(pros)
  446. this.totalShopPeice();
  447. },
  448. changeNnmber(e,item,pros){//输入商品数量更新
  449. let _value = e.detail.value;
  450. if(!this.$api.isNumber(_value)){
  451. pros.productCount = pros.minBuyNumber
  452. }else if(_value < pros.minBuyNumber){
  453. this.$util.msg(`该商品最小起订量为${pros.minBuyNumber}`,2000);
  454. pros.productCount = pros.minBuyNumber
  455. }else{
  456. pros.productCount = e.detail.value
  457. this.processActivityPrice(pros)
  458. }
  459. this.updateShoppogNum(pros)
  460. this.totalShopPeice();
  461. },
  462. processActivityPrice(pros){//单独处理活动价格和阶梯价格
  463. let ladderPriceList = pros.ladderPriceList;
  464. if(pros.ladderPriceFlag == '0' || pros.actStatus == 1){
  465. pros.retailPrice = pros.retailPrice
  466. }else{
  467. ladderPriceList.forEach((item,index)=>{
  468. if(pros.productCount>=item.buyNum){
  469. pros.retailPrice = item.buyPrice
  470. }
  471. })
  472. }
  473. },
  474. updateShoppogNum(pros){//加减购物车商品更新到后台
  475. let params ={userID:this.userID,productID:pros.productID,productCount:pros.productCount}
  476. shoppingCartUpdate(params).then(response =>{
  477. this.isshowDelbtn = false;
  478. this.initGetCartGoodsList();
  479. }).catch(error =>{
  480. this.$util.msg(error.msg,2000);
  481. })
  482. },
  483. toConfirmation(){//跳转确认订单页面
  484. let setGoodsList=[];
  485. this.goodsList.forEach(res=>{
  486. let products = res.productsList
  487. products.forEach(pros=>{
  488. if(pros.productsChecked){
  489. setGoodsList.push(pros.productID)
  490. }
  491. })
  492. })
  493. if(setGoodsList == ''){
  494. this.$util.msg("请先选择结算商品~",2000);
  495. return
  496. }else{
  497. /**
  498. * @获取勾选的商品ID拼接字符串逗号隔开,最后一个逗号去掉
  499. * @获取勾选的商品分类ID拼接字符串格式逗号隔开,最后一个逗号去掉
  500. */
  501. let productID = '';
  502. this.goodsList.forEach(el=>{
  503. el.productsList.forEach(pros=>{
  504. if(pros.productsChecked){
  505. productID += pros.productID+','
  506. }
  507. })
  508. })
  509. let cartPramsData={
  510. allPrice:this.allPrice,
  511. allCount:this.allCount,
  512. productID:productID.substring(0,productID.lastIndexOf(',')),
  513. productCount:''
  514. }
  515. this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({data:cartPramsData})}`)
  516. }
  517. },
  518. showDelManager(){//显示删除商品管理
  519. this.isshowDelbtn = true;
  520. this.isNnder = true;
  521. if(this.isCheckAll) {
  522. this.updateBothCheckBtn();
  523. } else {
  524. // 失效也被勾选
  525. this.goodsList.forEach(item => {
  526. if(item.checked) {
  527. item.productsList.forEach(pros => {
  528. pros.productsChecked = true;
  529. })
  530. }
  531. })
  532. this.updateCheckAllBtn();
  533. }
  534. },
  535. hideDelManage(){//隐藏删除商品管理
  536. this.isshowDelbtn = false;
  537. if(this.isCheckAll) {
  538. this.updateBothCheckBtn();
  539. } else {
  540. // 失效商品取消勾选
  541. this.goodsList.forEach(item => {
  542. if(item.isDisabled) {
  543. item.checked = false;
  544. }
  545. item.productsList.forEach(pros => {
  546. if(pros.validFlag == '3') {
  547. pros.productsChecked = false;
  548. }
  549. })
  550. })
  551. this.updateCheckAllBtn();
  552. }
  553. },
  554. deleteList(){//删除购物车商品
  555. this.delGoodsList=[];
  556. this.goodsList.forEach(delitem=>{
  557. let products = delitem.productsList
  558. products.forEach(pros=>{
  559. if(pros.productsChecked){
  560. this.delGoodsList += pros.productID+','
  561. }
  562. })
  563. })
  564. if(this.delGoodsList.length == 0){
  565. this.$util.msg("请选择要删除的商品~",2000);
  566. return
  567. }else{
  568. this.$util.modal('','确定删除选中的商品吗?','确定','取消',true,() =>{
  569. shoppingCartDelete({userID:this.userID,productIDs:this.delGoodsList}).then(response =>{
  570. this.$util.msg('删除成功',2000);
  571. setTimeout(()=>{
  572. this.isshowDelbtn = false;
  573. this.initGetCartGoodsList();
  574. },2000)
  575. }).catch(error =>{
  576. this.$util.msg(error.msg,2000)
  577. })
  578. })
  579. }
  580. },
  581. goIndex(){
  582. uni.switchTab({
  583. url: '/pages/tabBar/home/home'
  584. });
  585. },
  586. goNavto(url){
  587. uni.navigateTo ({
  588. url
  589. })
  590. },
  591. navToListPage(id){
  592. this.isModallayer = true;
  593. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  594. }
  595. },
  596. watch:{//深度监听所有数据,每次改变重新计算总价和总数
  597. goodsList:{
  598. deep:true,
  599. handler(val,oldval){
  600. this.totalPeice()
  601. this.totalCount()
  602. }
  603. }
  604. },
  605. onReachBottom() {
  606. if(this.hasNextPage){
  607. this.loadding = true
  608. this.pullUpOn = true
  609. this.getOnReachBottomData()
  610. }
  611. },
  612. onPullDownRefresh() {//下拉刷新
  613. this.initGetCartGoodsList()
  614. uni.stopPullDownRefresh()
  615. },
  616. onShow(){
  617. if(this.hasLogin){
  618. this.initData()
  619. }else{
  620. this.initLogin()
  621. }
  622. },
  623. }
  624. </script>
  625. <style lang="scss">
  626. page{
  627. background: #f7f7f7;
  628. height: auto;
  629. }
  630. .cart-content{
  631. position: relative;
  632. padding-bottom:74rpx;
  633. }
  634. .container-cart-main.none{
  635. display: none;
  636. }
  637. .container-cart-main.show{
  638. display: block;
  639. }
  640. .cart-content.empty.none{
  641. display: none;
  642. }
  643. .cart-content.empty.show{
  644. display: block;
  645. }
  646. .container-cart.show{
  647. display: block;
  648. }
  649. .container-cart.none{
  650. display: none;
  651. }
  652. .empty-container.none{
  653. display: none;
  654. }
  655. .empty-container.show{
  656. display: flex;
  657. }
  658. .checkbox-box{
  659. display: flex;
  660. align-items: center;
  661. .checkbox{
  662. display: flex;
  663. margin: 0;
  664. padding: 0;
  665. display: flex;
  666. flex-direction: column;
  667. align-items: center;
  668. box-sizing: border-box;
  669. text-align: center;
  670. text-decoration: none;
  671. border-radius: 0;
  672. -webkit-tap-highlight-color: transparent;
  673. overflow: hidden;
  674. background-color:#FFFFFF;
  675. font-size: 36rpx;
  676. color:$color-system;
  677. }
  678. &.disabled{
  679. .checkbox{
  680. color:#999999
  681. }
  682. }
  683. .text{
  684. font-size: $font-size-24;
  685. margin-left: 10rpx;
  686. }
  687. }
  688. .goods-list{
  689. width: 100%;
  690. height: auto;
  691. border-top: 1px solid #EBEBEB;
  692. background-color: #F7F7F7;
  693. .goods-item{
  694. width: 702rpx;
  695. padding: 0 24rpx;
  696. background: #FFFFFF;
  697. margin-bottom: 24rpx;
  698. }
  699. .shoptitle{
  700. display: flex;
  701. align-items: center;
  702. height: 80rpx;
  703. // border-bottom: 1px solid #EBEBEB;
  704. line-height: 80rpx;
  705. .checkbox-box{
  706. padding: 10rpx;
  707. }
  708. .text{
  709. margin-left: 37rpx;
  710. font-size: $font-size-28;
  711. color: $text-color;
  712. text-align: left;
  713. font-weight: bold;
  714. }
  715. }
  716. .goods-pros{
  717. width: 100%;
  718. height: auto;
  719. }
  720. .goods-pros-t{
  721. display: flex;
  722. align-items: center;
  723. width: 100%;
  724. height: 217rpx;
  725. padding:0 0 26rpx 0;
  726. .checkbox-box{
  727. padding: 10rpx;
  728. }
  729. .pros-img{
  730. width: 210rpx;
  731. height: 100%;
  732. border-radius: 10rpx;
  733. margin:0 26rpx 0 38rpx;
  734. border:1px solid #f3f3f3;
  735. image{
  736. width: 100%;
  737. height: 100%;
  738. border-radius: 10rpx;
  739. }
  740. }
  741. }
  742. .goods-pros-b{
  743. width:622rpx;
  744. margin-left: 84rpx;
  745. height: 40rpx;
  746. padding:0 0 26rpx 0;
  747. // border-top: 1px solid #EBEBEB;
  748. &.show{
  749. display: block;
  750. }
  751. &.none{
  752. display: none;
  753. }
  754. .sum{
  755. font-size: $font-size-28;
  756. line-height: 40rpx;
  757. color: $text-color;
  758. display: flex;
  759. justify-content: flex-end;
  760. .money{
  761. color: #FF2A2A;
  762. font-size: $font-size-28;
  763. }
  764. .money-sign{
  765. font-size: $font-size-24;
  766. color: #FF2A2A;
  767. }
  768. }
  769. }
  770. .pros-product{
  771. width: 386rpx;
  772. height: 100%;
  773. line-height: 36rpx;
  774. font-size: $font-size-26;
  775. position: relative;
  776. .producttitle{
  777. width: 100%;
  778. display: inline-block;
  779. height: auto;
  780. text-overflow:ellipsis;
  781. display: -webkit-box;
  782. word-break: break-all;
  783. -webkit-box-orient: vertical;
  784. -webkit-line-clamp: 2;
  785. overflow: hidden;
  786. margin-bottom: 8rpx;
  787. .no-text{
  788. display: inline-block;
  789. height:36rpx;
  790. padding: 0 12rpx;
  791. line-height: 36rpx;
  792. background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
  793. border-radius:18rpx;
  794. text-align: center;
  795. color: #FFFFFF;
  796. font-size: $font-size-24;
  797. margin-right: 24rpx;
  798. }
  799. }
  800. .productspec{
  801. height: 36rpx;
  802. color: #999999;
  803. }
  804. .productprice{
  805. height: 48rpx;
  806. position: absolute;
  807. width: 100%;
  808. bottom: 0;
  809. .price{
  810. line-height: 48rpx;
  811. font-size: $font-size-28;
  812. width: 48%;
  813. color: #FF2A2A;
  814. float: left;
  815. &.disabled{
  816. color: #999999;
  817. }
  818. .money-sign{
  819. font-size: $font-size-24;
  820. color: #FF2A2A;
  821. }
  822. }
  823. .count{
  824. height: 100%;
  825. float: right;
  826. position: relative;
  827. &.show{
  828. display: block;
  829. }
  830. &.none{
  831. display: none;
  832. }
  833. .number-box{
  834. display: flex;
  835. justify-content: center;
  836. align-items: center;
  837. .iconfont{
  838. font-size: $font-size-24;
  839. padding:0 20rpx;
  840. color: $text-color;
  841. text-align: center;
  842. line-height: 48rpx;
  843. font-weight: bold;
  844. }
  845. .btn-input{
  846. width: 62rpx;
  847. height: 48rpx;
  848. line-height: 48rpx;
  849. background: #F8F8F8;
  850. border-radius: 4rpx;
  851. text-align: center;
  852. font-size: $font-size-24;
  853. }
  854. }
  855. .uni-numbox{
  856. position: absolute;
  857. left: 45rpx;
  858. bottom: 0;
  859. .uni-numbox-minus, .uni-numbox-plus{
  860. width: 50rpx;
  861. line-height: 40rpx;
  862. }
  863. .uni-numbox-value {
  864. font-size: $font-size-28;
  865. width: 60rpx;
  866. }
  867. }
  868. }
  869. }
  870. }
  871. }
  872. .footer{
  873. width: 100%;
  874. background-color: #FFFFFF;
  875. height: 110rpx;
  876. position: fixed;
  877. bottom: 0rpx;
  878. z-index: 10;
  879. .footer-le{
  880. width: 490rpx;
  881. height: 100%;
  882. padding:0 30rpx;
  883. float: left;
  884. .text{
  885. font-weight: bold;
  886. }
  887. .foot-check{
  888. width: 100rpx;
  889. float: left;
  890. line-height: 110rpx;
  891. font-size: $font-size-24;
  892. .checkbox{
  893. width: 40rpx;
  894. text-align: center;
  895. }
  896. .text{
  897. width: 60rpx;
  898. float: right;
  899. }
  900. }
  901. .foot-check-delbtn{
  902. float: left;
  903. .delBtn{
  904. margin: 0;
  905. padding: 0;
  906. display: flex;
  907. flex-direction: column;
  908. align-items: center;
  909. box-sizing: border-box;
  910. font-size: $font-size-24;
  911. text-align: center;
  912. text-decoration: none;
  913. border-radius: 0;
  914. -webkit-tap-highlight-color: transparent;
  915. overflow: hidden;
  916. background-color:#FFFFFF;
  917. color: #FF2A2A;
  918. padding: 0 24rpx;
  919. display: flex;
  920. justify-content: center;
  921. align-items: center;
  922. line-height: 110rpx;
  923. font-weight: bold;
  924. &.none{
  925. display: none;
  926. }
  927. }
  928. }
  929. .sum{
  930. font-size: $font-size-28;
  931. line-height: 110rpx;
  932. color: $text-color;
  933. display: flex;
  934. justify-content: flex-end;
  935. .money{
  936. color: #FF2A2A;
  937. }
  938. .money-sign{
  939. font-size: $font-size-24;
  940. color: #FF2A2A;
  941. }
  942. }
  943. }
  944. .footer-ri{
  945. width: 200rpx;
  946. height: 100%;
  947. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  948. float: right;
  949. display: flex;
  950. justify-content: space-between;
  951. align-items: center;
  952. z-index: 999;
  953. &.none{
  954. display: none;
  955. }
  956. .btn{
  957. width: 200rpx;
  958. height: 100%;
  959. font-size: $font-size-28;
  960. line-height: 110rpx;
  961. color: #FFFFFF;
  962. display: flex;
  963. justify-content: center;
  964. align-items: center;
  965. }
  966. }
  967. .footer-del{
  968. width: 400rpx;
  969. height: 110rpx;
  970. position: absolute;
  971. padding-left: 200rpx;
  972. background: #FFFFFF;
  973. right: 0;
  974. top: 0;
  975. z-index: 1000;
  976. &.show{
  977. animation: showDelbtn 0s linear both;
  978. }
  979. &.none{
  980. animation: hideDelbtn 0s linear both;
  981. }
  982. .btn{
  983. width: 50%;
  984. height: 100%;
  985. line-height: 110rpx;
  986. font-size: $font-size-28;
  987. color: #FFFFFF;
  988. text-align: center;
  989. float: left;
  990. }
  991. .btn.btn-cancel{
  992. background:#EEC1AB;
  993. }
  994. .btn.btn-confirm{
  995. background:#FF2A2A;
  996. }
  997. @keyframes showDelbtn {
  998. 0% {
  999. transform: translateX(0);
  1000. }
  1001. 100% {
  1002. transform: translateX(-100%);
  1003. }
  1004. }
  1005. @keyframes hideDelbtn {
  1006. 0% {
  1007. transform: translateX(-100%);
  1008. }
  1009. 100% {
  1010. transform: translateX(0);
  1011. }
  1012. }
  1013. }
  1014. }
  1015. </style>