<template>
  <div>
    <MOSTY.PageTree :pageTitle="'适用法律法规清单'" :searchType="'03'" @getDeptId="getdeptId">
      <template #serach>
        <el-divider />
        <div class="btnBox">
          <el-button type="primary" @click="onloadExcel" v-loading="exportLoading">
            <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 #lawType="{ row }">
              <dict-tag :options="D_TB_FLLB" :value="row.lawType" :tag="false" :isTree="true" />
            </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">
      <lawStoreinfo @close="close" :orgData="orgData" :saveBtnShow="saveBtnShow" :zdlist='{ D_BZ_FLZYLY }'
        :title="title" :editObj="editObj.editObj" />
    </div>
  </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, ref, getCurrentInstance } from "vue";
import * as MOSTY from "@/components/MyComponents/index";
import { getApi } from "@/api/tobAcco_api.js";
import lawStoreinfo from "./commponents/lawStoreinfo.vue";
import { exportXlsx } from "@/excel/Export2Excel.js";
const { proxy } = getCurrentInstance();
const { D_BZ_FLZYLY, D_TB_FLLB } = proxy.$dict("D_BZ_FLZYLY", "D_TB_FLLB");
// 数据
const tableloading = ref(false);
const saveBtnShow = ref(false);
const addplanShow = ref(false);
const title = ref("");
const tableData = ref([]);
const exportLoading = ref(false)
const tableColumn = ref([
  {
    title: "识别单位",
    prop: "orgname",
    sortable: true
  },
  {
    title: "法律法规名称",
    prop: "lawName",
    sortable: true
  },
  {
    title: "发布日期",
    prop: "promulgationdate",
    sortable: true
  },
  {
    title: "生效日期",
    prop: "implementationdate",
    sortable: true
  },
  {
    title: "发布单位",
    prop: "promulgationcompany",
    sortable: true
  },
  {
    title: "录入单位",
    prop: "orgname",
    sortable: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const orgData = ref({
  orgId: '',
  orgName: '',
})
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})// 分页
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20
});
let editObj = reactive({
  editObj: null
});

onMounted(() => {
});
//获取部门数据
const getdeptId = (val) => {
  listQuery.orgcode = val.id;
  listQuery.orgname = val.orgname;
  listQuery.pageCurrent = 1;
  pageConfiger.pageCurrent = 1;
  getDataList();
};
//获取法律识别清单
function getDataList() {
  tableloading.value = true;
  getApi(listQuery, "/mosty-jcgl/lawDistr/getYsbPage").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;
  });
}
//查看详情
const seeInfo = (row) => {
  let params = {
    id: row.lawId
  };
  getApi(params, `/mosty-jcgl/lawRegulations/getLawRegulaById`).then((res) => {
    editObj.editObj = res;
  });
  title.value = "法律法规详情";
  addplanShow.value = true;
  saveBtnShow.value = false;
};
//导出Excel
function onloadExcel() {
  exportLoading.value = true
  let title = {
    orgname: '识别单位',
    lawname: "法律法规名称",
    promulgationcompany: "发布单位",
    promulgationdate: "发布日期",
    implementationdate: "生效日期",
    documentNumber: "文号",
    lawLevel: "法律法规等级",
    lawType: "法律法规类型",
  };
  getApi(listQuery, "/mosty-jcgl/lawDistr/exportData").then(async (res) => {
    if (res) {
      let data = res;
      if (data) {
        for (let i = 0; i < data.length; i++) {
          if (data[i].lawType) {
            data[i].lawType = proxy.$getDictVal(data[i].lawType, LAW_TYPE);
          }
          if (data[i].lawLevel) {
            data[i].lawLevel = proxy.$getDictVal(data[i].lawLevel, LAW_LEVEL);
          }
        }
        let tablename = `${listQuery.orgname}适用法律法规清单.xlsx`;
        exportXlsx(title, data, `${listQuery.orgname}适用法律法规清单`, tablename);
        exportLoading.value = false
      }
      exportLoading.value = false
    }
  }).finally(() => {
    exportLoading.value = false
  });
}
const close = () => {
  addplanShow.value = false;
  getDataList();
};

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;

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




}
</style>