<template>


  <div class="L-main" id="L-size-main">
    <div class="content-search" id="L-header">
      <div class="search-title">查询条件</div>
      <el-form :inline="true" :model="queryParams" ref="queryForm" size="small" class="demo-form-inline">
        <el-row>
          <el-col :span="6">
            <el-form-item label="单位名称：" prop="nickName">
              <el-input v-model="queryParams.nickName" placeholder="请输入单位名称" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="单位类型：" prop="dwlx">
              <el-select v-model="queryParams.dwlx" placeholder="用户状态" clearable>
                <el-option v-for="dict in dict.type.dwlx" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="统一社会信用代码：" class="tyshxydm-class" prop="userName">
              <el-input v-model="queryParams.userName" placeholder="请输入统一社会信用代码" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :span="3" style="text-align: right;padding-right: 20px;">
            <el-form-item class="unit-form">
              <el-button size="mini" @click="resetQuery">重置</el-button>
              <el-button size="mini" type="primary" @click="handleQuery">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <main>
      <div class="search-title">
        <span class="search-title-span">单位列表</span>

      </div>
      <section>
        <el-table ref="multipleTable" v-loading="loading" :data="userList" :height="tabHeader" :max-height="tabHeader"
          :row-class-name="tableRowClassName" @selection-change="handleSelectionChange" row-key="userName">
          <el-table-column type="selection" width="55" :reserve-selection="true">
          </el-table-column>
          <el-table-column type="index" label="序号" width="50" align="center" />
          <el-table-column label="单位名称" align="center" key="nickName" prop="nickName">
            <template slot-scope="scope">{{ scope.row.nickName }}</template>
          </el-table-column>
          <el-table-column label="单位类型" align="center" key="dwlx" prop="dwlx">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.dwlx" :value="scope.row.dwlx" />
            </template>
          </el-table-column>
          <el-table-column label="统一社会信用代码" align="center" key="userName" prop="userName">
            <template slot-scope="scope">{{ scope.row.userName }}</template>
          </el-table-column>
          <el-table-column label="所属区域" align="center" key="ssqycounty" prop="ssqycounty">
            <template slot-scope="scope">{{ scope.row.ssqycity }}</template>
          </el-table-column>
          <el-table-column label="所属行业" align="center" key="sshy" prop="sshy">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sshy" :value="scope.row.sshy" />
              <!-- {{ scope.row.sshy }} -->
            </template>
          </el-table-column>
          <el-table-column label="单位地址" align="center" key="dwxxdz" prop="dwxxdz">
            <template slot-scope="scope">{{ scope.row.dwxxdz }}</template>
          </el-table-column>

        </el-table>
      </section>
      <my-pagination id="L-pagination" :total="total" :page="queryParams.current" :limit="queryParams.size"
        @pagination="getPagination" :current-page.sync="queryParams.current"></my-pagination>
    </main>
    <div class="bottomclass">
      <el-button size="mini" @click="resetCancel">取消</el-button>
      <el-button type="primary" size="mini" @click="resetConfirm">确定</el-button>
    </div>


  </div>
</template>

<script>
// import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from "@/api/system/user";
import { listUnit, delUnit } from "@/api/auditPagesApi/index";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import myPagination from "@/views/components/Pagination/index.vue"

export default {
  name: "User",
  dicts: ['dwlx', 'sshy'],
  components: { Treeselect, myPagination },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 部门名称
      deptName: undefined,
      // 默认密码
      initPassword: undefined,
      // 岗位选项
      postOptions: [],
      // 角色选项
      roleOptions: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/tc/unit/importData"
      },
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        userName: undefined,
        nickName: undefined,
        dwlx: undefined,
      },
      // 表单校验

      tabHeader: undefined,
      tabclicklist: []
    };
  },
  watch: {

    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);

    }
  },
  created() {
    this.getList();
    // this.getConfigKey("sys.user.initPassword").then(response => {
    //   this.initPassword = response.msg;
    // });
  },
  mounted() {
    this.cancalDebounce();
    window.addEventListener('resize', this.cancalDebounce);
  },
  destroyed() {
    window.removeEventListener('resize', this.cancalDebounce);
  },
  methods: {
    dakai(val) {
      console.log(val);

      this.toggleSelection(val)
    },
    resetCancel() {
      this.$emit('liebiaoClose')
      this.toggleSelection()
      this.$emit('adddanweilist', [])

    },
    resetConfirm() {
      this.$emit('adddanweilist', this.tabclicklist)
      this.$emit('liebiaoClose')
      this.toggleSelection()

    },
    // 清空/回显table多选
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      if (val) {
        this.tabclicklist = val
      }


    },

    // 修改table背景色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 !== 0) {
        return 'evenNumber-row';
      }
      return '';
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUnit(this.queryParams).then(response => {
        this.userList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      }
      );
    },
    // 页码获取
    getPagination(pages) {
      this.queryParams.current = pages.page;
      this.queryParams.size = pages.limit;
      this.getList();
    },
    // 节点单击事件

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.toggleSelection()
      this.handleQuery();
    },


    // 屏幕尺寸变化
    cancalDebounce() {
      const element = document.getElementById('L-size-main'); // 通过元素的 ID 获取元素
      const header = document.getElementById('L-header'); // 通过元素的 ID 获取元素
      const pagination = document.getElementById('L-pagination'); // 通过元素的 ID 获取元素
      const elementHeight = element.offsetHeight;
      const headerHeight = header.offsetHeight;
      const paginationtHeight = pagination.offsetHeight;
      this.tabHeader = elementHeight - headerHeight - paginationtHeight - 120;
    }
  }
};
</script>