cart.vue 27 KB

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