<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="SYSTEMNAME">
              <el-input v-model="searchForm.SYSTEMNAME" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="完成状态" prop="COMPLETIONSTATUS">
              <el-select v-model="searchForm.COMPLETIONSTATUS">
                <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">
                <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="STAFFING_ID"
        @get-data="fnGetData"
      >
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="SYSTEMNAME" label="制度名称" width="250" />
        <el-table-column prop="COMPLETIONSTATUS" label="完成状态" width="250">
          <template #default="{ row }">
            <el-tag v-if="row.COMPLETIONSTATUS === '1'">已上传</el-tag>
            <el-tag v-else-if="row.COMPLETIONSTATUS === '0'">未上传</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="有效状态" prop="VALIDSTATUS">
          <template #default="{ row }">
            <el-tag v-if="row.VALIDSTATUS === '1'">正常</el-tag>
            <el-tag v-else-if="row.VALIDSTATUS === '0'">未生效</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="CORP_NAME" label="经营企业" width="150" />
        <el-table-column prop="OPERATIONTYPE" label="经营类型" width="150" />
        <el-table-column prop="EXPIRYDATE" label="到期时间" width="150" />
        <el-table-column prop="CREATETIME" label="创建时间" width="150" />
        <el-table-column prop="OPERATTIME" label="修改时间" width="150" />
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="fnView(row.STAFFING_ID)"
            >
              查看
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="fnAddOrEdit(row.STAFFING_ID, 'edit')"
            >
              编辑
            </el-button>
          </template>
        </el-table-column>
        <template #button>
          <el-button type="primary" @click="fnAddOrEdit('', 'add')">
            新增
          </el-button>
        </template>
      </layout-table>
    </layout-card>
    <add
      v-model:visible="data.addOrEditDialog.visible"
      v-model:form="data.addOrEditDialog.form"
      :type="data.addOrEditDialog.type"
      @get-data="fnResetPagination"
    />
    <view-info
      v-model:visible="data.viewDialog.visible"
      :info="data.viewDialog.info"
      :label-name="labelName"
    />
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils";
import useListData from "@/assets/js/useListData.js";
import Add from "./components/add.vue";
import { nextTick, reactive } from "vue";
import {
  getSafetyStaffingList,
  infoStaffingView,
} from "@/request/traffic_safety_staffing.js";
import ViewInfo from "./components/view.vue";

const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getSafetyStaffingList);
const data = reactive({
  addOrEditDialog: {
    visible: false,
    type: "",
    form: {},
  },
  viewDialog: {
    visible: false,
    info: {},
  },
});
const fnAddOrEdit = async (STAFFING_ID = "", type = "add") => {
  data.addOrEditDialog.visible = true;
  data.addOrEditDialog.type = type;
  if (type === "edit" && STAFFING_ID) {
    data.addOrEditDialog.form.STAFFING_ID = STAFFING_ID;
  } else {
    data.addOrEditDialog.form = {};
  }

  await nextTick();
};

const fnView = async (STAFFING_ID) => {
  const resData = await infoStaffingView({
    STAFFING_ID,
  });
  data.viewDialog.info = resData.pd;
  data.viewDialog.visible = true;
};
</script>

<style scoped></style>
