<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="24" :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="机构名称">
                <org-tree
                  v-model="queryParams.orgId"
                  @defaultOrg="getDefaultOrg"
                  @checkChange="checkChange"
                  @click="clickTreeNode"
                  ref="orgTree"
                ></org-tree>
              </el-form-item>
              <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">
              <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"
              ></right-toolbar>
            </el-row>
          </div>

          <el-table
            v-loading="loading"
            :data="questionList"
            height="646"
            size="small"
            border
          >
            <el-table-column
              align="center"
              type="index"
              label="序号"
              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
              align="center"
              label="地区"
              prop="affiliatedArea"
              show-overflow-tooltip
              min-width="60"
              v-if="columns[6].visible"
            />
            <el-table-column
              align="center"
              label="行社名称"
              prop="affiliatedBank"
              show-overflow-tooltip
              min-width="80"
              v-if="columns[7].visible"
            />
            <el-table-column
              align="center"
              label="机构名称"
              prop="orgName"
              show-overflow-tooltip
              v-if="columns[1].visible"
            />
            <el-table-column
              align="center"
              label="标准依据"
              prop="checkContent"
              min-width="150"
              v-if="columns[2].visible"
            >
              <template slot-scope="scope">
                <pre>{{ scope.row.checkContent }}</pre>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="隐患描述"
              prop="questionDesc"
              show-overflow-tooltip
              v-if="columns[3].visible"
            />
            <el-table-column
              align="center"
              label="发现时间"
              prop="submitTime"
              width="170px"
              v-if="columns[8].visible"
            >
              <template slot-scope="scope">
                <span>{{
                  dayjs(scope.row.submitTime).format("YYYY年MM月DD日")
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="整改期限"
              prop="submitTime"
              width="150"
              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
              align="center"
              label="整改状态"
              prop="reformStatus"
              width="120px"
              v-if="columns[5].visible"
            >
              <template slot-scope="scope">
                <span>{{
                  getLabel(
                    dict.type.question_reform_status,
                    scope.row.overdueStatus && scope.row.reformStatus==10
                      ? scope.row.overdueStatus
                      : scope.row.reformStatus
                  )
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              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 OrgTree from "@/components/orgTree/orgQuerySelector.vue";
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 },
        { key: 6, label: `地区`, visible: true },
        { key: 7, label: `行社名称`, visible: true },
        { key: 8, label: `发现时间`, visible: true },
      ],
    };
  },
  dicts: ["question_reform_status"],
  components: { OrgTree, Dialog, DataRangePicker },
  computed: {
    ...mapGetters(["orgId", "userId","orgName"]),
  },
  beforeRouteEnter(to,from,next){
    console.log(from,'to')
    if(from.path === '/home'){
      next(vm=>{
        vm.queryParams.reformStatus = to.query.reformStatus;
      })
    }else {
      next()
    }
  },
  methods: {
    dayjs,
    getLabel,
    /** 查询隐患问题清单列表 */
    getList() {
      this.loading = true;
      this.questionList = [];
      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.orgId = this.orgId;
      this.selectedOrgName = this.orgName;
      this.queryParams.checkSub = true;
      this.$refs["orgTree"].setCheckSub(this.queryParams.checkSub)
      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>
