<template>
  <div>
    <MOSTY.PageTree :pageTitle="'安全管理制度合法合规性评价'" :searchType="'03'" @getDeptId="getdeptId">
      <template #serach>
        <el-divider />
        <MOSTY.Search :searchArr="searchArr" @submit="onSearch" />
        <el-divider />
        <div class="btnBox">
          <el-button type="primary" @click="addglshow">
            <el-icon>
              <CirclePlus />
            </el-icon>
            <span>新增</span>
          </el-button>
        </div>
      </template>
      <template #table>
        <section class="eltab9">
          <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="operedit" @click="xglist(row)"><el-icon>
                  <EditPen />
                </el-icon>修改</span>
              <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon-color="red" title="确定要删除?"
                @confirm="dellist(row)">
                <template #reference>
                  <span span class="operdel" size="small">
                    <el-icon>
                      <Delete />
                    </el-icon>
                    删除</span>
                </template>
              </el-popconfirm>
              <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">
      <regularpjinfo @close="closefram" :saveBtnShow="saveBtnShow" :title="title" :id="rowId" />
    </div>
  </div>
</template>

<script setup>
import { reactive, onMounted, ref } from "vue";
import regularpjinfo from "./commponents/regularpjinfo.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { filterYear } from "@/utils/auth.js";
import { getApi, deleteApi } from "@/api/tobAcco_api.js";
import { ElMessage } from "element-plus";
const tableloading = ref(false)
const saveBtnShow = ref(false)
const title = ref('')
const rowId = ref(null)
const searchArr = reactive([
  {
    showType: "input",
    prop: "reportname",
    width: '250px',
    placeholder: '请输入报告名称'
  },
  {
    showType: "select",
    prop: "assessyear",
    width: '250px',
    options: filterYear(7),
  }

]);
const tableColumn = ref([
  {
    title: "报告名称",
    prop: "reportname",
    sortable: true
  },
  {
    title: "评价时间",
    prop: "assessyear",
    sortable: true
  },
  {
    title: "组织单位",
    prop: "initiateemp",
    sortable: true
  },
  {
    title: "组织部门",
    prop: "initiatedep",
    sortable: true
  },
  {
    title: "组织人",
    prop: "sponsor",
    sortable: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})
const addplanShow = ref(false);
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20,
})

// 表格数据
const tableData = ref([]);
onMounted(() => {
});
// 方法
const getdeptId = (val) => {
  listQuery.initiateempid = val.id;
  listQuery.pageCurrent = 1;
  getDataList();
};

function onSearch(obj) {
  listQuery.reportname = obj.reportname
  listQuery.assessyear = obj.assessyear
  listQuery.pageCurrent = 1
  pageConfiger.pageCurrent = 1
  getDataList()
}
//获取查询数据
function getDataList() {
  tableloading.value = true
  getApi(listQuery, '/mosty-jcgl/lawComprep/getLawCompList').then((res) => {
    if (res.records) {
      tableloading.value = false;
      tableData.value = res.records;
      pageConfiger.total = res.total;
    }
  }).catch((err) => {
    tableData.value = []
    tableloading.value = false;
  }).finally(() => {
    tableloading.value = false;
  })
}
//新增
const addglshow = () => {
  addplanShow.value = true;
  saveBtnShow.value = true
  title.value = '发起安全管理制度合法合规性评价'
};
//修改
const xglist = (row) => {
  addplanShow.value = true;
  saveBtnShow.value = true
  title.value = '修改安全管理制度合法合规性评价'
  rowId.value = row.id
}
//详情
function seeInfo(row) {
  addplanShow.value = true;
  saveBtnShow.value = false
  title.value = '查看安全管理制度合法合规性评价'
  rowId.value = row.id
}
//删除
function dellist(row) {
  deleteApi({}, `/mosty-jcgl/lawComprep/lawCompDel/${row.id}`).then((res) => {
    ElMessage.success("删除成功");
    listQuery.pageCurrent = 1
    getDataList()
  })
}
//关闭弹窗
function closefram() {
  addplanShow.value = false
  listQuery.pageCurrent = 1
  pageConfiger.pageCurrent = 1
  rowId.value = null
  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;
  }

  .right {
    padding: 0 10px;
    margin: 0px 14px;
    background: #fff;
  }
}
</style>