<template>
  <div>
    <MOSTY.PageTree :pageTitle="'有效规章制度清单'" :searchType="'01'" @getDeptId="getdeptId">
      <template #serach>
        <el-divider />
        <div class="btnBox">
          <el-button type="primary" @click="onloadExcel" v-loading="excelLoading">
            <el-icon>
              <Download />
            </el-icon>
            <span>导出</span>
          </el-button>
        </div>
      </template>
      <template #table>
        <section class="eltab8">
          <MOSTY.Table :table-columns="tableColumn" :tableData="tableData" :tableloading="tableloading"
            :isSelect="false" :isSort="true" @SortChange="SortChange" style="width: 100%;">
            <template #level="{ row }">
              <dict-tag :options="D_BZ_LWJB" :value="row.level" :tag="false" />
            </template>
            <template #actions="{ row }">
              <span class="operesee" @click="seeInfo(row)"><el-icon>
                  <View />
                </el-icon>查看</span>
            </template>
          </MOSTY.Table>
        </section>
        <div class="fenye">
          <MOSTY.Pages :pageConfiger="pageConfiger" @changeSize="handleSizeChange" @changeNo="handleCurrentChange" />

        </div>
      </template>
    </MOSTY.PageTree>
    <!-- 新增信息列表 -->
    <div v-if="addplanShow" class="dialog-box">
      <regulStoreinfo @close="closefram" :saveBtnShow="saveBtnShow" :title="title" :id="rowId" />
    </div>
  </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, ref } from "vue";
import regulStoreinfo from "./commponents/regulStoreinfo.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { getApi } from "@/api/tobAcco_api.js";
import { exportXlsx } from "@/excel/Export2Excel.js";
const excelLoading = ref(false)
const addplanShow = ref(false);
const tableloading = ref(false);
const saveBtnShow = ref(true);
const rowId = ref(null);
const title = ref(null);
const tableData = ref([]);
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20,
  type: '1',//规章制度
});
const tableColumn = ref([
  {
    title: "识别单位",
    prop: "orgname",
    sortable: true
  },
  {
    title: "识别部门",
    prop: "departname",
    sortable: true
  },
  {
    title: "文件编号",
    prop: "shortid",
    sortable: true
  },
  {
    title: "文件名称",
    prop: "filename",
    sortable: true
  },
  {
    title: "文件描述",
    prop: "filedescribe",
    sortable: true
  },
  {
    title: "制定修订情况",
    prop: "revise",
    sortable: true
  },
  {
    title: "识别人",
    prop: "username",
    sortable: true,

  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})

// 方法
const getdeptId = (val) => {
  listQuery.depart = val.id;
  listQuery.orgname = val.orgname;
  listQuery.pageCurrent = 1
  pageConfiger.pageCurrent = 1
  getDataList();
}
function getDataList() {
  tableloading.value = true
  getApi(listQuery, '/mosty-jcgl/regulationsrules/getPageList').then((res) => {
    if (res.records) {
      tableloading.value = false;
      tableData.value = res.records;
      pageConfiger.total = res.total;
    }
  }).catch(() => {
    tableData.value = []
    tableloading.value = false;
  }).finally(() => {
    tableloading.value = false;
  })
}
//详情
function seeInfo(row) {
  addplanShow.value = true;
  saveBtnShow.value = false
  title.value = '规章制度与规程查看'
  rowId.value = row.libraryid
}

//关闭弹窗
function closefram() {
  rowId.value = null
  addplanShow.value = false
  listQuery.pageCurrent = 1
  pageConfiger.pageCurrent = 1
  getDataList()
}

function onloadExcel() {
  excelLoading.value = true;
  let title = {
    orgname: "识别单位",
    departname: "识别部门",
    shortid: "文件编号",
    filename: "文件名称",
    filedescribe: "文件描述",
    revise: "制定修订情况",
    username: "识别人"
  };
  getApi(listQuery, '/mosty-jcgl/regulationsrules/exportData').then((res) => {
    if (res) {
      let data = res
      if (data) {
        let tablename = `${listQuery.orgname}有效规章制度清单.xlsx`
        exportXlsx(title, data, `${listQuery.orgname}有效规章制度清单`, tablename);
        excelLoading.value = false;
      }
    }
    excelLoading.value = false;
  }).finally(() => {
    excelLoading.value = false;
  })
}

//分页
const handleSizeChange = (currentSize) => {
  listQuery.pageSize = currentSize;
  pageConfiger.pageSize = currentSize;
  getDataList();
};
const handleCurrentChange = (currentPage) => {
  listQuery.pageCurrent = currentPage;
  pageConfiger.pageCurrent = currentPage;
  getDataList();
};
</script>

<style lang="scss" scoped>
.bigBox {
  display: flex;

  .right {
    padding: 0 10px;
    margin: 0px 14px;
    background: #fff;

  }
}

.btnBox {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 12px;
}
</style>