cart.vue 35 KB

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