<template>
  <div>
    <layout-card>
      <el-row :gutter="12">
        <el-col :span="5">
          <layout-department-tree
            :department-id="DEPARTMENT_ID"
            @node-click="
              router.push({
                path: '/risk_statement/job_notification_card',
                query: {
                  DEPARTMENT_ID: $event.id,
                },
              })
            "
          />
        </el-col>
        <el-col :span="19">
          <layout-table
            v-model:pagination="pagination"
            :data="list"
            @get-data="fnGetDataTransfer"
          >
            <el-table-column label="序号" width="70">
              <template #default="{ $index }">
                {{ serialNumber(pagination, $index) }}
              </template>
            </el-table-column>
            <el-table-column post prop="DEPARTMENT_NAME" label="机构" />
            <el-table-column post prop="NAME" label="岗位" />
            <el-table-column label="状态" width="100">
              <template #default="{ row }">
                <span v-if="row.STATUS === '0'">启用</span>
                <span v-if="row.STATUS === '1'">禁用</span>
              </template>
            </el-table-column>
            <el-table-column label="照片">
              <template #default="{ row }">
                <layout-tooltip-img :imgs="row.imgs" />
              </template>
            </el-table-column>
          </layout-table>
        </el-col>
      </el-row>
    </layout-card>
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils.js";
import useListData from "@/assets/js/useListData.js";
import { getPostList } from "@/request/enterprise_management.js";
import { ref } from "vue";
import LayoutDepartmentTree from "@/components/department_tree/index.vue";
import { useUserStore } from "@/pinia/user.js";
import { onBeforeRouteUpdate, useRoute, useRouter } from "vue-router";
import LayoutTooltipImg from "@/components/tooltip_img/index.vue";

const userStore = useUserStore();
const router = useRouter();
const route = useRoute();
const departmentIdDefault = userStore.getUserInfo.DEPARTMENT_ID;
const DEPARTMENT_ID = ref(route.query.DEPARTMENT_ID || departmentIdDefault);
const { list, pagination, fnGetData, fnResetPagination } = useListData(
  getPostList,
  {
    otherParams: { DEPARTMENT_ID: DEPARTMENT_ID.value },
  }
);
const fnGetDataTransfer = () => {
  fnGetData({
    DEPARTMENT_ID: DEPARTMENT_ID.value,
  });
};
const fnResetPaginationTransfer = () => {
  fnResetPagination({
    DEPARTMENT_ID: DEPARTMENT_ID.value,
  });
};
onBeforeRouteUpdate((to) => {
  DEPARTMENT_ID.value = to.query.DEPARTMENT_ID || departmentIdDefault;
  fnResetPaginationTransfer();
});
</script>

<style scoped lang="scss"></style>
