<template>
  <el-dialog v-model.trim="addShow" :title="title" width="30%" draggable :close-on-click-modal="false">
    <el-form :model="form" ref="ruleFormRef" label-width="102px" :rules="formRules" style="padding: 0 80px 0px 0;">
      <el-form-item label="地址名称：" prop="v_addressName">
        <el-input v-model.trim="form.v_addressName" placeholder="请输入企业类型" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="经度：" prop="v_lon">
        <el-input v-model.trim="form.v_lon" placeholder="请输入企业类型" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="维度：" prop="v_lat">
        <el-input v-model.trim="form.v_lat" placeholder="请输入企业类型" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="装备类型：" prop="deviceType">
        <el-select placeholder="请选择装备类型" clearable v-model.trim="form.deviceType" @change="changeType">
          <el-option v-for="item in deviceTypeInfo.list" :key="item.id" :label="item.name" :value="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="装备型号：" prop="equipType">
        <el-input v-model.trim="form.equipType" placeholder="请输入企业类型" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="设备状态：" prop="deviceStatus">
        <el-input v-model.trim="form.deviceStatus" placeholder="请输入企业类型" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="GPS编号：" prop="GPScode">
        <el-radio-group v-model.trim="GPScode">
          <el-radio :label="3">Option A</el-radio>
          <el-radio :label="6">Option B</el-radio>
          <el-radio :label="9">Option C</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancelFn">取消</el-button>
        <el-button type="primary" @click="publishFn">
          保存
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>

import type { FormInstance, FormRules } from 'element-plus'
import { ElMessage } from 'element-plus'

const emits = defineEmits(['send'])
const addShow = ref(false)
let title = ref("新增")
const ruleFormRef: any = ref()
const form = reactive({
  v_addressName: '',
  v_lon: '',
  v_lat: '',
  deviceType: '',
  enterprise: '',
  isEnable: '',
  enterprise: '',
  isEnable: '',

})

const deviceTypeInfo = reactive({
  list: [{

value: 'Option1',
label: 'Option1',
},
{
value: 'Option2',
label: 'Option2',

}]
})


const formRules = reactive<FormRules<any>>({
  enterprise: [
    { required: true, message: '请输入企业类型', trigger: 'blur' },
  ],


})

const publishFn = () => {
  if (!ruleFormRef) return
  ruleFormRef.value.validate((valid: any) => {
    if (valid) {
      if (form.linkUrl && linkReg.test(form.linkUrl)) {
        ElMessage({
          type: 'warning',
          message: "请输入正确格式的跳转链接"
        })
      }
      console.log('submit!')
    } else {
      console.log('error submit!')
      return false
    }
  })
}

const cancelFn = (formEl: FormInstance | undefined) => {
  if (!ruleFormRef) return
  ruleFormRef.value.resetFields()
  addShow.value = false
}

const beforeChange = (ev: any) => {
  return new Promise((resolve, reject) => {
    resolve(true)
  })

}

const changeType =()=>{

}


const open = (val: any) => {
  title.value = "新增"
  addShow.value = true
}

const edit = () => {
  title.value = "编辑"
  addShow.value = true
}

defineExpose({
  open,
  edit
})

</script>

<style scoped lang="scss"></style>
