<template>
    <div>
        <!-- <el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button> -->

      <!--   <el-dialog  :visible.sync="dialogVisible" width="80%" height="1080px;" :before-close="handleClose" append-to-body	> -->
            <el-tabs v-model="activeName" type="card">
                <el-tab-pane v-for="item in pdfFileLists" :key="item.value" label="合同信息" name="first"  style="height:500px;">
                    <embed :src="'data:application/pdf;base64,' + item.base64"  type="application/pdf" title="Embedded PDF" style="overflow: auto; width: 100%; height: 100%;"/>
                </el-tab-pane>
                <!-- <el-tab-pane label="申请协议" name="first"  style="height:780px;">
                    招采融信申请协议
                    编号：ZCRXKL-20210712001
                    本《供应链金融服务平台融信转让协议》（以下简称为“本协议”、“《融信转让
                    协议》”）由融信转让人、融信受让人于本协议约定的时间在北京市东城区签署：
                    融信转让人：B 供应商 2_TSCF 培训专用
                    住所：成都市高新区新园南二路一号
                    法定代表人：张健
                    融信受让人：B 供应商 1_TSCF 培训专用
                    住所：成都市高新区新园南二路一号
                    法定代表人：张健 鉴于：
                    (A) 融信反向保理平台由中粮资本科技有限责任公司建设并运营，向用户提供
                    应收账款管理、转让、融资等服务。
                    (B) 融信转让人与融信受让人（以下简称为“双方”）均为融信反向保理平台的
                    用户。
                    (C) 融信转让人现持有融信，享有融信项下的应收账款债权。
                    (D) 双方均同意使用融信反向保理平台的服务，现融信转让人拟将融信项下应
                    收账款债权全部或部分通过融信反向保理平台转让给融信受让人，融信受
                    因此，经双方协商一致，签订本协议，约定如下:
                </el-tab-pane>
                <el-tab-pane label="配置管理" name="second" style="height:780px;">
                    住所：成都市高新区新园南二路一号
                    法定代表人：张健
                    融信受让人：B 供应商 1_TSCF 培训专用
                    住所：成都市高新区新园南二路一号
                    法定代表人：张健 鉴于：
                    (A) 融信反向保理平台由中粮资本科技有限责任公司建设并运营，向用户提供
                    应收账款管理、转让、融资等服务。
                    (B) 融信转让人与融信受让人（以下简称为“双方”）均为融信反向保理平台的
                    用户。
                    (C) 融信转让人现持有融信，享有融信项下的应收账款债权。
                    (D) 双方均同意使用融信反向保理平台的服务，现融信转让人拟将融信项下应
                    收账款债权全部或部分通过融信反向保理平台转让给融信受让人，融信受
                    因此，经双方协商一致，签订本协议，约定如下:</el-tab-pane> -->

            </el-tabs>
            <span slot="footer" class="dialog-footer" style="float: right;">
                    <!-- <el-button type="primary" @click="selectType" size="mini">签署</el-button> -->
                    <!-- <el-button @click="closePdfShow" size="mini">取 消</el-button> -->
                    <el-button @click="submit" size="mini">确 定</el-button>
            </span>
            
            <!-- <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
            </span> -->
        <!-- </el-dialog> -->
        <div>
             <!--选择签署意愿类型-->
            <!-- <el-dialog  :visible.sync="confirmIsShow" width="600px"  append-to-body :before-close = "cancelUpdate" center>
                <el-form ref="updateForm"  :disabled="false" :model="updateForm"  v-if="confirmIsShow" label-width="150px"  class="demo-form-inline" :inline="true">
                    <el-radio-group v-model="updateForm.radio">
                        <el-radio label="01">人脸</el-radio>
                        <el-radio label="02">短信</el-radio>
                    </el-radio-group>
                </el-form>

                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="confirmSelect">确 定</el-button>
                    <el-button @click="cancelUpdate">取 消</el-button>
                </div>
            </el-dialog> -->
            <!--短信-->
            <!-- <el-dialog  :visible.sync="messageIsShow" width="800px"  append-to-body :before-close = "cancelMessage" center>
                <el-form ref="messageForm"  :disabled="false" :model="messageForm"  v-if="messageIsShow" label-width="150px"  class="demo-form-inline" :inline="true" @submit.native.prevent>
                        <el-form-item label="验证码" prop="validCode">
                            <el-input v-model="messageForm.validCode" style="width: 200px" maxlength="6"  oninput="value=value.replace(/[^\d]/g,'')"/>
                        </el-form-item>
                        <el-form-item>
                            <el-button  v-show="messShow"  type="success" @click="send">点击获取验证码</el-button>
                            <el-button v-show="!messShow" type="success" disabled><span>{{timer}}</span>秒后重新获取</el-button>
                        </el-form-item>

                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="checkCode">确定</el-button>
                    <el-button @click="cancelMessage">取 消</el-button>
                </div>
            </el-dialog> -->
            <!--授权编号的短信框-->
            <!-- <el-dialog  title="授权短信验证"  :visible.sync="projectIsShow" width="800px"  append-to-body :before-close = "cancelProject" center>
                <el-form ref="projectForm"  :disabled="false" :model="projectForm"  v-if="projectIsShow" label-width="150px"  class="demo-form-inline" :inline="true">
                        <el-form-item label="验证码" prop="code">
                            <el-input v-model="projectForm.code" style="width: 200px" maxlength="6"  oninput="value=value.replace(/[^\d]/g,'')"/>
                        </el-form-item>
                        <el-form-item>
                            <el-button  v-show="proShow"  type="success" @click="proSend">点击获取验证码</el-button>
                            <el-button v-show="!proShow" type="success" disabled><span>{{proTimer}}</span>秒后重新获取</el-button>
                        </el-form-item>

                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="checkProCode">确定</el-button>
                    <el-button @click="cancelProject">取 消</el-button>
                </div>
            </el-dialog> -->
            <!--人脸二维码-->
            <!-- <el-dialog  :visible.sync="faceIsShow" width="500px"  append-to-body :before-close = "cancelFace" center>
                <img :src="'data:image/jpeg;base64,' + this.fileUrl" style="overflow: auto; width: 100%; height: 100%;"/>
            </el-dialog> -->
            <!--去融资-->
            <el-dialog  :visible.sync="goShow" width="300px"  append-to-body :before-close = "cancelGo" center>
                    <!-- <p>恭喜您成功签收一笔融信</p> -->
                    <p>签收融信成功，融信信息：</p>
                    <el-form ref="financeSignForm" :model="financeSignForm" label-width="auto" :inline="true">
                        <el-row>
                            <el-form-item label="融信编号：">{{financeSignForm.zfiNumber}}</el-form-item>
                            <el-form-item label="融信金额：">{{handleInput(financeSignForm.zfiAmount) + "元"}}</el-form-item>
                            <el-form-item label="大写：">{{smallToBig(financeSignForm.zfiAmount)}}</el-form-item>
                        </el-row>
                        <el-row>
                            <el-form-item label="融信利率：">{{financeSignForm.zfiRate + "%"}}</el-form-item>
                            <el-form-item label="最长融信期限：">{{financeSignForm.intervalTime + "天"}}</el-form-item>
                            <el-form-item label="融信有效期：">{{financeSignForm.validity}}</el-form-item>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="goFinance">去融资</el-button>
                        <el-button @click="cancelGo">取 消</el-button>
                    </div>    
            </el-dialog>
        </div>
    </div>
    
</template>


<script>
import {sendMessage,checkCode,faceAuth,checkFaceAuth,contractSigning,listStamped} from "@/api/service/credit/message";
import {cfcaProjectNo,projectSendMessage,checkProCode} from "@/api/service/credit/cfcaProject";
import {getCreditDetail,getFinanceSign} from "@/api/service/credit/credit";
import { amtformat } from "@/utils/amtCommon";
import Cookies from 'js-cookie';
export default {
    props : ['pdfFileLists','zfiId', 'parents'],
    data() {
        return {
            activeName: "first",
            dialogVisible: false,
            dialogTableVisible: false,
            dialogFormVisible: false,
            form: {
                name: "",
                region: "",
                date1: "",
                date2: "",
                delivery: false,
                type: [],
                resource: "",
                desc: "",
            },
            formLabelWidth: "120px",
             //展示选择意愿
            confirmIsShow:false,
            //意愿
            updateForm:{},
            //意愿类型
            zfpAuthTypeInit:'',
            zfpAuthType:'',
            //短信展示
            messageIsShow:false,
            //短信
            messageForm:{validCode:""},
            //人脸二维码
            fileUrl:"",
            //控制人脸二维码是否展示
            faceIsShow:false,
            //人脸验证结果
            faceResult:"",
            //人脸识别结果传参
            authForm:{},
            financeSignForm:{},
            //控制短信验证码倒计时是否展示
            messShow:true,
            timer:60,
            openFile:false,
            wordUrl: "",
            show:false,
            heid:false,
            auth_timer : null,
            //融资方审批状态
            zfiSupplierStatus:'',
            //核心审批状态
            zfiCoreStatus:'',
            //平台审批状态
            zfiPlatformStatus:'',
            //融信状态
            zfiStatus:'',
            //盖章文件
            creditSealList:[],
            //生成授权编号的短信框
            projectIsShow:false,
            //短信
            projectForm:{code:""},
            //控制倒计时是否展示
            proShow:true,
            //时间
            proTimer:60,
            //项目编号
            projectCode:"",
            //融信信息
            financeData:{},
            //接收方
            receiveName:"",
            //开立方
            openName:"",
            //显示去融资框
            goShow:false,
            //融信类型
            zfiCreateType:"",
        };
    },
    created() {
         getCreditDetail(this.zfiId).then((response) => {
             if(response.data){
                //融信状态
                 this.zfiStatus = response.data.financeInf.zfiStatus;
                 //融资方审批状态
                 this.zfiSupplierStatus =  response.data.financeInf.zfiSupplierStatus;
                 //平台审批状态
                 this.zfiPlatformStatus =  response.data.financeInf.zfiPlatformStatus;
                 //核心审批状态
                 this.zfiCoreStatus = response.data.financeInf.zfiCoreStatus;
                //意愿类型
                this.zfpAuthType = response.data.zfpAuthType;
                this.zfpAuthTypeInit = response.data.zfpAuthType;
                //融信信息
                this.financeData = response.data.financeInf;
                //接收方
                this.receiveName = response.data.receiveName;
                //开立方
                this.openName = response.data.openName;
                //融信类型
                this.zfiCreateType = response.data.financeInf.zfiCreateType;
             }
        })
        this.dialogVisible = true;
        for(var i = 0 ; i < this.pdfFileLists.length; i++){
            var base64 = this.pdfFileLists[i].base64;
            <embed src="data:application/pdf;base64,"  type="application/pdf" title="Embedded PDF" style="overflow: auto; width: 100%; height: 100%;"/>
        } 
    },
    methods: {
        handleClose(done) {
            this.$confirm("确认关闭？")
                .then((_) => {
                    done();
                })
                .catch((_) => {});
        },
        selectChildType(){
            this.$parent.selectType();
        },
    //回到父页
    cancelGo(){
        this.goShow = false;
        this.closePdfShows();
        this.goParent();
    },
    
    closePdfShows(){
        this.parents.closePdfShows();
    },
    //返回到列表页
    goParent(){
       this.parents.goParent();
    },
    //去融资
    goFinance(){
        //关闭弹框
        this.goShow = false;
        this.closePdfShows();
         this.goParent();
        Cookies.set("/credit/goFinance/"+this.zfiId + "/", this.$route.fullPath)
        this.$router.push({ path: "/credit/goFinance/"+this.zfiId + "/" });
    },
    submit(){
        //状态判断为盖完章之后的
        debugger
        if(this.zfiStatus == '01' && this.zfiCreateType == '0'){
           //供应商申请
            this.msgSuccess("确权成功，融信已提交,"+this.receiveName+"签收");
            this.closePdfShows();
            this.goParent();
        }
        else if(this.zfiStatus == '02' && this.zfiCreateType == '2'){//供应商开立
                this.msgSuccess("确权成功,融信已生效");
                this.closePdfShows();
                this.goParent();
            }else if(this.zfiStatus == '02' && this.zfiCreateType == '0'){//签收
            getFinanceSign(this.zfiId).then((response) => {
                //融信编号
                this.financeSignForm.zfiNumber = response.data.zfiNumber;
                //融信金额
                if(response.data.zfiAmount){
                    this.financeSignForm.zfiAmount = response.data.zfiAmount;
                }else{
                    this.financeSignForm.zfiAmount = "0.00";
                }
                //利率
                if(response.data.zfiRate){
                    this.financeSignForm.zfiRate = response.data.zfiRate;
                }else{
                    this.financeSignForm.zfiRate = "0";
                }
                //最长融信期限
                this.financeSignForm.intervalTime = response.data.intervalTime;
                //融信有效期
                if(response.data.validity){
                this.financeSignForm.validity = response.data.validity;
                }
                this.goShow = true;
                this.closePdfShows();
            });
        }else if(this.zfiCreateType == '1' && this.zfiCoreStatus == '01' && this.zfiStatus=='01'){//核心开立
            this.msgSuccess("开立成功，融信已提交"+this.receiveName+"签收");
            this.closePdfShows();
            this.goParent();
        }else if(this.zfiCreateType == '2' && this.zfiPlatformStatus == '01' && this.zfiSupplierStatus == '01' && this.zfiStatus=='00'){
            //融资开立盖章
            this.msgSuccess("开立成功,待:"+this.openName+"确权；确权结果请留意待办事项与站内消息");
            this.closePdfShows();
            this.goParent();
        }else if(this.zfiCreateType == '1' && this.zfiSupplierStatus == '01' && this.zfiPlatformStatus == '01'){//补充资料
            getFinanceSign(this.zfiId).then((response) => {
                //融信编号
                this.financeSignForm.zfiNumber = response.data.zfiNumber;
                //融信金额
                if(response.data.zfiAmount){
                    this.financeSignForm.zfiAmount = response.data.zfiAmount;
                }else{
                    this.financeSignForm.zfiAmount = "0.00";
                }
                //利率
                if(response.data.zfiRate){
                    this.financeSignForm.zfiRate = response.data.zfiRate;
                }else{
                    this.financeSignForm.zfiRate = "0";
                }
                //最长融信期限
                this.financeSignForm.intervalTime = response.data.intervalTime;
                //融信有效期
                if(response.data.validity){
                this.financeSignForm.validity = response.data.validity;
                }
                this.goShow = true;
                this.closePdfShows();
            });
        }
    },
    /* 金额展示 */
    handleInput(str) {
        return amtformat(str, 2, ".", ",");
    },
    /* //  将数字金额转换为大写金额 */
    smallToBig(money) {
      //  将数字金额转换为大写金额
      var cnNums = new Array(
        "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" ); //汉字的数字
      var cnIntRadice = new Array("", "拾", "佰", "仟"); //基本单位
      var cnIntUnits = new Array("", "万", "亿", "兆"); //对应整数部分扩展单位
      var cnDecUnits = new Array("角", "分", "毫", "厘"); //对应小数部分单位
      var cnInteger = "整"; //整数金额时后面跟的字符
      var cnIntLast = "元"; //整数完以后的单位
      //最大处理的数字
      var maxNum = 999999999999999.9999;
      var integerNum; //金额整数部分
      var decimalNum; //金额小数部分
      //输出的中文金额字符串
      var chineseStr = "";
      var parts; //分离金额后用的数组，预定义
      if (money == "" || money == null || money == undefined) {
        return "零元零角零分";
      }
      money = parseFloat(money);
      if (money >= maxNum) {
        //超出最大处理数字
        return "超出最大处理数字";
      }
      if (money == 0) {
        chineseStr = cnNums[0] + cnIntLast + cnInteger;
        return chineseStr;
      }
      //四舍五入保留两位小数,转换为字符串
      money = Math.round(money * 100).toString();
      integerNum = money.substr(0, money.length - 2);
      decimalNum = money.substr(money.length - 2);
      //获取整型部分转换
      if (parseInt(integerNum, 10) > 0) {
        var zeroCount = 0;
        var IntLen = integerNum.length;
        for (var i = 0; i < IntLen; i++) {
          var n = integerNum.substr(i, 1);
          var p = IntLen - i - 1;
          var q = p / 4;
          var m = p % 4;
          if (n == "0") {
            zeroCount++;
          } else {
            if (zeroCount > 0) {
              chineseStr += cnNums[0];
            }
            //归零
            zeroCount = 0;
            chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
          }
          if (m == 0 && zeroCount < 4) {
            chineseStr += cnIntUnits[q];
          }
        }
        chineseStr += cnIntLast;
      }
      //小数部分
      if (decimalNum != "") {
        var decLen = decimalNum.length;
        for (var i = 0; i < decLen; i++) {
          var n = decimalNum.substr(i, 1);
          if (n != "0") {
            chineseStr += cnNums[Number(n)] + cnDecUnits[i];
          }
        }
      }
      if (chineseStr == "") {
        chineseStr += cnNums[0] + cnIntLast + cnInteger;
      } else if (decimalNum == "" || /^0*$/.test(decimalNum)) {
        chineseStr += cnInteger;
      }
      return chineseStr;
    },
    },
};
</script>