<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="MEETING_TITLE">
              <el-input v-model="searchForm.MEETING_TITLE" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会议类型" prop="MEETING_TYPE">
              <el-select v-model="searchForm.MEETING_TYPE">
                <el-option
                  v-for="item in MEETINGTYPEMENU"
                  :key="item.id"
                  :label="item.id"
                  :value="item.name"
                />
              </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
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetData"
      >
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="MEETING_TITLE" label="会议标题" width="250" />
        <el-table-column prop="MEETING_TYPE" label="会议类型" width="250">
          <template #default="{ row }">
            <div v-if="row.MEETING_TYPE === '1'">安全生产例会</div>
            <div v-else-if="row.MEETING_TYPE === '2'">安全生产委员会会议</div>
          </template>
        </el-table-column>
        <el-table-column label="会议状态" prop="SIGNEDDATE">
          <template #default="{ row }">
            <el-tag v-if="row.MEETING_STATUS === 1">{{ "进行中" }}</el-tag>
            <el-tag v-else>未开始</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="MEETING_DATE" label="会议时间" />
        <el-table-column label="参会人数" width="100">
          <template #default="{ row }">
            {{ row.MEETING_PERSONS + "/" + row.TOTALPERSONNUM }}人
          </template>
        </el-table-column>
        <el-table-column prop="HOST_PERSON" label="主持人" />
        <el-table-column prop="MEETING_ADDRESS" label="会议地点" />
        <el-table-column prop="CORP_NAME" label="运输企业" />
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/safety_production_related/safety_meeting/meeting_info',
                  query: {
                    SAFETY_MEETING_ID: row.SAFETY_MEETING_ID,
                  },
                })
              "
            >
              查看
            </el-button>
            <el-button
              type="danger"
              text
              link
              @click="deleteItem(row.SAFETY_MEETING_ID)"
            >
              删除
            </el-button>
            <!-- 阅读详情按钮 -->
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/safety_production_related/safety_meeting/details',
                  query: {
                    SAFETY_MEETING_ID: row.SAFETY_MEETING_ID,
                  },
                })
              "
            >
              参会人员
            </el-button>
          </template>
        </el-table-column>
        <template #button>
          <el-button
            type="primary"
            @click="
              router.push({
                path: '/safety_production_related/safety_meeting/add',
              })
            "
          >
            添加
          </el-button>
        </template>
      </layout-table>
    </layout-card>
    <edit
      v-model:visible="data.analysisDialog.visible"
      :info="data.analysisDialog.info"
      @get-data="fnResetPagination"
    />
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils";
import useListData from "@/assets/js/useListData.js";
import { MEETINGTYPEMENU } from "@/assets/js/constant.js";
import { reactive } from "vue";
import {
  getSafetyMeetingList,
  setSafetyMeetingDelete,
} from "@/request/traffic_safety_meeting.js";
import router from "@/router/index.js";
import { ElMessage, ElMessageBox } from "element-plus";

const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getSafetyMeetingList);
const data = reactive({
  analysisDialog: {
    visible: false,
    info: {},
  },
});
// 删除事件
const deleteItem = async (value) => {
  await ElMessageBox.confirm(`确定要删除吗？`, {
    type: "warning",
  });
  await setSafetyMeetingDelete({ SAFETY_MEETING_ID: value });
  ElMessage.success("删除成功");
  fnGetData();
};
</script>

<style scoped></style>
