<template>
  <el-dialog v-model.trim="addShow" :title="title" width="480px" draggable :close-on-click-modal="false">
    <el-form :model="form" ref="ruleFormRef" label-width="102px" :rules="formRules" style="padding: 0 0px 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.value" :label="item.label"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="装备型号：" prop="deviceCode">
        <el-input v-model.trim="form.deviceCode" placeholder="请输入装备型号" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="装备规格：" prop="deviceSize">
        <el-input v-model.trim="form.deviceSize" placeholder="请输入装备规格" clearable maxlength="30" />
      </el-form-item>
      <el-form-item label="装备状态：" prop="deviceStatus">
        <el-radio-group v-model="form.deviceStatus">
          <el-radio :label="item.value" v-for="(item,index) in deviceStatusInfo.list">{{ item.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="GPS编号：" prop="GPScode">
        <el-input v-model.trim="form.gpsCode" placeholder="请输入GPS编号" clearable maxlength="30" />
      </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: '',
  deviceCode: '',
  deviceSize: '',
  deviceStatus: '',
  gpsCode: '',

})

const deviceTypeInfo = reactive({
  list: [{

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

  }]
})

const deviceStatusInfo = 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) {
     
      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 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>
