<template>
  <div class="modalSty" ref="refModel">
    <a-modal
      v-model:visible="visible"
      title="新增预警类型"
      @ok="handleOk"
      :bodyStyle="{ padding: '20px' }"
      :getContainer="() => $refs.refModel"
      centered
    >
      <a-form
        :model="formState"
        name="basic"
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 16 }"
        autocomplete="off"
        @finish="onFinish"
        @finishFailed="onFinishFailed"
      >
        <a-form-item
          label="所属领域"
          name="name"
          :rules="[{ required: true, message: 'Please input your username!' }]"
        >
          <a-select
            v-model:value="formState.username"
            show-search
            placeholder="Select a person"
            :options="options"
          />
        </a-form-item>
        <a-form-item
          label="所属行业"
          name="username"
          :rules="[{ required: true, message: 'Please input your username!' }]"
        >
          <a-select
            v-model:value="formState.username"
            show-search
            placeholder="Select a person"
            :options="options2"
          />
        </a-form-item>
        <a-form-item
          label="预警类型"
          name="username"
          :rules="[{ required: true, message: '请输入预警类型名称' }]"
        >
          <a-input v-model:value="formState.username" />
        </a-form-item>
        <a-form-item label="备注">
          <a-textarea v-model:value="formState.username" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>
<script setup lang="ts">
  import { SelectTypes } from 'ant-design-vue/lib/select';
  import { ref, reactive } from 'vue';

  const options = ref<SelectTypes['options']>([
    { value: '0', label: '城市生命线安全' },
    { value: '1', label: '生产安全' },
    { value: '2', label: '自然灾害' },
  ]);
  const options2 = ref<SelectTypes['options']>([
    { value: '0', label: '供水' },
    { value: '1', label: '排气' },
    { value: '2', label: '燃气' },
    { value: '3', label: '电梯' },
  ]);

  const visible = ref(false);
  const handleOk = (e) => {
    console.log(e);
    visible.value = false;
  };
  //
  const formState = reactive({
    username: '',
    password: '',
    remember: true,
  });
  const onFinish = (values) => {
    console.log('Success:', values);
  };
  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };
  //
  function show() {
    visible.value = true;
  }
  //   编译器宏,暴露出方法
  defineExpose({
    show,
  });
</script>
<style lang="less" scoped>
  :deep(.ant-modal-header) {
    background-color: #2d74e7;
  }

  :deep(.ant-modal-title) {
    color: white;
  }
</style>
