<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="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="reformRange">
                <DataRangePicker
                  clearable
                  v-model="queryParams.reformRange"
                  key="daterange"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </DataRangePicker>
              </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"
              align="center"
              type="index"
              label="序号"
              width="60px"
              v-if="columns[0].visible"
            ></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="checkContent"
              v-if="columns[2].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[3].visible"
            />

            <el-table-column
              header-align="center"
              align="center"
              label="整改期限"
              prop="submitTime"
              width="120"
              v-if="columns[4].visible"
            >
              <template slot-scope="scope">
                <span>{{
                  dayjs(scope.row.reformDeadline).format("YYYY-MM-DD")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              align="center"
              label="整改状态"
              prop="reformStatus"
              width="100px"
              v-if="columns[5].visible"
            >
              <template slot-scope="scope">
                <span>{{
                  getLabel(
                    dict.type.question_reform_status,
                    scope.row.reformStatus
                  )
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              label="操作"
              width="150"
              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:reform:query']"
                  >详情</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-s-unfold"
                  @click="handleReform(scope.row)"
                  v-hasPermi="['question:reform: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"
          />
        </div>
      </el-col>
    </el-row>
    <Dialog ref="dialog" @success="getList()"></Dialog>
  </div>
</template>

<script>
import { page } from "@/api/question/reform.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: "QuestionReform",
  data() {
    return {
      // 遮罩层
      loading: true,
      // // 选中数组
      // ids: [],
      // // 非单个停用
      // single: true,
      // // 非多个停用
      // multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 隐患问题清单表格数据
      questionList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgId: this.orgId,
        reformRange: 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 },
      ],
    };
  },
  dicts: ["question_reform_status"],
  components: { OrgTree, Dialog, DataRangePicker },
  computed: {
    ...mapGetters(["orgId", "userId"]),
  },
  created() {},
  methods: {
    dayjs,
    getLabel,
    /** 查询隐患问题清单列表 */
    getList() {
      this.loading = true;
      page(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.reformRange = 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/questionreform/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>
