<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <org-tree
          v-model="queryParams.orgId"
          @defaultKey="getDefaultKey"
          @checkChange="checkChange"
          @click="clickTreeNode"
          :businessTree="true"
        ></org-tree>
      </el-col>
      <el-col :span="20" :xs="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="关键字" prop="searchKey">
            <el-input
              v-model="queryParams.searchKey"
              placeholder="请输入关键字"
              clearable
            />
          </el-form-item>
          <el-form-item prop="confirmStatus" label="确认状态">
            <el-select
              prop="confirmStatus"
              label="确认状态"
              v-model="queryParams.confirmStatus"
              placeholder="请选择确认状态"
              clearable
            >
              <el-option
                v-for="dict in dict.type.question_confirm_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="reformStatus" label="整改状态">
            <el-select
              prop="reformStatus"
              label="整改状态"
              v-model="queryParams.reformStatus"
              placeholder="请选择整改状态"
              clearable
            >
              <el-option
                v-for="dict in dict.type.question_reform_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="发现日期" prop="submitRange">
            <el-date-picker
              clearable
              v-model="queryParams.submitRange"
              type="daterange"
              format="yyyy-MM-dd"
              placeholder="请选择发现日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <!-- <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:question:export']"
              >导出</el-button
            >
          </el-col> -->
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
            :columns="columns"
          ></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          :data="questionList"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            v-if="columns[0].visible"
          ></el-table-column>
          <el-table-column
            label="隐患所属机构名称"
            align="center"
            prop="orgName"
            v-if="columns[1].visible"
          />
          <el-table-column
            label="来源任务名称"
            align="center"
            prop="srcTaskName"
            v-if="columns[2].visible"
          />
          <el-table-column
            label="检查内容"
            align="center"
            prop="checkContent"
            v-if="columns[3].visible"
          />
          <el-table-column
            label="隐患描述"
            align="center"
            prop="questionDesc"
            v-if="columns[4].visible"
          />
          <el-table-column
            label="提出人名称"
            align="center"
            prop="submitorName"
            width="100px"
            v-if="columns[5].visible"
          />
          <el-table-column
            label="发现日期"
            align="center"
            prop="submitTime"
            width="120"
            v-if="columns[6].visible"
          >
            <template slot-scope="scope">
              <span>{{
                dayjs(scope.row.submitTime).format("YYYY-MM-DD")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="确认状态"
            align="center"
            width="80px"
            prop="confirmStatus"
            v-if="columns[7].visible"
          >
            <template slot-scope="scope">
              <span>{{
                getLabel(
                  dict.type.question_confirm_status,
                  scope.row.confirmStatus
                )
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="整改状态"
            align="center"
            prop="reformStatus"
            width="80px"
            v-if="columns[8].visible"
          >
            <template slot-scope="scope">
              <span>{{
                getLabel(
                  dict.type.question_reform_status,
                  scope.row.reformStatus
                )
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-tickets"
                @click="handleDetail(scope.row)"
                v-hasPermi="['question:list:query']"
                >详情</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-s-check"
                @click="handleConfirm(scope.row)"
                v-hasPermi="['question:list:confirm']"
                v-if="scope.row.orgId==orgId && scope.row.confirmStatus==0"
                >隐患确认</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-s-flag"
                @click="handleConfirmDissent(scope.row)"
                v-hasPermi="['question:list:confirmDissent']"
                v-if="scope.row.submitorId==userId && scope.row.confirmStatus==1"
                >异议审批</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-s-unfold"
                @click="handleReform(scope.row)"
                v-hasPermi="['question:list:reform']"
                v-if="scope.row.orgId==orgId && scope.row.confirmStatus==2 && scope.row.reformStatus!=11"
                >整改</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <Dialog ref="dialog" @success="getList()"></Dialog>
  </div>
</template>

<script>
import {
  listQuestion,
} from "@/api/question/list.js";
import OrgTree from "@/components/orgTree";
import Dialog from "./dialog.vue";
import { mapGetters } from "vuex";
import dayjs from "dayjs";
import { getLabel } from "./../../commonOption";
export default {
  name: "Question",
  data() {
    return {
      // 遮罩层
      loading: true,
      // // 选中数组
      // ids: [],
      // // 非单个禁用
      // single: true,
      // // 非多个禁用
      // multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 隐患问题清单表格数据
      questionList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgId: this.orgId,
        submitRange: null,
        confirmStatus: null,
        reformStatus: null,
        checkSub: true,
      },
      columns: [
        { key: 0, label: `序号`, visible: true },
        { key: 1, label: `隐患所属机构`, visible: true },
        { key: 2, label: `来源任务`, visible: true },
        { key: 3, label: `检查内容`, visible: true },
        { key: 4, label: `隐患描述`, visible: true },
        { key: 5, label: `提出人`, visible: true },
        { key: 6, label: `发现日期`, visible: true },
        { key: 7, label: `确认状态`, visible: true },
        { key: 8, label: `整改状态`, visible: true },
      ],
    };
  },
  dicts: ["question_confirm_status", "question_reform_status"],
  components: { OrgTree, Dialog },
  computed: {
    ...mapGetters(["orgId","userId"]),
  },
  created() {},
  methods: {
    dayjs,
    getLabel,
    /** 查询隐患问题清单列表 */
    getList() {
      this.loading = true;
      listQuestion(this.queryParams).then((response) => {
        this.questionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map((item) => item.id);
    //   this.single = selection.length !== 1;
    //   this.multiple = !selection.length;
    // },
    handleDetail(row){
      this.$refs.dialog.show(row,'detail')
    },
    handleConfirm(row){
      this.$refs.dialog.show(row,'confirm')
    },
    handleConfirmDissent(row){
      this.$refs.dialog.show(row,'confirmDissent')
    },
    handleReform(row){
      this.$refs.dialog.show(row,'reform')
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/question/export",
        {
          ...this.queryParams,
        },
        `question_${new Date().getTime()}.xlsx`
      );
    },
    //单选框状态改变
    checkChange(state) {
      this.queryParams.checkSub = state;
      this.getList();
    },
    getDefaultKey(key) {
      this.queryParams.orgId = key;
      this.getList();
    },
    // 节点单击事件
    clickTreeNode(data) {
      this.queryParams.orgId = data.id;
      this.getList();
    },
  },
};
</script>
