<template>
  <el-container class="problem_list">
    <el-main style="padding: 10px 10px" v-show="tableShow">
      <div class="content_wrapper">
        <el-table
          :data="tableData"
          border
          stripe
          v-loading="loading"
          :height="tableHeight"
          align="center"
          style="width: 100%"
        >
          <el-table-column
            prop="ordr1"
            label="序号"
            align="center"
            min-width="80"
          >
          </el-table-column>
          <el-table-column
            v-if="pageName === 'inspectionView'"
            prop="spfsnlType"
            label="专业"
            show-overflow-tooltip
            align="center"
            :formatter="formatterspfsnlType"
            min-width="120"
          >
          </el-table-column>
          <el-table-column
            prop="genus"
            label="检查内容"
            align="center"
            min-width="200"
          >
          </el-table-column>
          <el-table-column
            prop="focPblm"
            label="重点检查项目"
            align="center"
            min-width="260"
          >
          </el-table-column>
          <el-table-column
            v-if="pageName === 'inspectionIndex'"
            prop="sn"
            align="center"
            show-overflow-tooltip
            min-width="160"
            label="与问题清单对应的编号"
            >
          </el-table-column>
          <el-table-column
            prop="chkItem"
            label="具体检查项目"
            align="center"
            min-width="420"
          >
          </el-table-column>
          <el-table-column
            prop="chkGist"
            show-overflow-tooltip
            min-width="200"
            align="center"
            label="检查依据（法规及规范相应条款）"
          >
          </el-table-column>
          <el-table-column v-if="pageName === 'inspectionView'" label="检查结果" align="center" >
            <el-table-column label="无问题" align="center">
              <el-table-column
                prop="pblmNt"
                show-overflow-tooltip
                align="center"
                min-width="160"
                label="记录检查结果"
              >
              </el-table-column>
              <el-table-column
                prop="isPblm"
                show-overflow-tooltip
                align="center"
                min-width="160"
                label="直接勾选"
              >
                <template #default="scope">
                  <div v-for="item in ynList" :key="item">
                    <span v-if="scope.row.isPblm === item.value">☑</span
                    ><span v-else>□</span><span>{{ item.label }}</span>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column label="有问题" align="center">
              <el-table-column
                prop="pblmDesc"
                align="center"
                show-overflow-tooltip
                min-width="160"
                label="问题描述（完成底稿）"
              >
              </el-table-column>
              <el-table-column
                prop="pblmPasi"
                align="center"
                show-overflow-tooltip
                min-width="160"
                label="问题定性"
              >
              <template #default="scope">
                <div v-for="item in problemType" :key="item">
                  <span v-if="scope.row.scale === item.value">☑</span
                  ><span v-else>□</span><span>{{ item.label }}</span>
                </div>
              </template>
            </el-table-column>
              <el-table-column
                prop="subjectNames"
                show-overflow-tooltip
                align="center"
                min-width="160"
                label="确认责任单位"
              >
              </el-table-column>
              <el-table-column
                prop="pblmMasteryLevel"
                align="center"
                show-overflow-tooltip
                min-width="160"
                label="问题掌握标准"
              >
              </el-table-column>
            </el-table-column>
            <el-table-column
              prop="nt"
              align="center"
              show-overflow-tooltip
              min-width="160"
              label="其他情况说明"
            >
            </el-table-column>
          </el-table-column>
          <el-table-column
            v-if="pageName === 'inspectionIndex'"
            prop="pblmMasteryLevel"
            align="center"
            show-overflow-tooltip
            min-width="160"
            label="问题掌握标准"
            >
          </el-table-column>
          <el-table-column
            prop="chkFrp"
            show-overflow-tooltip
            align="center"
            min-width="160"
            label="检查资料或部位"
          >
          </el-table-column>
          <el-table-column
            v-if="pageName === 'inspectionView'"
            prop="subName"
            show-overflow-tooltip
            align="center"
            min-width="160"
            label="参考范本"
          >
            <template #default="scope">
              <div>
                <p v-for="item in scope.row.fileList" :key="item.id">
                  <a
                    v-if="item.bizType === '1'"
                    :href="`${hostUrl}/${item.filePath}`"
                    target="_blank"
                    rel="noopener noreferrer"
                  >
                    {{ item.fileName }}
                  </a>
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            v-if="pageName === 'inspectionView'"
            prop="subName"
            show-overflow-tooltip
            align="center"
            min-width="160"
            label="佐证资料（上传照片或扫描件为主）"
          >
            <template #default="scope">
              <div>
                <p v-for="item in scope.row.fileList" :key="item.id">
                  <a
                    v-if="item.bizType === '2'"
                    :href="`${hostUrl}/${item.filePath}`"
                    target="_blank"
                    rel="noopener noreferrer"
                  >
                    {{ item.fileName }}
                  </a>
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            v-if="pageName === 'inspectionView'"
            prop="pblmsDesc"
            show-overflow-tooltip
            align="center"
            min-width="160"
            label="备注"
          >
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            width="130"
          >
            <template #default="scope">
              <el-button
                type="text"
                size="small"
                @click="toEditProblem(scope.row)"
                >编辑</el-button
              >
              <el-button
                @click="deleteProblem(scope.row)"
                type="text"
                size="small"
                >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="margin-left: 30px"
          :pager-count="5"
          :current-page="pageIndex"
          background
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :page-sizes="[10, 20, 50, 100]"
          @current-change="pageIndexChange"
          @size-change="handleSizeChange"
        ></el-pagination>
      </div>
      <add-problem-com
        v-if="addFileVisiual"
        :titleType="'编辑'"
        :rowData="rowData"
        :currentNodeId="currentNodeId"
        :listType="type"
        :pageName="pageName"
        :objId="objId"
        @dialogClose="dialogClose"
      ></add-problem-com>
    </el-main>
  </el-container>
</template>
<script>
import request from "@/utils/gw_ajax_request.js";
// import addProblemCom from './dialogCom/addProblemCom.vue'
import ProblemModifyCom from "./dialogCom/ProblemModifyCom.vue";
import ProblemDetailCom from "./dialogCom/ProblemDetails.vue";
import ExportExcel from "./dialogCom/ExportExcel.vue";
import ExportWord from "./dialogCom/ExportWord.vue";
import axios from "axios";
import { hostUrl } from "@/utils/global_variable.js";
import { TacObiPblmHbPage, TacObiPblmHbInsert } from "@/api/InspectionReport.js";
import addProblemCom from "./dialogCom/addProblemView.vue";

export default {
  props: [
    "currentNodeId",
    "type",
    "objId",
    "pertype",
    "submitStatus",
    "rightTableName",
    "pageName",
  ],
  data() {
    return {
      problemType: [
        { label: "一般", value: "0" },
        { label: "较重", value: "1" },
        { label: "严重", value: "2" },
      ],
      pblmPasi: "", //严重程度
      pblmNm: "",
      subjectNames: "", //单位名称，多个单位逗号拼接字符串
      ifCasePblm: "",
      tableData: [],
      baseInfo: {
        nm: "",
        condition: "",
        comment: "",
      },
      // problemId: '',
      pageIndex: 1,
      pageSize: 20,
      total: 0,
      loading: false,

      // showFileVisiual: false,
      addFileVisiual: false,
      modifyFileVisiual: false,
      // exportEvent: false,//导出对话框v-if
      // exportWordDialog: false,
      // problemId: '',
      name: "",
      tableHeight: window.innerHeight - 245,
      //   showtypical:"",
      professionList: [
        { label: "前期与设计", value: "1" },
        { label: "建设管理", value: "2" },
        { label: "计划下达与执行", value: "3" },
        { label: "资金使用与管理", value: "4" },
        { label: "质量行为", value: "5" },
        { label: "质量实体", value: "6" },
        { label: "工程安全", value: "7" },
      ],
      ynList: [
        { label: "是", value: "1" },
        { label: "否", value: "0" },
      ],
      rowData: {},
      tableShow: false,
    };
  },
  components: {
    addProblemCom,
    ProblemModifyCom,
    ExportExcel,
    ExportWord,
    ProblemDetailCom,
  },
  computed: {
    persId() {
      return localStorage.getItem("userid")
        ? localStorage.getItem("userid")
        : "1098101939614724096";
    },
  },
  created() {
    // let currentOrgId = localStorage.getItem("currentOrgId")
    // if(currentOrgId == '036'){
    //   this.showtypical=false;
    // }else{
    //   this.showtypical = true;
    // }
  },
  mounted() {
    console.log(
      "---problemView----mounted--------",
      this.currentNodeId,
      this.type,
      this.pageName
    );
  },
  activated() {},
  methods: {
    formatterspfsnlType(row, column) {
      const data = this.professionList.filter((item) => {
        return item.label === row.spfsnlType;
      });
      if (data.length > 0) {
        return data[0].label;
      } else {
        return "";
      }
    },
    turnType() {
      if (this.type == "7") {
        this.name = "参建单位";
      } else if (this.type == "6") {
        this.name = "工程安全";
      } else if (this.type == "5") {
        this.name = "质量";
      } else if (this.type == "4") {
        this.name = "资金使用与管理";
      } else if (this.type == "3") {
        this.name = "计划下达与执行";
      } else if (this.type == "2") {
        this.name = "建设管理";
      } else if (this.type == "1") {
        this.name = "前期与设计";
      }
    },
    getProblemList(val) {
      this.turnType();
      this.loading = true;
      const params = {
        spfsnlType: this.name,
        // currentNodeId:this.currentNodeId,
        // objId: this.currentNodeId,
        objId: this.objId,
        pageSize: this.pageSize,
        pageNum: this.pageIndex,
        isPblm:val
      };
      TacObiPblmHbInsert(params)
        .then((res1) => {
          TacObiPblmHbPage(params)
            .then((res) => {
              if (res.data.list.length > 0) {
                res.data.list.forEach((item, index) => {
                  item.ordr1 = index + 1;
                });
              }
              this.tableData = res.data.list;
              this.total = res.data.total;
              this.loading = false;
              this.tableShow = true;
            })
            .catch((err) => {
              this.loading = false;
            });
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    getProblemList1(val) {
      this.turnType();
      this.loading = true;
      const params = {
        spfsnlType: this.name,
        objId: this.objId,
        pageSize: this.pageSize,
        pageNum: this.pageIndex,
        isPblm:val
      };
          TacObiPblmHbPage(params)
            .then((res) => {
              if (res.data.list.length > 0) {
                res.data.list.forEach((item, index) => {
                  item.ordr1 = index + 1;
                });
                this.tableData = res.data.list;
                this.total = res.data.total;
                this.loading = false;
                this.tableShow = true;
              }
            })
            .catch((err) => {
              this.loading = false;
            });
    },

    // toAddFile() {
    //     Object.assign(this.rowData,row)
    //     this.addFileVisiual = true
    // },
    // //导出Excel
    // exportExcel() {
    //     this.exportEvent = true
    // },
    // //导出Word
    // exportWord() {
    //     this.exportWordDialog = true
    // },
    toEditProblem(row) {
      Object.assign(this.rowData, row);
      this.addFileVisiual = true;
    },
    deleteProblem(row) {
      this.$confirm("确认删除该问题吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        // request.get(`/tac/obj/pblmstb/hb/delete/${row.id}`).then(res=>{
        request.get(`/tac/obj/pblm/hb/delete/${row.id}`).then((res) => {
          if (res.success) {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.getProblemList();
          } else {
            this.$message({
              type: "error",
              message: res.message,
            });
          }
        });
      });
    },
    pageIndexChange(val) {
      this.pageIndex = val;
      this.getProblemList();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getProblemList();
    },
    dialogClose() {
      this.addFileVisiual = false;
      // this.modifyFileVisiual = false
      // this.exportEvent = false
      // this.showFileVisiual = false
      // this.exportWordDialog = false
      this.getProblemList();
    },
    pblmPasiChange(val) {
      this.getProblemList();
    },
    handleSelectionChange(val) {
      let problemArr = [];
      val.forEach((ele) => {
        problemArr.push(ele.id);
      });
      this.problemId = problemArr.join(",");
    },
    // showJobFile() {
    //     // this.exportWordDialog = true
    //     this.openPageoffice()
    // },
    // isUsePo() {
    //     // 是否启用PageOffice
    //     let _this = this;
    //     axios.defaults.timeout = 2000;
    //     axios.get('/pageofficePath/pageoffice/getUsePo').then((res) => {
    //         let data = res.data
    //         if (data.isUse == 'true') {
    //             _this.exportWordDialog = false
    //             // 打开PageOffice
    //             _this.openPageoffice()
    //         } else {
    //             _this.exportWordDialog = true
    //         }
    //     }).catch(function (err) {
    //         _this.exportWordDialog = true
    //     })
    // },
    // openPageoffice: function () {

    //     let host = hostUrl;
    //     let nginx = '/pageofficePath/';
    //     let rgstrId = this.currentNodeId;
    //     let type = "20" + this.type;
    //     let persId = this.persId;
    //     let href = 'pageoffice://|' + host + nginx + '/pageoffice/pblmlist/word/' + type + '/' + rgstrId + '?persId=' + persId + '&pblmId=' + this.problemId + '|width=1100px;height=800px;ismodal=false;||91A4EE66EC1921F376873E85D6C74FFA|A890649B44577C32CE1930797E1299F9';
    //     let a = document.createElement('a'); // 创建a标签
    //     a.setAttribute('href', href);// href链接
    //     a.click();// 自执行点击事件
    //     console.log(href)
    // },
    // // 查看问题详情
    // toCheckDetail(row) {
    //     this.problemId = row.id
    //     this.showFileVisiual = true
    // }
  },
  watch: {
    currentNodeId(val) {
      // this.getProblemList();
      this.tableShow = false;
    },
    type(val) {
      // this.getProblemList();
      this.tableShow = false;
    },
    // backStatus(val) {
    //     if (val) {
    //         //回退状态为成功时
    //         this.getProblemList()
    //     }
    // }
  },
};
</script>
<style>
.problem_list {
  .project_title {
    line-height: 50px;
    text-align: center;
    color: #333;
    border-bottom: solid 1px #eee;
  }

  h4 {
    line-height: 50px;
    color: #444;
  }

  .operate_btn {
    float: right;
    margin-bottom: 10px;
  }

  .inspPblmCate {
    padding: 2px 10px;
    border-radius: 10px;
    color: #ffffff;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
  }

  .el-form-item__label {
    font-size: large;
    color: #333;
  }

  .el-form--inline .el-form-item {
    margin-right: 6px;
  }

  .el-table__header th {
    font-size: large !important;
  }

  tr.el-table__row {
    font-size: large;
  }
}
</style>
