cart.vue 37 KB

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