<template>
  <div class="app-container">
    <div ref="sousuH">
      <!-- 搜索工作栏 -->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
        <el-form-item label="任务名称" prop="taskName">
          <el-input v-model="queryParams.taskName" placeholder="请输入任务名称" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="任务类型" prop="taskType">
          <el-select v-model="queryParams.taskType" placeholder="请选择任务类型" clearable size="small" @change="typeChange">
            <el-option v-for="dict in this.getDictDatas(DICT_TYPE.TASK_TYPE)" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="任务状态" prop="taskStatus">
                            <el-select v-model="queryParams.taskStatus" placeholder="请选择任务状态" clearable size="small">
                              <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                            </el-select>
                          </el-form-item> -->
        <!-- <el-form-item label="任务积分" prop="taskScore">
          <el-input v-model="queryParams.taskScore" placeholder="请输入任务积分" clearable @keyup.enter.native="handleQuery" />
        </el-form-item> -->
        <el-form-item label="检查日期" prop="inspectTime">
          <el-date-picker v-model="queryParams.inspectTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
            type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
            :default-time="['00:00:00', '23:59:59']" />
        </el-form-item>
        <!-- <el-form-item label="所属单位" prop="orgId">
                            <el-input v-model="queryParams.orgId" placeholder="请输入所属单位" clearable @keyup.enter.native="handleQuery" />
                          </el-form-item> -->
        <!-- <el-form-item label="检查结果" prop="inspResult">
                            <el-select v-model="queryParams.inspResult" placeholder="请选择检查结果" clearable size="small">
                              <el-option v-for="dict in this.getDictDatas(DICT_TYPE.DENGER_HANDLE)" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                            </el-select>
                          </el-form-item> -->
        <!-- <el-form-item label="是否隐患" prop="isdenger">
                            <el-select v-model="queryParams.isdenger" placeholder="请选择是否隐患" clearable size="small">
                              <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" :key="dict.value"
                                :label="dict.label" :value="dict.value" />
                            </el-select>
                          </el-form-item> -->
        <!-- <el-form-item label="状态" prop="status">
                            <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
                              <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="dict.value" :label="dict.label"
                                :value="dict.value" />
                            </el-select>
                          </el-form-item> -->
        <el-form-item prop="inspectName">
          <template #label>
            <div style="min-width: auto;">检查项名称</div>
          </template>
          <el-input v-model="queryParams.inspectName" placeholder="请输入检查项名称" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 操作工具栏 -->
      <el-row :gutter="10" class="mb8">
        <!-- <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                v-hasPermi="['backend:inspect-his:create']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                :loading="exportLoading" v-hasPermi="['backend:inspect-his:export']">导出</el-button>
            </el-col> -->
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    </div>
    <!-- 列表 -->
    <!-- <el-table v-loading="loading" :data="list" :height="list.length ? tableHeight : 'auto'"> -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="检查项名称" align="center" prop="insp_name" width="150" />
      <el-table-column label="任务名称" align="center" prop="task_name" width="130" />
      <el-table-column label="任务类型" align="center" prop="task_type">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.TASK_TYPE" :value="scope.row.task_type" />
        </template>
      </el-table-column>
      <el-table-column label="任务内容" align="center" prop="description" />
      <el-table-column label="任务状态" align="center" prop="taskStatus" width="120">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.TASK_STATUS" :value="scope.row.taskStatus" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="任务积分" align="center" prop="taskScore" /> -->
      <el-table-column label="检查日期" align="center" prop="inspect_time" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.inspect_time) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属单位" align="center" prop="org_name" width="150" />
      <!-- <el-table-column label="检查结果" align="center" prop="inspResult">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.DENGER_HANDLE" :value="scope.row.inspResult" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="检查频次" align="center" prop="inspectFrequency">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.CHECK_FRE" :value="scope.row.inspectFrequency" />
        </template>
      </el-table-column> -->
      <el-table-column label="是否隐患" align="center" prop="isdenger">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.isdenger" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="状态" align="center" prop="status">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleSee(scope.row)"
            v-hasPermi="['backend:inspect-his:update']">查看</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['backend:inspect-his:update']">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['backend:inspect-his:delete']">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="800px" v-dialogDrag append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务名称" prop="taskName">
              <el-input v-model="form.taskName" placeholder="请输入任务名称" /> </el-form-item></el-col>
          <el-col :span="12"><el-form-item label="任务类型" prop="taskType">
              <el-select v-model="form.taskType" placeholder="请选择任务类型" style="width: 100%">
                <el-option v-for="dict in this.getDictDatas(DICT_TYPE.TASK_TYPE)" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select> </el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12"><el-form-item label="任务状态" prop="taskStatus">
              <el-radio-group v-model="form.taskStatus" style="width: 100%">
                <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="dict.value"
                  :label="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item></el-col>
          <!-- <el-col :span="12">
            <el-form-item label="任务积分" prop="taskScore">
              <el-input v-model="form.taskScore" placeholder="请输入任务积分" /> </el-form-item></el-col> -->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查日期" prop="inspectTime">
              <el-date-picker clearable v-model="form.inspectTime" type="date" value-format="timestamp"
                placeholder="选择检查日期" style="width: 100%" /> </el-form-item></el-col>
          <el-col :span="12">
            <el-form-item label="所属单位" prop="orgId">
              <el-input v-model="form.orgId" placeholder="请输入所属单位" /> </el-form-item></el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="检查结果" prop="inspResult">
              <el-select v-model="form.inspResult" placeholder="请选择检查结果" style="width: 100%">
                <el-option v-for="dict in this.getDictDatas(DICT_TYPE.DENGER_HANDLE)" :key="dict.value"
                  :label="dict.label" :value="dict.value" />
              </el-select> </el-form-item></el-col>
          <el-col :span="12">
            <el-form-item label="检查频次" prop="inspectFrequency">
              <el-select v-model="form.inspectFrequency" placeholder="请选择检查频次" style="width: 100%">
                <el-option v-for="dict in this.getDictDatas(DICT_TYPE.CHECK_FRE)" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select> </el-form-item></el-col>
        </el-row> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位类型" prop="orgType">
              <el-select v-model="form.orgType" placeholder="请选择单位类型" style="width: 100%">
                <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMPANY_inspectitem_kind)" :key="dict.value"
                  :label="dict.label" :value="dict.value" />
              </el-select> </el-form-item>
          </el-col>
          <el-col :span="12"><el-form-item label="检查项名称" prop="inspectName">
              <el-input v-model="form.inspectName" placeholder="请输入检查项名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否隐患" prop="isdenger">
              <el-radio-group v-model="form.isdenger" style="width: 100%">
                <el-radio v-for="dict in this.getDictDatas(
                  DICT_TYPE.INFRA_BOOLEAN_STRING
                )" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status" style="width: 100%">
                <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="dict.value"
                  :label="parseInt(dict.value)">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row>
          <el-col :span="24"><el-form-item label="任务内容">
              <editor v-model="form.taskContent" :min-height="192" style="width: 100%" />
            </el-form-item></el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 对话框(添加 / 修改) -->
    <el-dialog title="查看" :visible.sync="opensee" width="800px" v-dialogDrag append-to-body class="detail">
      <el-form ref="form" :model="form" label-width="auto" label-position="left" :rules="rules">
        <el-row>
          <el-col :span="12">
            <el-form-item label="检查项名称" prop="inspName">
              <strong>{{ form.inspName }}</strong>
            </el-form-item></el-col>
          <el-col :span="12">
            <el-form-item label="任务名称" prop="taskName">
              <strong>{{ form.taskName }}</strong>
            </el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="任务类型" prop="taskType">
              <dict-tag :type="DICT_TYPE.TASK_TYPE" :value="form.taskType" />
            </el-form-item></el-col>
          <el-col :span="12">
            <el-form-item label="任务状态" prop="taskStatus">
              <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="form.taskStatus" />
            </el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="任务内容">
              <strong>{{ form.taskContent }}</strong>
            </el-form-item></el-col>
          <!-- <el-col :span="12">
            <el-form-item label="任务积分" prop="taskScore">
              <strong>{{ form.taskScore }}</strong>
            </el-form-item></el-col> -->
          <el-col :span="12">
            <el-form-item label="检查日期" prop="inspectTime">
              <strong>{{ parseTime(form.inspectTime) }}</strong>
            </el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属单位" prop="orgId">
              <strong>{{ form.orgId }}</strong>
            </el-form-item></el-col>
          <el-col :span="12">
            <el-form-item label="单位类型" prop="orgType">
              <dict-tag :type="DICT_TYPE.COMPANY_inspectitem_kind" :value="form.orgType" /> </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="检查频次" prop="inspectFrequency">
              <dict-tag :type="DICT_TYPE.CHECK_FRE" :value="form.inspectFrequency" />
            </el-form-item></el-col>
            <el-col :span="12">
            <el-form-item label="检查结果" prop="inspResult">
              <dict-tag :type="DICT_TYPE.DENGER_HANDLE" :value="form.inspResult" />
            </el-form-item></el-col>
        </el-row> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否隐患" prop="isdenger">
              <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="form.isdenger" />
            </el-form-item></el-col>
          <!-- <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="form.status" />
            </el-form-item>
          </el-col> -->
        </el-row>
        <!-- <el-row>
        
        </el-row> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="opensee = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>







import {
  createInspectHis,
  updateInspectHis,
  deleteInspectHis,
  getInspectHis,
  getInspectHisPage,
  exportInspectHisExcel,
} from "@/api/backend/inspectHis";
import Editor from "@/components/Editor";
import { DICT_TYPE, getDictDatas, getDictDatas2 } from "@/utils/dict";
import { getTableHeight } from "@/utils/ruoyi.js";
export default {
  name: "InspectHis",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检查项历史列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        taskName: null,
        taskType: null,
        taskStatus: null,
        taskScore: null,
        inspectTime: [],
        orgId: null,
        inspResult: null,
        inspectFrequency: null,
        isdenger: null,
        status: null,
        inspectName: null,
      },
      // 表单参数
      // 表单参数
      form: {
        status: 0
      },
      // 表单校验
      rules: {
        status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
        // taskScore: [
        //   { message: '只能是数字', trigger: 'change', pattern: /^(([1-9]\d{0,3})|0)?$/, }
        // ],
      },
      // 是否显示查看弹出层
      opensee: false,
      tableHeight: "",
      searchType: "",
      // searchName:"",
      // searchMisson:'',
    };
  },
  props: ["orgId", "taskType"],
  watch: {
    orgId: { //深度监听，可监听到对象、数组的变化
      handler(newV, oldV) {
        this.getList()
      },
      deep: true
    },
    // taskType: { //深度监听，可监听到对象、数组的变化

    //   handler(newV, oldV) {
    //     this.getList()
    //   },
    //   deep: true
    // }
  },
  mounted() {

    console.log(typeof 'this.taskType :>> ', typeof this.taskType);
    //挂载window.onresize事件(动态设置table高度)
    window.addEventListener("resize", () => {
      this.$nextTick(() => {
        if (this.$refs["sousuH"]) {
          this.tableHeight = getTableHeight(
            this.$refs["sousuH"].clientHeight + 200
          );
        }
      });
    });
  },

  created() {
    this.getList();
    this.$nextTick(() => {
      this.tableHeight = getTableHeight(
        this.$refs["sousuH"].clientHeight + 200
      );
    });
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      this.queryParams.orgId = this.orgId
      this.queryParams.taskType = this.taskType
      // 执行查询
      getInspectHisPage(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        taskName: undefined,
        taskType: undefined,
        taskContent: undefined,
        taskStatus: undefined,
        // taskScore: undefined,
        inspectTime: undefined,
        orgId: undefined,
        inspResult: undefined,
        inspectFrequency: undefined,
        orgType: undefined,
        isdenger: undefined,
        status: 0,
        inspectName: undefined,
      };

      this.form.orgId = this.orgId
      this.form.taskType = this.taskType
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNo = 1;
      // this.getList();
      // getInspectHisPage({ taskName: this.queryParams.taskName, taskType: this.searchType, inspName: this.queryParams.inspectName }).then(res => {
      //   console.log(res, 'ssss');
      // })
      const params = {
        taskName: this.queryParams.taskName && this.queryParams.taskName,
        taskType: this.searchType,
        inspName: this.queryParams.inspectName && this.queryParams.inspectName,
      };

      getInspectHisPage(params).then(res => {
        this.list = res.data.list
        console.log(res, 'ssss');
      });

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加检查项历史";
    },

    /** 查看按钮操作 */
    handleSee(row) {
      this.reset();
      const id = row.id;
      getInspectHis(id).then((response) => {
        this.form = response.data;
        this.opensee = true;
        this.title = "查看检查项历史";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getInspectHis(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改检查项历史";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateInspectHis(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createInspectHis(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除名称为"' + row.insp_name + '"的数据项?')
        .then(function () {
          return deleteInspectHis(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      // 执行导出
      this.$modal
        .confirm("是否确认导出?")
        .then(() => {
          this.exportLoading = true;
          return exportInspectHisExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "API 访问日志.xls");
          this.exportLoading = false;
        })
        .catch(() => { });
    },
    typeChange(e) {
      // console.log(e,'change');
      this.searchType = e
      getInspectHisPage({ pageNo: 1, pageSize: 10, taskType: e }).then(res => {
        this.list = res.data.list
        // console.log(res,'ooo');
      })
    }
  },
};
</script>
<style lang="scss" scoped>
.detail {

  ::v-deep .el-form-item__label,
  ::v-deep .el-form-item__content {
    font-size: 16px;
    color: #86909C;
    font-weight: 500;
  }

  ::v-deep .el-form-item__content {
    color: #444444 !important;
    font-size: 14px;
  }
}
</style>