<template>
  <el-drawer v-model="visible" title="电子围栏台账" direction="rtl" size="50%">
    <el-card>
      <el-form
        :model="searchForm"
        label-width="20px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="关键字" prop="KEYWORDS" label-width="60px">
              <el-input
                v-model="searchForm.KEYWORDS"
                placeholder="请输入关键字"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="30px">
              <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"
        @get-data="fnGetData"
      >
        <el-table-column reserve-selection type="selection" width="55" />
        <el-table-column label="序号" width="70">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column property="layName" label="所属图层" width="150" />
        <el-table-column property="regName" label="名称" />
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button type="primary" text link @click="handleJoin(row)"
              >绑定</el-button
            >
          </template>
        </el-table-column>
      </layout-table>
    </layout-card>
  </el-drawer>
</template>
<script setup>
import { serialNumber } from "@/assets/js/utils.js";
import useListData from "@/assets/js/useListData.js";
import { getRyRegionList } from "@/request/risk_control.js";
import { useVModels } from "@vueuse/core";
const { list, pagination, searchForm, fnGetData, fnResetPagination, tableRef } =
  useListData(getRyRegionList);
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
    default: false,
  },
  form: {
    type: Object,
    required: true,
    default: () => {},
  },
});
const emits = defineEmits(["update:visible", "update:form"]);
const { visible, form } = useVModels(props, emits);
const handleJoin = (row) => {
  form.value.ELECTRONIC_FENCE_NAME = row.regName;
  form.value.ELECTRONIC_FENCE_ID = row.id;
  visible.value = false;
};
</script>
