<template>
  <div class="policy">
    <div class="search-wrapper">
      <el-form
        :inline="true"
        :model="searchForm"
        class="search_form"
        style="text-align: left"
      >
        <el-form-item label="姓名">
          <el-input
            v-model="searchForm.name"
            size="small"
            placeholder="请输入姓名"
            @keyup.enter.native="onSubmit"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input
            v-model="searchForm.phone"
            size="small"
            placeholder="请输入手机号码"
            @keyup.enter.native="onSubmit"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="onSubmit"
            >查询</el-button
          >
        </el-form-item>
        <br />
        <el-form-item label="状态" style="margin-top: 10px">
          <el-radio-group v-model="searchForm.state" @change="onSubmit">
            <el-radio
              :label="item.state"
              v-for="item in stateList"
              :key="item.state"
              >{{ item.stateName }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-wrapper">
      <table-template
        :tableData="tableData"
        :tableColumns="tableColumns"
        :loading="loading"
        :pagination="pagination"
        @Jump="jumpPage"
      >
        <el-table-column slot="housingType" label="事项类型" align="center">
          <template slot-scope="scope">
            <el-tag>{{
              scope.row.housingType == 2
                ? "住房"
                : scope.row.housingType == 3
                ? "商办"
                : "-"
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          width="120"
          key="stateName"
          prop="stateName"
          label="状态"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.type">{{ scope.row.stateName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="380" align="left">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" round @click="view(scope.row)"
              >查看</el-button
            >
            <el-button
              type="primary"
              size="mini"
              round
              @click="record(scope.row)"
              >记录</el-button
            >
            <el-button
              type="danger"
              size="mini"
              round
              v-if="
                scope.row.state === 6 ||
                scope.row.state === 2 ||
                scope.row.state === 3 ||
                scope.row.state === 4
              "
              @click="revocationHandle(scope.row)"
              >撤回</el-button
            >

            <!-- 待复审的单子有通过拒绝-->
            <template v-if="scope.row.state === 1">
              <el-button
                type="success"
                size="mini"
                round
                @click="pass(scope.row)"
                >复审通过</el-button
              >
              <el-button
                type="danger"
                size="mini"
                round
                @click="deny(scope.row)"
                >复审拒绝</el-button
              >
            </template>
            <template v-if="scope.row.state === 2">
              <el-button
                type="success"
                size="mini"
                round
                @click="passFinal(scope.row)"
                >终审通过</el-button
              >
              <el-button
                type="danger"
                size="mini"
                round
                @click="deny(scope.row)"
                >终审拒绝</el-button
              >
            </template>
            <el-button
              v-if="
                scope.row.attachedFileMark === true &&
                searchForm.departmentCode === '10000027'
              "
              type="info"
              size="mini"
              round
              @click="viewUrl(scope.row)"
              >查看附件</el-button
            >
          </template>
        </el-table-column>
      </table-template>
    </div>
    <el-dialog
      title="申报详情"
      :visible.sync="viewShow"
      width="800px"
      :close-on-press-escape="false"
    >
      <div class="content">
        <!-- 新增start -->
        <el-table :data="totalList" style="width: 100%">
          <el-table-column prop="reasonName" label="审核单位" width="180">
          </el-table-column>
          <el-table-column prop="state" label="审核状态" width="180">
          </el-table-column>
          <el-table-column prop="reason" label="审核意见"> </el-table-column>
        </el-table>
        <div class="cell" v-if="viewDetail.checkArea != '丹阳市'">
          <p class="label">是否享受过相关政策</p>
          <p
            :class="[
              'value',
              viewDetail.enjoyFlag == true ? 'value2' : 'value1',
            ]"
          >
            {{ viewDetail.enjoyFlag ? "否" : "是" }}
          </p>
        </div>
        <div class="cell">
          <p class="label">市契税系统</p>
          <p class="value">
            {{
              viewDetail.tradeStatus === 0
                ? "未支付"
                : viewDetail.tradeStatus === 1
                ? "已支付"
                : viewDetail.tradeStatus === 2
                ? "不予发放"
                : "未审核"
            }}
          </p>
        </div>
        <!-- 新增end -->
        <div class="cell">
          <p class="label">事项类型</p>
          <p class="value">
            {{
              viewDetail.housingType == 2
                ? "住房"
                : viewDetail.housingType == 3
                ? "商办"
                : "-"
            }}
          </p>
        </div>
        <div class="cell">
          <p class="label">事项名称</p>
          <p class="value">{{ viewDetail.guideName }}</p>
        </div>
        <div class="cell">
          <p class="label">人才类型</p>
          <p class="value">{{ category }}</p>
        </div>
        <div class="cell">
          <p class="label">人才认定内容</p>
          <p class="value">{{ contentName }}</p>
        </div>
        <div class="cell">
          <p class="label">工作单位</p>
          <p class="value">{{ unitName }}</p>
        </div>
        <div class="cell">
          <p class="label">事项名称</p>
          <p class="value">{{ viewDetail.guideName }}</p>
        </div>
        <div class="cell">
          <p class="label">实施主体</p>
          <p class="value">{{ viewDetail.departmentName }}</p>
        </div>
        <div class="cell">
          <p class="label">姓名</p>
          <p class="value">{{ viewDetail.name }}</p>
        </div>
        <div class="cell">
          <p class="label">身份证</p>
          <p class="value">{{ viewDetail.idCard }}</p>
        </div>
        <div class="cell">
          <p class="label">手机号</p>
          <p class="value">{{ viewDetail.phone }}</p>
        </div>
        <!-- <div class="cell">
          <p class="label">工作单位</p>
          <p class="value">{{ viewDetail.unit }}</p>
        </div> -->
        <div class="cell">
          <p class="label">联系地址</p>
          <p class="value">{{ viewDetail.address }}</p>
        </div>
        <div class="cell">
          <p class="label">不动产权证号</p>
          <p class="value">{{ viewDetail.realEstateCard }}</p>
        </div>
        <div class="cell">
          <p class="label">不动产权坐落地址</p>
          <p class="value">{{ viewDetail.realEstateAddress }}</p>
        </div>
        <div class="cell">
          <p class="label">房屋面积</p>
          <p class="value">{{ viewDetail.square }}</p>
        </div>
        <div class="cell">
          <p class="label">银行卡号</p>
          <p class="value">{{ viewDetail.bankCard }}</p>
        </div>
        <div class="cell">
          <p class="label">所属银行</p>
          <p class="value">{{ viewDetail.bank }}</p>
        </div>
        <div
          class="cell"
          v-if="viewDetail.bankPicture && viewDetail.bankPicture.length > 0"
        >
          <p class="label">银行卡照片</p>
          <p class="value">
            <el-image
              v-for="(item, index) in viewDetail.bankPicture"
              :key="index"
              style="width: 100px; height: 100px; margin-right: 10px"
              :src="item.picture"
              :z-index="7777777"
              :preview-src-list="[item.picture]"
            >
            </el-image>
          </p>
        </div>
        <div
          class="cell"
          v-if="viewDetail.idCardPicture && viewDetail.idCardPicture.length > 0"
        >
          <p class="label">身份证照片</p>
          <p class="value">
            <el-image
              v-for="(item, index) in viewDetail.idCardPicture"
              :key="index"
              style="width: 100px; height: 100px; margin-right: 10px"
              :src="item.picture"
              :z-index="7777777"
              :preview-src-list="[item.picture]"
            >
            </el-image>
          </p>
        </div>
        <div class="cell">
          <p class="label">商品房买卖合同3张</p>
          <p class="value">
            <el-image
              v-for="(item, index) in viewDetail.contract"
              :key="index"
              style="width: 100px; height: 100px; margin-right: 10px"
              :src="item.picture"
              :z-index="7777777"
              :preview-src-list="[item.picture]"
            >
            </el-image>
          </p>
        </div>
        <div class="cell">
          <p class="label">不动产权证书</p>
          <p class="value">
            <el-image
              style="width: 100px; height: 100px"
              :src="viewDetail.certificate"
              :z-index="7777777"
              :preview-src-list="[viewDetail.certificate]"
            >
            </el-image>
          </p>
        </div>
        <div class="cell">
          <p class="label">契税完税凭证</p>
          <p class="value">
            <el-image
              style="width: 100px; height: 100px"
              :src="viewDetail.voucher"
              :z-index="7777777"
              :preview-src-list="[viewDetail.voucher]"
            >
            </el-image>
          </p>
        </div>
        <div class="cell" v-if="viewDetail.labour.length > 0">
          <p class="label">上传一年以上劳动合同的项目</p>
          <p class="value">
            <el-image
              v-for="(item, index) in viewDetail.labour"
              :key="index"
              style="width: 100px; height: 100px; margin-right: 10px"
              :src="item.picture"
              :z-index="7777777"
              :preview-src-list="[item.picture]"
            >
            </el-image>
          </p>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      title="操作记录"
      :visible.sync="recordShow"
      width="800px"
      :close-on-press-escape="false"
    >
      <div class="content">
        <div class="cell" v-for="item in recordList" :key="item.createTime">
          <p class="label" style="margin-right: 20px">
            {{ item.stateName }}
            <span v-if="item.reason">({{ item.reason }})</span>
          </p>
          <div class="info">
            <p class="item">操作人：{{ item.reasonName }}</p>
            <p class="item">操作时间：{{ item.createTime }}</p>
          </div>
        </div>
        <p v-if="record.length === 0">暂无记录~</p>
      </div>
    </el-dialog>
    <el-dialog
      title="终审通过"
      :visible.sync="finalShow"
      width="500px"
      :close-on-press-escape="false"
    >
      <div class="content">
        <div class="cell1">
          <p class="label" style="margin: 0 0 10px 0">请输入原因：</p>
          <el-input
            type="textarea"
            placeholder="请输入通过原因"
            v-model="textarea"
            maxlength="50"
            show-word-limit
          ></el-input>
        </div>
        <div class="cell1">
          <p class="label">请上传附件：</p>
          <el-upload
            class="upload-demo"
            name="file"
            action="string"
            :limit="1"
            :show-file-list="true"
            :on-remove="handleRemove"
            :on-error="handleError"
            :on-exceed="handleExceed"
            ref="dmtUploadFile"
            :file-list="fileList"
            :http-request="uploadFile"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip" style="color: #f56c6c">
              支持上传jpg/png/doc/docx/xls/xlsx/pdf等文件
            </div>
          </el-upload>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="finalShow = false">取 消</el-button>
        <el-button type="primary" @click="passFinal1">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="查看附件"
      :visible.sync="showUrl"
      width="500px"
      :close-on-press-escape="false"
    >
      <div style="margin: 0 0 0 10px; font-weight: 700">图片附件：</div>
      <div
        class="content"
        style="display: flex; flex-wrap: wrap"
        v-if="pictureUrlList.length > 0"
      >
        <div v-for="(item, index) in pictureUrlList" :key="index">
          <el-image
            style="width: 95px; height: 95px; margin: 10px"
            :src="item.file"
            :preview-src-list="[item.file]"
          ></el-image>
        </div>
      </div>
      <div
        class="content"
        style="display: flex; justify-content: center"
        v-if="pictureUrlList.length == 0"
      >
        <el-empty :image-size="50"></el-empty>
      </div>
      <div style="margin: 0 0 0 10px; font-weight: 700">文件附件：</div>
      <div
        class="content"
        style="display: flex; flex-direction: column; flex-wrap: wrap"
        v-if="fileUrlList.length > 0"
      >
        <div
          v-for="(item, index) in fileUrlList"
          :key="index"
          style="
            margin: 10px 10px 0 10px;
            display: flex;
            align-items: center;
            justify-content: space-between;
          "
        >
          <p class="label" style="margin: 0; text-align: center">
            {{ item.fileExplain }}
          </p>
          <el-button
            size="mini"
            type="primary"
            @click="download(item.file)"
            class="down-text"
            >下载附件</el-button
          >
        </div>
      </div>
      <div
        class="content"
        style="display: flex; justify-content: center"
        v-if="fileUrlList.length == 0"
      >
        <el-empty :image-size="50"></el-empty>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TableTemplate from "@/components/Table";
import { changeList, setName, setTel, setCertNo } from "@/utils";
import { get } from "@/api/talents";
import docxtemplater from "docxtemplater";
import PizZip from "pizzip";
import JSZipUtils from "jszip-utils";
import { saveAs } from "file-saver";
import { uploadWordFile, uploadTalentFile } from "@/api/upload";

import {
  mattersHousingList,
  mattersHousingUpdate,
  mattersHousingGet,
  mattersGetReason,
  mattersHousingReason,
  queryAttacheFile,
  revocation,
} from "@/api/policy";

export default {
  components: { TableTemplate },
  data() {
    return {
      showUrl: false,
      pictureUrlList: [],
      fileUrlList: [],
      finalShow: false,
      textarea: "",
      fileList: [],
      rowDetail: {},
      fileUrl1: [],
      userName: "",
      searchForm: {
        name: "",
        phone: "",
        state: "",
        departmentCode: "",
      },
      stateList: [
        {
          state: "",
          stateName: "全部",
          type: "",
        },
        {
          state: 0,
          stateName: "待审核",
          type: "warning",
        },
        {
          state: 1,
          stateName: "待复审",
          type: "warning",
        },
        {
          state: 6,
          stateName: "资料审核",
          type: "warning",
        },
        {
          state: 2,
          stateName: "待终审",
          type: "warning",
        },
        {
          state: 3,
          stateName: "已完结",
          type: "success",
        },
        {
          state: 4,
          stateName: "已驳回",
          type: "danger",
        },
        {
          state: 5,
          stateName: "已撤销",
          type: "info",
        },
        {
          state: 7,
          stateName: "发放补贴",
          type: "success",
        },
      ],
      stateList1: [
        {
          state: 0,
          stateName: "待审核",
          type: "warning",
        },
        {
          state: 1,
          stateName: "待复审",
          type: "warning",
        },
        {
          state: 6,
          stateName: "资料审核",
          type: "warning",
        },
        {
          state: 2,
          stateName: "待终审",
          type: "warning",
        },
        {
          state: 3,
          stateName: "已完结",
          type: "success",
        },
        {
          state: 4,
          stateName: "已驳回",
          type: "danger",
        },
        {
          state: 5,
          stateName: "已撤销",
          type: "info",
        },
        {
          state: 7,
          stateName: "发放补贴",
          type: "success",
        },
        {
          state: 8,
          stateName: "初审通过",
          type: "success",
        },
        {
          state: 9,
          stateName: "已驳回",
          type: "danger",
        },
      ],
      loading: false,
      tableData: [],
      tableColumns: [
        {
          key: "code",
          label: "申请编号",
          width: 200,
        },
        {
          key: "name",
          label: "姓名",
        },
        {
          key: "phone",
          label: "手机号",
          width: 150,
        },
        {
          key: "housingType",
          label: "事项类型",
          type: "slot",
        },
        {
          key: "guideName",
          label: "事项名称",
          width: 200,
        },
        {
          key: "departmentName",
          label: "实施主体",
        },
        {
          key: "createTime",
          label: "更新时间",
          width: 180,
        },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      viewShow: false,
      viewDetail: {
        labour: [],
      },
      recordShow: false,
      recordList: [],
      examineList: [],
      housingList: [],
      totalList: [],
      category: "",
      contentName: "",
      unitName: "",
      state: "",
      arr1: "", // 财政局
      arr2: "", // 税务局
      arr3: "", // 不动产登记
      arr4: "", // 人设局
      arr5: "", // 住建局
      realEstateAddress: "", // 住址
      square: "", // 房屋面积
      realEstateCard: "", // 证号
      address: "", // 联系地址
      arr1List: [], // 四个部门查询记录
      arr2List: [], // 住建局查询记录
      comdeed: null,
    };
  },
  methods: {
    viewUrl(row) {
      console.log(row);
      queryAttacheFile({ code: row.code }).then((res) => {
        console.log(res);
        if (res.success) {
          this.pictureUrlList = res.data.filter((item) => {
            let fileType =
              item.fileExplain.split(".")[
                item.fileExplain.split(".").length - 1
              ];
            return fileType == "jpg" || fileType == "jpeg" || fileType == "png";
          });
          this.fileUrlList = res.data.filter((item) => {
            let fileType =
              item.fileExplain.split(".")[
                item.fileExplain.split(".").length - 1
              ];
            return fileType != "jpg" && fileType != "jpeg" && fileType != "png";
          });
          console.log(this.pictureUrlList);
          console.log(this.fileUrlList);
          this.showUrl = true;
        } else {
          this.$message.error(res.msg || "查询失败");
        }
      });
    },
    download(url) {
      console.log(url);
      let fileType = url.split(".")[url.split(".").length - 1];
      if (fileType == "pdf" || fileType == "PDF") {
        window.open(url);
      } else {
        window.location.href = url;
      }
    },
    handleExceed(files, fileList) {
      console.log(files, fileList);
      this.$message.warning(`最多上传1个文件！`);
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
      this.fileUrl1 = this.fileUrl1.filter((item) => {
        return item.fileExplain != file.name;
      });
      console.log(this.fileUrl1);
    },
    handleError(err, file, fileList) {
      console.log("err,file,fileList", err, file, fileList);
    },
    uploadFile(param) {
      const link = document.createElement("a");
      link.style.display = "none";
      uploadTalentFile(param.file)
        .then((res) => {
          console.log("res", res);
          if (res.success) {
            this.$message.success(res.msg || "上传成功");
            this.fileUrl1.push({
              fileExplain: param.file.name,
              file: res.data,
            });
          } else {
            // 上传失败删除列表展示
            this.$refs.dmtUploadFile.uploadFiles.splice(
              this.$refs.dmtUploadFile.uploadFiles.indexOf(res),
              1
            );
            console.log(this.$refs.dmtUploadFile.uploadFiles);
            this.$message.error(res.msg || "上传失败");
          }
        })
        .catch((err) => {
          this.fileList = [];
          this.$message.error(err.msg || "上传失败");
        });
    },
    init() {
      this.loading = true;
      let parmas = {
        name: this.searchForm.name,
        phone: this.searchForm.phone,
        state: this.searchForm.state,
        departmentCode: this.searchForm.departmentCode,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
      };
      mattersHousingList(parmas).then((res) => {
        this.loading = false;
        if (res.success) {
          this.pagination.total = res.data.total;
          if (res.data.total) {
            this.tableData = res.data.list.map((item) => {
              this.state = item.state;
              item.stateName = this.getSatusArr(item.state).stateName;
              item.type = this.getSatusArr(item.state).type;
              return item;
            });
            if (localStorage.getItem("userName") == "admin") {
              this.tableData = changeList(this.tableData);
            }
          } else {
            this.tableData = [];
          }
        } else {
          this.$message.error("网络错误");
        }
      });
    },
    onSubmit() {
      this.pagination.currentPage = 1;
      this.init();
    },
    jumpPage() {
      this.init();
    },
    view(row) {
      // console.log('row----',row);
      let params = {
        code: row.code,
        matterType: row.matterType,
      };
      let params2 = {
        appId: "1234",
        code: row.code,
        // name: this.userName
      };
      // 查询四个部门的记录  mattersHousingReason
      mattersHousingReason(params2).then((res) => {
        this.examineList = res.data;
        this.examineList.forEach((item) => {
          item.state == 8 ? (item.state = "通过") : (item.state = "拒绝");
        });
        this.totalList = this.examineList.concat(this.housingList);
      });
      // // 查询最后审批的记录
      mattersGetReason(params2).then((res) => {
        this.housingList = res.data;
        // console.log("this.housingList----", this.housingList);
        this.housingList.forEach((item) => {
          item.state == 1 ||
          item.state == 2 ||
          item.state == 3 ||
          item.state == 6 ||
          item.state == 7
            ? (item.state = "通过")
            : (item.state = "拒绝");
        });
        this.totalList = this.examineList.concat(this.housingList);
      });
      mattersHousingGet(params).then((res) => {
        console.log("res----", res);
        // get({ talentCode: res.data.talentCode }).then((res) => {
        this.category = res.data.categoryName;
        this.contentName = res.data.contentName;
        this.unitName = res.data.unitName;
        // });
        this.viewDetail = res.data;
        if (localStorage.getItem("userName") == "admin") {
          this.viewDetail.name = setName(this.viewDetail.name);
          this.viewDetail.phone = setTel(this.viewDetail.phone);
          this.viewDetail.idCard = setCertNo(this.viewDetail.idCard);
        }
        this.viewDetail.idCardPicture = res.data.pictureList.filter((item) => {
          return item.pictureType === 1;
        });
        this.viewDetail.bankPicture = res.data.pictureList.filter((item) => {
          return item.pictureType === 8;
        });
        this.viewDetail.contract = res.data.pictureList.filter((item) => {
          return (
            item.pictureType !== 1 &&
            item.pictureType !== 5 &&
            item.pictureType !== 6 &&
            item.pictureType !== 7 &&
            item.pictureType !== 8
          );
        });
        this.viewDetail.certificate = res.data.pictureList.find((item) => {
          return item.pictureType === 5;
        }).picture;
        this.viewDetail.voucher = res.data.pictureList.find((item) => {
          return item.pictureType === 6;
        }).picture;
        this.viewDetail.labour = [];
        res.data.pictureList.map((item) => {
          if (item.pictureType == 7) {
            return this.viewDetail.labour.push(item);
          }
        });
        this.viewShow = true;
      });
    },
    record(row) {
      // console.log("row---", row);
      mattersGetReason({ code: row.code }).then((res) => {
        let getReason = res.data;
        mattersHousingReason({ code: row.code }).then((res) => {
          let housingReason = res.data;
          let reason = housingReason.concat(getReason);
          this.recordList = reason.map((item) => {
            item.stateName = this.getSatusArr1(item.state)
              ? this.getSatusArr1(item.state).stateName
              : "未知状态";
            return item;
          });
        });
        this.recordShow = true;
      });
    },
    pass(row) {
      // console.log("row---", row);
      this.$prompt(`确定通过该申请的复审吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: "请输入原因",
        inputType: "textarea",
        type: "warning",
      })
        .then(({ value }) => {
          if (!value) {
            this.$message.error("未输入原因");
            return;
          }
          let params2 = {
            appId: "1234",
            code: row.code,
            //name: this.userName
          };
          // if (this.state == 1) {
          // mattersHousingGet({ appId: 1234, code: row.code }).then((res) => {
          //   console.log('res详情-----',res)
          //   this.realEstateAddress = res.data.realEstateAddress; // 住址
          //   this.square = res.data.square; // 房屋面积
          //   this.realEstateCard = res.data.realEstateCard; // 证号
          //   this.address = res.data.address; // 联系地址
          // });
          // 查询四个部门的记录  mattersHousingReason
          Promise.all([
            mattersHousingReason(params2),
            get({ talentCode: row.talentCode }),
            mattersHousingGet({ appId: 1234, code: row.code }),
          ]).then((res) => {
            console.log("res------", res);
            this.realEstateAddress = res[2].data.realEstateAddress; // 住址
            this.square = res[2].data.square; // 房屋面积
            this.realEstateCard = res[2].data.realEstateCard; // 证号
            this.address = res[2].data.address; // 联系地址
            this.arr1List = res[0].data;
            this.arr1List.forEach((item) => {
              item.reasonName.search("财政") != -1
                ? (this.arr1 = item.reason)
                : "";
              item.reasonName.search("税务") != -1
                ? (this.arr2 = item.reason)
                : "";
              item.reasonName.search("不动产") != -1
                ? (this.arr3 = item.reason)
                : "";
              item.reasonName.search("人社") != -1
                ? (this.arr4 = item.reason)
                : "";
            });
            if (row.guideName.search("商办") !== -1) {
              this.comdeed = 2;
              this.initTemplate(
                res[1],
                row,
                value,
                "人才购买商办用房契税补贴申请表"
              );
            } else {
              this.comdeed = 1;
              this.initTemplate(
                res[1],
                row,
                value,
                "人才购房契税补贴(住宅)申请表"
              );
            }
          });
          // }
        })
        .catch(() => {
          // console.log("取消审核");
        });
    },
    revocationHandle(row) {
      revocation({
        code: row.code,
      }).then((res) => {
        if (res.success) {
          this.$message.success("撤回成功");
          this.init();
        } else {
          this.$message.warning(res.msg || "撤回失败");
        }
      });
    },
    // 填充模板代码 ---
    initTemplate(res, row, value, tepname) {
      // console.log('res-----',res)
      // console.log('row-----',row)
      // console.log('value-----',value)
      // console.log('tepname-----',tepname)
      // console.log('1-----',this.realEstateAddress)
      // console.log('2-----',this.square)
      // console.log('3-----',this.realEstateCard)
      // console.log('4-----',this.address)
      let that = this;
      let arr = res.data;
      arr.name = arr.name ? arr.name : ""; // 姓名
      arr.idCard = arr.idCard ? arr.idCard : ""; // 身份证号
      arr.category = arr.category ? arr.category : ""; // 人才类型
      arr.unitName = arr.unitName ? arr.unitName : ""; // 工作单位
      arr.titleName = arr.titleName ? arr.titleName : ""; // 职称
      arr.birthPlace = arr.birthPlace ? arr.birthPlace : ""; // 联系地址
      arr.phone = arr.phone ? arr.phone : ""; // 手机号码
      arr.arr1 = this.arr1 || ""; // 财政
      arr.arr2 = this.arr2 || ""; // 税务
      arr.arr3 = this.arr3 || ""; // 不动产
      arr.arr4 = this.arr4 || ""; // 人设
      arr.arr5 = value || ""; // 住建
      arr.realEstateAddress = this.realEstateAddress || ""; // 住址
      arr.square = this.square || ""; // 房屋面积
      arr.realEstateCard = this.realEstateCard || ""; // 证号
      arr.address = this.address || ""; // 联系地址
      // 如果comdeed为1 就是住宅申请表 如果为2就是商办用房表
      if (this.comdeed == 1) {
        this.docxsrc = "./static/deedTax.docx"; //模板文件的位置
      } else if (this.comdeed == 2) {
        this.docxsrc = "./static/comdeedTax.docx"; //模板文件的位置
      }
      let docxname = tepname; //导出文件的名字
      // 读取并获得模板文件的二进制内容
      JSZipUtils.getBinaryContent(this.docxsrc, function (error, content) {
        // docxsrc是模板。我们在导出的时候，会根据此模板来导出对应的数据
        // 抛出异常
        if (error) {
          throw error;
        }
        // 创建一个PizZip实例，内容为模板的内容
        let zip = new PizZip(content);
        // 创建并加载docx templater实例对象
        let doc = new docxtemplater().loadZip(zip);
        // 设置模板变量的值
        // console.log("arr666---", arr);
        doc.setData({
          ...arr, // e中的数据可以再模板中直接使用
        });
        try {
          // 用模板变量的值替换所有模板变量
          doc.render();
        } catch (error) {
          // 抛出异常
          let e = {
            message: error.message,
            name: error.name,
            stack: error.stack,
            properties: error.properties,
          };
          console.log(
            JSON.stringify({
              error: e,
            })
          );
          throw error;
        }
        // 生成一个代表docxtemplater对象的zip文件（不是一个真实的文件，而是在内存中的表示）
        let out = doc.getZip().generate({
          type: "blob",
          mimeType:
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        });
        // console.log("out----", out);
        uploadWordFile(
          new File([out], "deed-text" + new Date().valueOf() + ".docx", {
            type: out.type,
          })
        ).then((res) => {
          // console.log("文件的res----", res);
          let params = {
            code: row.code,
            name: that.userName,
            state: 6,
            reviewerId: row.reviewerId,
            reason: value,
            fileUrl: res.data,
          };
          mattersHousingUpdate(params).then((res) => {
            console.log("复审通过后的返回值---", res);
            if (res.success) {
              that.$message.success(`复审通过`);
              that.init();
            } else {
              that.$message.error(res.msg || "审核失败");
            }
          });
        });
        // 将目标文件对象保存为目标类型的文件，并命名
        saveAs(out, docxname);
        // 住宅end
      });
    },
    passFinal(row) {
      console.log(row);
      this.rowDetail = row;
      this.fileList = [];
      this.fileUrl1 = [];
      this.finalShow = true;
    },
    passFinal1() {
      if (!this.textarea) {
        this.$message.error("未输入原因");
        return;
      }
      if (this.fileUrl1.length == 0) {
        this.$message.error("未上传附件");
        return;
      }
      let params = {
        code: this.rowDetail.code,
        name: this.userName,
        state: 3,
        reason: this.textarea,
        reviewerId: this.rowDetail.reviewerId,
        attachedPictureUploadDTO: this.fileUrl1,
      };
      mattersHousingUpdate(params).then((res) => {
        if (res.success) {
          this.finalShow = false;
          this.$message.success(`资料终审通过`);
          this.init();
        } else {
          this.$message.error(res.msg || "审核失败");
        }
      });
    },
    deny(row) {
      this.$prompt(`确定驳回该申请的审核吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: "请输入原因",
        inputType: "textarea",
      })
        .then(({ value }) => {
          if (!value) {
            this.$message.error("未输入原因");
            return;
          }
          let params = {
            code: row.code,
            name: this.userName,
            state: 4,
            reviewerId: row.reviewerId,
            reason: value,
          };

          mattersHousingUpdate(params).then(() => {
            this.$message.success(`审核驳回成功`);
            this.init();
          });
        })
        .catch(() => {
          // console.log("取消审核");
        });
    },
    getSatusArr(state) {
      return this.stateList.filter((item) => {
        return item.state === state;
      })[0];
    },
    getSatusArr1(state) {
      return this.stateList1.filter((item) => {
        return item.state === state;
      })[0];
    },
  },
  created() {
    this.userName = localStorage.getItem("userName");
    // this.searchForm.departmentCode = getQueryString("departmentCode") || ''; //原始
    this.searchForm.departmentCode = this.$route.query.departmentCode; // 修改
    this.init();
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/stylus/common';

.content {
  max-height: 60vh;
  overflow-y: auto;

  .cell {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;

    .label {
      width: 150px;
      color: #999;
      text-align: left;

      span {
        color: red;
        font-size: 12px;
      }
    }

    .value {
      color: #000;
      text-align: left;
    }
    .value1{
      color: red;
    }
    .value2{
      color: green;
    }

    .info {
      .item {
        width: 100%;
        text-align: left;
        color: #000;
        margin-bottom: 10px;
      }

      .item:last-child {
        margin-bottom: 0;
      }
    }
  }
}
</style>
