<template>
  <div class="shopCar-bottom-bar">
    <div class="bar-left">
		<!-- #ifndef MP-TOUTIAO -->
		
		<!-- #endif -->
    <y-badge :count="carCount">
		  <div class="icon-shopcar" @click="switchToShopCar"></div>
		</y-badge>
		<!-- #ifdef MP-TOUTIAO -->
		<!-- class="icon-shopcar" @click="switchToShopCar" -->
			<!-- <div class="icon-index" @click="switchToShopCar">
        <img src="http://image.jxc4.com/image/8f31f82796a186c331d92095130e5829.png" style="width: 60rpx;height: 60rpx;">
      </div> -->
		<!-- #endif -->
	  
      <!-- #ifdef MP-WEIXIN || MP-ALIPAY || MP-KUAISHOU || MP-TOUTIAO -->
      <button class="btn-share" type="primary" open-type="share">
        <div class="icon-share"></div>
        <div class="share-text">分享</div>
      </button>
      <!-- #endif -->

	  <!-- #ifdef APP-PLUS || APP -->
	  <div class="btn-share" type="primary" @click="appShare">
	    <div class="icon-share"></div>
	    <div class="share-text">分享</div>
	  </div>
	  <!-- #endif -->
    
    </div>
    <!-- <div class="check-modal" v-if="checkModalShow">
      <CheckModal @close="closeModal" @confirm="confirmModal"></CheckModal>
    </div> -->
    <div class="bar-right" v-if="canBuy && skuName.id !== 6031118">
      <!-- v-if="isLogin && !skuName.count" -->
	  
	  <!-- #ifndef MP-TOUTIAO -->
	  
	  <!-- #endif -->
    <div class="btn-add" v-if="!skuName.count" @click="handlePlus">加入购物车</div>
    <div v-if="(isLogin && skuName.count) && skuName.id !== 6031118">
      <plus-minus :skuName="skuName" :count="skuName.count" @clickPlus="handlePlus" @clickMinus="handleMinus" @countChange="countChange"></plus-minus>
    </div>
	  <!-- #ifdef MP-TOUTIAO -->
    <!-- v-if="!skuName.count" -->
	  <!-- <div class="btn-add"  @click="buyNow">立即购买</div> -->
	  <!-- <div class="btn-add" v-if="isShowShop" @click="buyNow">立即购买</div> -->
	  <!-- <div class="btn-add" v-else style="opacity: 0.5;">即将开始</div> -->
	  <!-- #endif -->
	  
      <!-- <button v-if="!isLogin && !skuName.count" class="btn-add" open-type="getUserInfo" @getuserinfo="getUserInfo">加入购物车789</button> -->
      
    </div>
  </div>
</template>
<script>
import PlusMinus from '@/components/goodCmp/plus-minus/plus-minus'
import YBadge from '@/components/badge/badge.vue'
import { toast, modal, errToast,jumpPage } from '@/utils/uniapi.js'
import { msgData } from '@/config'
import { mapGetters, mapActions } from 'vuex'
import {store} from '@/store'
export default {
  props: {
    skuName: {
      type: Object
    },
    isShare:{
      type:String
    }
  },
  components: {
    YBadge, PlusMinus
  },
  data() {
    return {
      // checkModalShow: false
    }
  },
  computed: {
    ...mapGetters({
      carCount: 'cartPage/carCount',
      isLogin: 'login/isLogin',
      canBuy: 'indexPage/canBuy',
      confirmCheckShow: 'confirmCheckShow',
      isShowShop: 'isShowShop',
      isMaterial: "indexPage/isMaterial",
      materialInfo:"indexPage/materialInfo"
    })
  },
  onHide() {
    // this.checkModalShow = false
  },
  methods: {
    ...mapActions({
      changeCar: 'cartPage/changeCar',
      clearAllShopCar: "cartPage/clearAllShopCar"
    }),
	// app分享
	appShare() {
	  console.log('app分享')
    let _this = this
    uni.getProvider({
      service: 'share',
      success: function (res) {
        uni.share({
          provider: res.provider[0],
          scene: "WXSceneSession",
          imageUrl: _this.skuName.img.replace('http','https'),
          type: 5,
          miniProgram: {
            id: 'gh_0d7e2243b51f',
            path: '/pagesGoods/good-detail/index?skuID=' + _this.skuName.id,
            type: 0,
            webUrl:'https://ask.dcloud.net.cn/article/287'
          },
          success: function (res) {
            console.log("success:",res);
            toast('分享成功')
          },
          fail: function (err) {
            console.log("fail:",err);
            toast('分享失败')
          }
        });
      }
    });
	
  },
  // 跳转到购物车
  switchToShopCar() {
      // console.log('跳转到购物车111111111111111111111')
    // #ifndef MP-TOUTIAO || APP-PLUS
    uni.switchTab({url: "/pages/cart/index"});
    // console.log('跳转到购物车')
    // #endif

    // #ifdef MP-TOUTIAO || APP-PLUS
    if(!this.isLogin) {
        toast('请登录')
        uni.setStorageSync('shareInfo',JSON.stringify([{storeID:this.skuName.storeID},{skuID:this.skuName.id},{type:this.isShare}]))
        store.commit('login/changeLoginStatus', '')
        jumpPage('switchTab','/pages/mine/index',800)
        return
      } 
      jumpPage('navigateTo','/pages/cart/index')

    // uni.switchTab({ url: "/pages/index/index" });
    // #endif
  },
  // // 京西到家，立即购买
  // async buyNow() {
  //     // 再来一单
  //       // 请求商品
  //       try {
  //         this.showLoad();
  //         // console.log('打印当前商品信息')
  //         // // 清空购物车，放入购物车
  //         await this.clearAllShopCar();
  //         await this.handlePlus()
  //         jumpPage('navigateTo','/pages/cart/index')
  //       } catch (e) {
  //         console.error(e);
  //         // errToast(e);
  //       } finally {
  //         this.hideLoad();
  //       }
  //   },
  async handlePlus() {
    try {
      if(!this.isLogin){
        toast('请登录')

        // #ifdef MP-TOUTIAO || APP-PLUS
        uni.setStorageSync('shareInfo',JSON.stringify([{storeID:this.skuName.storeID},{skuID:this.skuName.id},{type:this.isShare}]))
        store.commit('login/changeLoginStatus', '')
        // #endif
        
        jumpPage('switchTab','/pages/mine/index',800)
        return
      }

      this.$emit('handleSkuNamePlus')
    } catch (e) {
      console.error(e)
      errToast(e)
    }
  },
  async handleMinus() {
    this.$emit('handleSkuNameMinus')
  },
  async countChange(count) {
    this.$emit('handleSkuNameChange', {
      count
    })
  }
  }
}
</script>

<style lang="scss">
@import "./shopCar-bottom-bar.scss";
</style>