<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="addUserHander">
            <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="editClick(row)"><el-icon>
                  <EditPen />
                </el-icon>修改</span>
              <span class="operesee" @click="seeClick(row)"><el-icon>
                  <Compass />
                </el-icon>查看</span>
              <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon-color="red" title="确定要删除?"
                @confirm="handledelete(row)">
                <template #reference>
                  <span class="operdel" size="small">
                    <el-icon>
                      <Delete />
                    </el-icon>删除</span>
                </template>
              </el-popconfirm>
            </template>
          </MOSTY.Table>
        </section>
        <div class="fenye">
          <MOSTY.Pages :pageConfiger="pageConfiger" @changeSize="handleSizeChange" @changeNo="handleCurrentChange" />

        </div>

      </template>
    </MOSTY.PageTree>

    <!-- 修改 -->
    <div v-if="comprehensiveShow" class="dialog-box">
      <EditAqkt @close="close" :title="title" :orgcode="orgcode" :rowId="rowId" :saveBtnShow="saveBtnShow" />
    </div>
  </div>
</template>

<script setup>
// 引入
import { onMounted, reactive, ref, getCurrentInstance } from "vue";
import { filterYear } from "@/utils/auth.js";
import { ElMessage } from "element-plus";
import EditAqkt from "./commponents/EditAqkt.vue";
import * as MOSTY from "@/components/MyComponents/index";
import { postApi } from "@/api/tobAcco_api.js";
import { dateFormat } from "@/utils/tools";
const { proxy } = getCurrentInstance();
const { D_BZ_LWJB } = proxy.$dict("D_BZ_LWJB");
// 数据
const searchArr = reactive([
  {
    showType: "input",
    prop: "username",
    width: '250px',
    placeholder: '请输入人员姓名查询'
  },
  {
    showType: "year",
    prop: "year",
    width: '250px',
    defaultVal: String(dateFormat({ type: "year", time: new Date() }))
  }

]);
const comprehensiveShow = ref(false);
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20,
  type: '3',
  year: String(dateFormat({ type: "year", time: new Date() }))
});
const rowId = ref(null);
const saveBtnShow = ref(true);
const title = ref("新增");

const tableData = ref([
]);
const tableColumn = ref([
  {
    title: "课题名称",
    prop: "titlename",
    sortable: true
  },
  {
    title: "级别",
    prop: "level",
    sortable: true,
    slot: true
  },
  {
    title: "小组成员",
    prop: "username",
    sortable: true
  },
  {
    title: "完成时间",
    prop: "time",
    sortable: true
  },
  {
    title: "年度",
    prop: "year",
    sortable: true
  },
  {
    title: "主要内容",
    prop: "content",
    sortable: true
  },
  {
    title: "级别",
    prop: "level",
    slot: true,
    sortable: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})
onMounted(() => {

});
function onSearch(obj) {
  listQuery.pageCurrent = 1
  pageConfiger.pageCurrent = 1;
  listQuery.username = obj.username
  listQuery.year = obj.year
  getListData();
}
function close() {
  rowId.value = null
  comprehensiveShow.value = false
  getListData()
}
//获取列表数据
const tableloading = ref(false);
function getListData() {
  tableloading.value = true;
  postApi(listQuery, "/mosty-jcgl/safetypaperCommend/getPageList").then((res) => {
    if (res.records) {
      tableloading.value = false;
      tableData.value = res.records;
      pageConfiger.total = res.total;
    } else {
      tableData.value = [];
      tableloading.value = false;
    }
  }).finally(() => {
    tableloading.value = false;
  });
}
//分页
const handleSizeChange = (currentSize) => {
  listQuery.pageSize = currentSize;
  pageConfiger.pageSize = currentSize;
  getListData();
};
const handleCurrentChange = (currentPage) => {
  listQuery.pageCurrent = currentPage;
  pageConfiger.pageCurrent = currentPage;
  getListData();
};
//选择右侧部门
const getdeptId = (val) => {
  listQuery.orgcode = val.id;
  listQuery.pageCurrent = 1;
  pageConfiger.pageCurrent = 1;
  getListData();
};
// 方法

//新增
const addUserHander = () => {
  title.value = "安全课题新增";
  orgcode.value = listQuery.orgcode
  comprehensiveShow.value = true;
  rowId.value = null;
  saveBtnShow.value = true;
};

// 编辑
const orgcode = ref("")
const editClick = (row) => {
  title.value = "安全课题修改";
  orgcode.value = listQuery.orgcode
  comprehensiveShow.value = true;
  saveBtnShow.value = true;
  rowId.value = row.id
};
// 查看
const seeClick = (row) => {
  title.value = "安全课题详情";
  comprehensiveShow.value = true;
  rowId.value = row.id
  saveBtnShow.value = false;
};
//删除
const handledelete = (row) => {
  postApi({}, `/mosty-jcgl/safetypaperCommend/del/${row.id}`).then(
    (res) => {
      ElMessage.success("删除成功");
      getListData();
    }
  );
};



</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>