<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="100px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item
              label="职业危害告知书"
              prop="OCCUPATIONALNAME"
              label-width="120px"
            >
              <el-input v-model="searchForm.OCCUPATIONALNAME" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="完成状态" prop="COMPLETIONSTATUS">
              <el-select v-model="searchForm.COMPLETIONSTATUS" clearable>
                <el-option label="已上传" :value="1" />
                <el-option label="未上传" :value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="有效状态" prop="VALIDSTATUS">
              <el-select v-model="searchForm.VALIDSTATUS" clearable>
                <el-option label="有效" :value="1" />
                <el-option label="失效" :value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPagination">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        ref="tableRef"
        v-model:pagination="pagination"
        :data="list"
        row-key="LABORCONTRACT_ID"
        @get-data="fnGetData"
      >
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="NEWOCCUPATIONALNAME" label="用户名称" width="100"/>
        <el-table-column prop="OCCUPATIONALNAME" label="职业危害告知书" />
        <el-table-column prop="COMPLETIONSTATUS" label="完成状态" width="100">
          <template #default="{ row }">
            <el-tag v-if="row.COMPLETIONSTATUS === '1'">已上传</el-tag>
            <el-tag v-else>未上传</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="有效状态" prop="VALIDSTATUS" width="100">
          <template #default="{ row }">
            <el-tag v-if="row.VALIDSTATUS === '1'">有效</el-tag>
            <el-tag v-else>失效</el-tag>
          </template>
        </el-table-column>
        <!--        <el-table-column prop="CORP_NAME" label="经营企业" width="220" />
        <el-table-column prop="OPERATIONTYPE" label="经营类型" width="150" />-->
        <el-table-column prop="EXPIRYDATE" label="到期时间" width="180"/>
        <el-table-column prop="CREATETIME" label="创建时间" width="180"/>
        <el-table-column prop="OPERATTIME" label="修改时间" width="180"/>
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="fnView(row.OCCUPATIONALHAZARDS_ID)"
            >
              查看
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/occupational_hazards/details',
                  query: {
                    OCCUPATIONALHAZARDS_ID: row.OCCUPATIONALHAZARDS_ID,
                    USER_ID: row.USER_ID,
                  },
                })
              "
            >
              管理
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
    <add
      v-model:visible="data.addOrEditDialog.visible"
      v-model:form="data.addOrEditDialog.form"
      :type="data.addOrEditDialog.type"
      :options="[]"
      :loading="false"
      @get-data="fnResetPagination"
    />
    <view-info
      v-model:visible="data.viewDialog.visible"
      :info="data.viewDialog.info"
      label-name="详情"
    />
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils";
import useListData from "@/assets/js/useListData.js";
import Add from "./components/add.vue";
import { reactive, watchEffect } from "vue";
import {
  getSafetyOccupationalHazardsList,
  infoOccupationalHazardsView,
} from "@/request/traffic_occupational_hazards.js";
import ViewInfo from "./components/view.vue";
import { useRouter } from "vue-router";

const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getSafetyOccupationalHazardsList);
const data = reactive({
  addOrEditDialog: {
    visible: false,
    type: "",
    form: {},
  },
  viewDialog: {
    visible: false,
    info: {},
  },
});

watchEffect(() => {
  if (list.value.length > 0) {
    list.value.forEach((item) => {
      item.NEWOCCUPATIONALNAME = `${item.NAME}`;
    });
  }
});
const fnView = async (OCCUPATIONALHAZARDS_ID) => {
  const resData = await infoOccupationalHazardsView({
    OCCUPATIONALHAZARDS_ID,
  });
  if (resData && resData.pd) {
    data.viewDialog.info = resData.pd;
    data.viewDialog.visible = true;
  }
};
</script>

<style scoped></style>
