<template>
  <div class="dialogSty">
    <el-dialog
      :title="dialogParam.title"
      :visible.sync="dialogParam.dialogVisible"
      width="60%"
      @close="handleClose('dialogForm')">
      <el-row >
        <el-col :span="24">
          <el-divider content-position="left">个人身份证正信息</el-divider>
          <el-col :span="24">
            <el-image
              v-for="(item,index) of cardImgList"
              style="width: 100px; height: 100px; margin-right: 10px;"
              :src="item"
              :key="index"
              :preview-src-list="cardImgList">
            </el-image>
          </el-col>
        </el-col>
        <el-col :span="24" v-if="dialogParam.dialogType == '非居民'">
          <el-divider content-position="left">企业信息</el-divider>
          <el-col :span="24">
            <el-image
              v-for="(item,index) of enterpriseImgList"
              style="width: 100px; height: 100px; margin-right: 10px;"
              :src="item"
              :key="index"
              :preview-src-list="enterpriseImgList">
            </el-image>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-divider content-position="left">认证信息</el-divider>
          <el-col v-if = "dialogParam.dialogType == '非居民'" :span="24" v-for="(item,index) in nonResidentInfoList1" :key="'gas'+index">
            <el-col :span="12" v-for="(bitem,index) in item" :key="bitem.name" style="margin-bottom: 5px;">
              <div class="info-div" >
                <div class="item-name-sty">
                  {{bitem.name}}:
                </div>
                <div class="info-span" style="flex: 1;padding-left: 5px;font-size: 14px;">{{bitem.value}}</div>
              </div>
            </el-col>
          </el-col>
          <el-col v-if = "dialogParam.dialogType == '居民'" :span="24" v-for="(item,index) in residentInfoList1" :key="'resident'+index">
            <el-col :span="12" v-for="(bitem,index) in item" :key="bitem.name" style="margin-bottom: 5px;">
              <div class="info-div">
                <div class="item-name-sty">
                  {{bitem.name}}:
                </div>
                <div class="info-span" style="flex: 1;padding-left: 5px;font-size: 14px;">{{bitem.value}}</div>
              </div>
            </el-col>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-divider content-position="left">认证审核意见</el-divider>
          <el-form :model="dialogForm" ref="dialogForm" :rules="dialogFormRules" label-width="90px">
            <el-col :span="24">
              <el-form-item label="审核状态:" prop="fRzzt">
                <el-radio-group v-model="dialogForm.fRzzt">
                  <el-radio :label="'yrz'">已认证</el-radio>
                  <el-radio :label="'rzwtg'">认证未通过</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="理由:">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="dialogForm.reason">
                </el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose('dialogForm')">取 消</el-button>
        <el-button type="primary" @click="handleSubmit('dialogForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { realNameDetailInfoPort,submitRealNameAuditPort } from '@/api/realNameAudit'
export default {
  name: "realNameAuditDialog",
  data(){
    return{
      rowData:{},
      dialogForm:{
        fRzzt:'yrz',
        reason:''
      },
      dialogFormRules:{
        fRzzt:[
          { required:true,message:'请勾选审核意见'}
        ]
      },
      cardImgList:[],
      enterpriseImgList:[],
      nonResidentInfoList1:[],
      nonResidentInfoList: [
        {
          name: '经营者姓名',
          value: '张三',
          key:'fXm'
        },
        {
          name: '经营者联系电话',
          value:'17382982323',
          key:'fSjh',
        },
        {
          name: '经营者性别',
          value:'女',
          key:'fXb',
        },
        {
          name: '经营者年龄',
          value: '12',
          key:'fNl'
        },
        {
          name: '经营者身份证号',
          value:'121243434',
          key:'fSfzh',
        },
        {
          name: '身份证有效期',
          value: '十五年',
          key:'fSfzhyxq'
        },
        {
          name: '共/商业名称',
          value: '323023',
          key:'fSymc'
        },
        {
          name: '统一社会信用代码(纳税人识别号)',
          value:'12121',
          key:'fShtysbm',
        }
      ],
      residentInfoList1:[],
      residentInfoList: [
        {
          name: '姓名',
          value: '张三',
          key:'fXm'
        },
        {
          name: '联系电话',
          value:'17382982323',
          key:'fSjh',
        },
        {
          name: '性别',
          value:'女',
          key:'fXb',
        },
        {
          name: '年龄',
          value: '12',
          key:'fNl'
        },
        {
          name: '身份证号',
          value:'121243434',
          key:'fSfzh',
        },
        {
          name: '身份证有效期',
          value: '十五年',
          key:'fSfzhyxq'
        }
      ],
      dialogParam:{
        dialogVisible:false,
        title:'居民身份认证审核',
        dialogType:'非居民'
      }
    }
  },
  methods:{
    open(row) {
      console.log('打印详情部分row===>',row)
      this.rowData ={
        ...row
      }
      this.dialogForm.fRzzt = 'yrz';
      this.dialogForm.reason = '';
      this.dialogParam.dialogVisible= true;
      this.dialogParam.dialogType = row.whyxxfhylx;
      this.getInfoDataList();
    },
    async getInfoDataList(){
      await realNameDetailInfoPort(this.rowData.id_).then(async (res)=>{
        console.log('打印res',res);
        const { value } = res;
        let cardImgUrlList = [];
        if(value.fSfzghy){
          let sfzghImg  = JSON.parse(value.fSfzghy);
          let sfzghImgUrl = await this.$getPhotoUrl(sfzghImg[0].response.fileId);
          cardImgUrlList.push(sfzghImgUrl);
          console.log('打印sfzghImg',sfzghImg,sfzghImgUrl);
        }
        if(value.fSfzrxy){
          let sfzrxImg  = JSON.parse(value.fSfzrxy);
          let sfzrxImgUrl = await this.$getPhotoUrl(sfzrxImg[0].response.fileId);
          cardImgUrlList.push(sfzrxImgUrl);
          console.log('打印sfzghImg',sfzrxImg,sfzrxImgUrl);
        }
        this.cardImgList = cardImgUrlList;
        if(this.rowData.whyxxfhylx == '居民'){
          this.residentInfoList = await this.$assignValues(value, this.residentInfoList);
          this.residentInfoList1 = await this.$createDoubleArray(this.residentInfoList,2);
        }else{
          let enterpriseImgUrlList = [];
          if(value.fYyzz){
            let yyzzImg  = JSON.parse(value.fYyzz);
            let yyzzImgUrl = await this.$getPhotoUrl(yyzzImg[0].response.fileId);
            enterpriseImgUrlList.push(yyzzImgUrl);
            console.log('打印sfzghImg',yyzzImg,yyzzImgUrl);
          }
          if(value.fKhxkz){
            let khxkzImg  = JSON.parse(value.fKhxkz);
            let khxkzImgUrl = await this.$getPhotoUrl(khxkzImg[0].response.fileId);
            enterpriseImgUrlList.push(khxkzImgUrl);
            console.log('打印sfzghImg',khxkzImg,khxkzImgUrl);
          }
          if(value.fFrsfzrxy){
            let frsfzrxImg  = JSON.parse(value.fFrsfzrxy);
            let frsfzrxImgUrl = await this.$getPhotoUrl(frsfzrxImg[0].response.fileId);
            enterpriseImgUrlList.push(frsfzrxImgUrl);
            console.log('打印sfzghImg',frsfzrxImgUrl,frsfzrxImg);
          }
          if(value.fFrsfzghy){
            let frsfzghImg  = JSON.parse(value.fFrsfzghy);
            let frsfzghImgUrl = await this.$getPhotoUrl(frsfzghImg[0].response.fileId);
            enterpriseImgUrlList.push(frsfzghImgUrl);
            console.log('打印sfzghImg',frsfzghImg,frsfzghImgUrl);
          }
          this.enterpriseImgList = enterpriseImgUrlList;
          this.nonResidentInfoList = await this.$assignValues(value, this.nonResidentInfoList);
          this.nonResidentInfoList1 = await this.$createDoubleArray(this.nonResidentInfoList,2);
        }
      });
    },
    //关闭弹窗的事件
    handleClose(formName){
      this.$refs[formName].resetFields();
      this.dialogParam.dialogVisible = false
    },
    //确定提交弹窗的事件
    async handleSubmit(formName){
      this.$refs[formName].validate(async(valid) => {
        if (valid) {
          let params = {
            id:this.rowData.id_,
            fRzzt:this.dialogForm.fRzzt,
          }
          await submitRealNameAuditPort(params).then((res)=>{
            console.log('打印实名认证审核提交',res);
            if(res.code == 200){
              this.$message.success('审核成功!')
            }
            this.$emit('handleRefresh');
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });

      this.dialogParam.dialogVisible = false;
    },
  }
}
</script>

<style lang="scss" scoped>
.dialogSty{
  ::v-deep.el-dialog__body{
    padding: 20px!important;
    padding-top: 0px!important;
  }
  .info-div{
    display: flex;
    align-items: center;
    .item-name-sty{
      color: #333333;
      font-size: 16px;
    }
  }
}

</style>
