<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="100px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="4">
            <el-form-item label="关键字搜索" prop="KEYWORDS">
              <el-input v-model="searchForm.KEYWORDS" />
            </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="fnResetPaginationTransfer">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        ref="tableRef"
        :data="list"
        @get-data="fnGetData"
        v-model:pagination="pagination"
        row-key="UNITS_ID"
      >
        <el-table-column reserve-selection type="selection" width="55" />
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="OUTSOURCED_NAME" label="重点工程名称" />
        <el-table-column prop="DEPARTMENT_NAME" label="监管部门">
          <template v-slot="{ row }">
            <span v-if="row.Q_DEPARTMENT_NAME">
              {{ row.Q_DEPARTMENT_NAME }}
            </span>
            <span v-else>{{ row.DEPARTMENT_NAME }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="MANAGE_CORPS_NAME"
          label="监理单位"
          width="200"
        />
        <el-table-column
          prop="UNITS_PIC_NAME"
          label="相关方单位负责人"
          width="200"
        />
        <el-table-column prop="UNITS_PHONE" label="电话" />
        <el-table-column prop="CHECK_COUNT" label="安全环保检查次数" />
        <el-table-column label="操作" align="center" width="120">
          <template v-slot="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/keyprojects/inspection/record_list',
                  query: {
                    OUTSOURCED_ID: row.OUTSOURCED_ID,
                  },
                })
              "
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import useListData from "@/assets/js/useListData";
import { serialNumber } from "@/assets/js/utils";
import { getOutsourcedList } from "@/request/keyprojects.js";
import router from "@/router";

const { list, pagination, searchForm, fnGetData, fnResetPagination, tableRef } =
  useListData(getOutsourcedList);

const fnResetPaginationTransfer = () => {
  fnGetData(searchForm);
};
</script>

<style scoped></style>
