<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col :span="4" :xs="24">
        <org-tree
          v-model="queryParams.orgId"
          @defaultOrg="getDefaultOrg"
          @checkChange="checkChange"
          @click="clickTreeNode"
        ></org-tree>
      </el-col>
      <el-col :span="20" :xs="24">
        <div class="main-right-box">
          <!--    搜索条件    -->
          <div class="main-search-box">
            <el-form
              :model="queryParams"
              ref="queryForm"
              size="small"
              :inline="true"
              v-show="showSearch"
              label-width="80px"
            >
              <el-form-item label="关键字" prop="searchKey" label-width="60px">
                <el-input
                  v-model="queryParams.searchKey"
                  placeholder="请输入标准依据、隐患描述"
                  clearable
                  maxlength="50"
                />
              </el-form-item>
              <el-form-item prop="confirmStatus" label="隐患状态">
                <el-select
                  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">
                <DataRangePicker
                  clearable
                  v-model="queryParams.submitRange"
                  key="daterange"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </DataRangePicker>
              </el-form-item>
              <el-form-item> </el-form-item>
            </el-form>

            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="handleQuery"
                  >搜索</el-button
                >
                <el-button
                  type="primary"
                  icon="el-icon-refresh"
                  size="mini"
                  @click="resetQuery"
                  >重置</el-button
                >
                <el-button
                  type="primary"
                  icon="el-icon-download"
                  size="mini"
                  @click="handleExport"
                  >导出</el-button
                >
              </el-col>
              <right-toolbar
                :showSearch.sync="showSearch"
                @queryTable="getList"
                :columns="columns"
              ></right-toolbar>
            </el-row>
          </div>

          <el-table
            v-loading="loading"
            :data="questionList"
            height="640"
            size="small"
          >
            <el-table-column
              header-align="center"
              type="index"
              label="序号"
              align="center"
              width="60px"
              v-if="columns[0].visible"
            >
            <template slot-scope="scope">
              {{(queryParams.pageNum-1)*queryParams.pageSize+scope.$index+1}}
            </template>
          </el-table-column>
            <el-table-column
              header-align="center"
              label="机构名称"
              prop="orgName"
              v-if="columns[1].visible"
            />
            <el-table-column
              header-align="center"
              label="隐患来源"
              prop="srcTaskName"
              v-if="columns[2].visible"
            />
            <el-table-column
              header-align="center"
              label="标准依据"
              prop="checkContent"
              v-if="columns[3].visible"
            >
              <template slot-scope="scope">
                <pre>{{ scope.row.checkContent }}</pre>
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              label="隐患描述"
              prop="questionDesc"
              v-if="columns[4].visible"
            />
            <el-table-column
              header-align="center"
              label="提出人"
              align="center"
              prop="submitorName"
              width="100px"
              v-if="columns[5].visible"
            />
            <el-table-column
              header-align="center"
              label="发现时间"
              align="center"
              prop="submitTime"
              width="170px"
              v-if="columns[6].visible"
            >
              <template slot-scope="scope">
                <span>{{
                  dayjs(scope.row.submitTime).format("YYYY-MM-DD HH:mm:ss")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              label="隐患状态"
              width="100px"
              align="center"
              prop="confirmStatus"
              v-if="columns[7].visible"
            >
              <template slot-scope="scope">
                <span>{{
                  getLabel(
                    dict.type.question_confirm_status,
                    scope.row.overdueStatus?scope.row.overdueStatus:scope.row.confirmStatus
                  )
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              label="操作"
              width="180"
              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
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </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";
import DataRangePicker from "@/components/dateTime/daterange.picker.vue";
export default {
  name: "Question",
  data() {
    return {
      // 遮罩层
      loading: true,
      // // 选中数组
      // ids: [],
      // // 非单个禁用
      // single: true,
      // // 非多个禁用
      // multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 隐患问题清单表格数据
      questionList: [],
      selectedOrgName: null,
      // 查询参数
      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 },
      ],
    };
  },
  dicts: ["question_confirm_status"],
  components: { OrgTree, Dialog, DataRangePicker },
  computed: {
    ...mapGetters(["orgId", "userId"]),
  },
  created() {},
  methods: {
    dayjs,
    getLabel,
    /** 查询隐患问题清单列表 */
    getList() {
      this.loading = true;
      this.questionList=[];
      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.queryParams.submitRange = null;
      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(
        "core/question/export",
        {
          ...this.queryParams,
        },
        `${
          this.selectedOrgName
        }_${this.$tab.getCurrentTabName()}_${dayjs().format("YYYYMMDD")}.xlsx`
      );
    },
    //单选框状态改变
    checkChange(state) {
      this.queryParams.checkSub = state;
      this.getList();
    },
    getDefaultOrg(org) {
      this.queryParams.orgId = org.id;
      this.selectedOrgName = org.shortName;
      this.getList();
    },
    // 节点单击事件
    clickTreeNode(data) {
      this.queryParams.orgId = data.id;
      this.selectedOrgName = data.shortName;
      this.getList();
    },
  },
};
</script>
