
<style scoped>  
.comp-login {background-color:#F3F6FF;height:100%;height:100vh;padding:0;margin:0;}
.CashTotal{width: 80%; padding-bottom: 0.6rem;padding-top:2rem;margin: 0 auto;text-align: center;overflow: hidden;}
.btnCash {display:block;width:88%;height:2.6rem;padding:0;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;margin:0 auto;font-size:1rem;line-height:2.6rem;text-align:center;color:#fff;background:#3A8AFB;border:none;border-radius:0.2rem;margin-top:0.4rem;margin-bottom:1rem;}
.btnCashDetail {display: block;width: 88%;height: 2.6rem;padding: 0;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;
margin: 0 auto;line-height: 2.6rem;text-align: center;color: #3A8AFB;background: #fff;border-radius: 0.2rem;margin-bottom: 1rem;border: 0.04rem solid #3A8AFB;}
.btnTip{text-align: center;margin-top: 1.4rem;color:#5394FC;}
.EnterCash input{height:3rem;line-height:3rem; margin:0.4rem 0;border: medium none;display: inline;width: 70%;font-size: 1.8375rem !important;background:none;border:none;outline: none;}
.auditPopu{position: fixed;text-align: center;top:50%;margin-top:-10rem;min-height: 15.4rem;width: 84%;background: rgba(255, 255, 255, 1);margin-left:8%;border-radius: 0.2rem;}
.auditPopu img{display: block;margin: 0 auto;}
.auditPopu .successImg{width: 5rem;height: 5rem;margin-top: 2rem;}
.auditPopu h3{color:#3A8AFB;}
.auditPopu p{width:86%;margin: 0 auto; }
.auditPopu .closeImg{width: 2rem;height: 2rem;position: absolute;bottom: -3.2rem;margin-left:-1rem;left: 50%;}
.mask {position: fixed;top: 0;left: 0;height: 100%;width: 100%;background: rgba(0, 0, 0, 0.5);}
input[type=button], input[type=submit], input[type=file], button {cursor:pointer;outline:0px; -webkit-appearance:none; }
</style>
<style >
.jfBaseSize .EnterCash input#InputCashMoney{font-size: 2rem !important;}
</style>
<template>     
  <div class="container comp-login jfBaseSize" v-cloak v-bind:style="vh?'height:100vh':'height: 100%;'"> 
      <div class="CashEnterTotal">
          <div class="CashTotal">
            <div style="font-size: 2rem;">￥{{CashOutMoney}}</div>
            <span>可提现金额</span>
          </div>
          <div class="EnterCash" style="background: #fff;margin: 0 6%;margin-top: 0.5rem;padding-left:1rem;">
              <div class="CashTip" style="padding-top: 0.5rem;">输入提现金额</div>
              <span style="font-size:1.8rem;">￥</span><input type="text" id="InputCashMoney"/>
          </div>
          <div class="btnShow">
              <div class="btnTip">提现金额将于2小时内提现到微信钱包</div>
              <input type="button" id="btnCash" class="btnCash" value="确认提现" @click="SureCashOut()"/>
              <input type="button" id="btnCapitalDetail" class="btnCashDetail" value="收支明细" @click="goPage('Key_CInfo')"/>
          </div>
      </div>

       <div class="mask" v-show="isShow.IsshowMask"></div>
       <div class="auditPopu" v-show="isShow.IsshowCashOk">
          <img class="successImg" src="http://image.supercarrier8.com/h5_key/icon-OK.png" alt="success">
          <h3>
           提交成功！
          </h3>
          <p v-if="!isShow.IsshowAudit">
            请耐心等待，将在2小时内发放到微信零钱包！
          </p>
          <p v-else>
            请耐心等待，系统将在3个工作日内审核发放到微信零钱包！
          </p>
          <img class="closeImg" src="http://image.supercarrier8.com/h5_key/icon-close-white.png" alt="close" @click="goPage('Key_CInfo')"> 
    </div>
     <ReturnHome ref="returnhome"></ReturnHome>
  </div>
</template>
<script>
import { Toast } from 'mint-ui';
import channelHelper from "@/assets/js/channelHelper.js";
import { base64 } from "@/assets/js/cryptoHelper";
import { debug } from 'util';
import ReturnHome from "@/components/channel/temp001/ReturnHome";
import '@/assets/js/libs/js.cookie';
import { Indicator } from 'mint-ui';
export default {
  name: "Key_CashEnter",
    components: {ReturnHome},
  provide(){       
     return{           
        goPage:this.goPage       
     }   
  },
  props: ["comp", "cfg", "selectedPage"],
  data() {
    return {
      isShow:{
        IsshowMask:false,
        IsshowCashOk:false,
        IsshowAudit:false,
      },
      CashOutMoney: 0,
      vh:false,
      BaseTotalCount:{
        MoneyCount:"0.00",
        ScoreCount:"0",
        GiftCount:"0",
        UseMoneyCount:"0.00"
      }
    };
  },
  methods: {
    CloseTip(){
      this.isShow.IsshowMask=false;
      this.isShow.IsshowCashOk=false;
    },
     goPage(pagetype){
        this.$parent.changeSelectedPage(pagetype);
    },
    LoadBaseCount(){
        var that=this;
        var eno=that.sup8.context.enterpriseno;
        var url = "/channel/GetMyRewardsCount";
        var dataParams = {
            UserToken:channelHelper.GetUserToken(),
            EnterpriseNo: eno,
            LanguageType:channelHelper.GetLanguageType()
        };
        var cbError=function(){Indicator.close();}
        var cbSuccess = function(res){
            Indicator.close();
            if (res.flag){
                that.BaseTotalCount=res.data;
                var MoneyCount=parseFloat(that.BaseTotalCount.MoneyCount);
                var UseMoneyCount=parseFloat(that.BaseTotalCount.UseMoneyCount);
                sessionStorage.setItem("CashOutMoney",(MoneyCount*1000-UseMoneyCount*1000)/1000);
                that.CashOutMoney=sessionStorage.getItem("CashOutMoney");
            }
      }
       //请求后端
        channelHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
    },
    SureCashOut(){
        var that=this;
        var CashOutMoney=parseFloat(that.CashOutMoney);
        var InputCashMoney=$("#InputCashMoney").val();
        var regParam=/((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/
        if(!regParam.test(InputCashMoney))
        {
           Toast('请输入正确的金额!');return false;
        }
        var OpenId="";
        var wxUserInfo=this.sup8.context.wxUser;
        if(wxUserInfo)
        {
          OpenId=wxUserInfo.openid;
        }
        Indicator.open();
        var eno=that.sup8.context.enterpriseno;
        var url = "/channel/CashExtract";
        var dataParams = {
            Amount:InputCashMoney,
            UserToken:channelHelper.GetUserToken(),
            EnterpriseNo: eno,
            LanguageType:channelHelper.GetLanguageType(),
            OpenId:OpenId
        };
        var cbError=function(){Indicator.close();}
        var cbSuccess = function(res){
            Indicator.close();
            if (res.flag){
              that.isShow.IsshowMask=true;
              that.isShow.IsshowCashOk=true;
              if(res.data&&res.data==1){
                that.$set(that.isShow,'IsshowAudit',false);
              }else{
                that.$set(that.isShow,'IsshowAudit',true);
              }
              if(that.CashOutMoney)
              {
                  var CashOutMoney=parseFloat(CashOutMoney);
                  CashOutMoney=CashOutMoney-parseFloat(InputCashMoney);
                  sessionStorage.setItem("CashOutMoney",CashOutMoney);
              }
            }else
            {
              Toast(res.msg);return false;
            }
        };
        //请求后端
        channelHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
    }
  },
  watch: {
  },
  created: function() {
     Indicator.close(); 
  },
  mounted: function() {
     var that=this;
     that.LoadBaseCount();
      var isDesign = location.pathname.indexOf('design');
      if (!(isDesign>-1)) {
          that.$set(that,'vh',true);
      }else{
          that.$set(that,'vh',false);
      }
      setTimeout(()=>{
        let offsetHeight = document.body.offsetHeight;
        let scrollHeight = document.body.scrollHeight;
        this.height = scrollHeight>offsetHeight?scrollHeight+"px":offsetHeight+"px";
      },1000);
  }
};
</script>

