248 lines
6.6 KiB
Vue
248 lines
6.6 KiB
Vue
<template>
|
|
<div class="edit-popup">
|
|
<popup
|
|
ref="popupRef"
|
|
:title="popupTitle"
|
|
:async="true"
|
|
width="550px"
|
|
@confirm="handleSubmit"
|
|
@close="handleClose"
|
|
>
|
|
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
|
<el-form-item label="产品ID" prop="product_id">
|
|
<el-select
|
|
v-model="formData.product_id"
|
|
filterable
|
|
remote
|
|
reserve-keyword
|
|
placeholder="请输入产品信息"
|
|
:remote-method="queryProduct"
|
|
:loading="loading"
|
|
>
|
|
<el-option
|
|
v-for="item in productOptions"
|
|
:key="item.value"
|
|
:label="item.label"
|
|
:value="item.value"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="设备编码" prop="code">
|
|
<el-input v-model="formData.code" clearable placeholder="请输入设备编码" />
|
|
</el-form-item>
|
|
<el-form-item label="设备名称" prop="name">
|
|
<el-input v-model="formData.name" clearable placeholder="请输入设备名称" />
|
|
</el-form-item>
|
|
<el-form-item label="设备类型" prop="type">
|
|
<el-select class="flex-1" v-model="formData.type" clearable placeholder="请选择设备类型">
|
|
<el-option
|
|
v-for="(item, index) in dictData.device_type"
|
|
:key="index"
|
|
:label="item.name"
|
|
:value="parseInt(item.value)"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="监测项" prop="monitor_item">
|
|
<el-select class="flex-1" v-model="formData.monitor_item" multiple clearable placeholder="请选择设备监测项">
|
|
<el-option
|
|
v-for="(item, index) in dictData.monitor_item"
|
|
:key="index"
|
|
:label="item.name"
|
|
:value="item.value"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="视频地址" prop="video_url">
|
|
<el-input v-model="formData.video_url" clearable placeholder="请输入视频地址" />
|
|
</el-form-item>
|
|
<el-form-item label="设备状态" prop="status">
|
|
<el-select class="flex-1" v-model="formData.status" clearable placeholder="请选择设备状态">
|
|
<el-option
|
|
v-for="(item, index) in dictData.device_status"
|
|
:key="index"
|
|
:label="item.name"
|
|
:value="parseInt(item.value)"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="是否在线" prop="is_online">
|
|
<el-select class="flex-1" v-model="formData.is_online" clearable placeholder="请选择是否在线">
|
|
<el-option
|
|
v-for="(item, index) in dictData.device_online_status"
|
|
:key="index"
|
|
:label="item.name"
|
|
:value="parseInt(item.value)"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="是否绑定土地" prop="is_bind">
|
|
<el-select class="flex-1" v-model="formData.is_bind" clearable placeholder="请选择是否绑定土地">
|
|
<el-option
|
|
v-for="(item, index) in dictData.device_bind_status"
|
|
:key="index"
|
|
:label="item.name"
|
|
:value="parseInt(item.value)"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-form>
|
|
</popup>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup name="deviceEdit">
|
|
import type { FormInstance } from 'element-plus'
|
|
import Popup from '@/components/popup/index.vue'
|
|
import { apiDeviceAdd, apiDeviceEdit, apiDeviceDetail, getUserList, apiProductLists} from '@/api/device'
|
|
import { timeFormat } from '@/utils/util'
|
|
import type { PropType } from 'vue'
|
|
defineProps({
|
|
dictData: {
|
|
type: Object as PropType<Record<string, any[]>>,
|
|
default: () => ({})
|
|
}
|
|
})
|
|
const emit = defineEmits(['success', 'close'])
|
|
const formRef = shallowRef<FormInstance>()
|
|
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
|
const mode = ref('add')
|
|
|
|
|
|
// 弹窗标题
|
|
const popupTitle = computed(() => {
|
|
return mode.value == 'edit' ? '编辑设备' : '新增设备'
|
|
})
|
|
|
|
// 表单数据
|
|
const formData = reactive({
|
|
id: '',
|
|
product_id: '',
|
|
code: '',
|
|
name: '',
|
|
video_url: '',
|
|
type: '',
|
|
monitor_item: '',
|
|
status: '',
|
|
is_online: '',
|
|
is_bind: '',
|
|
})
|
|
|
|
|
|
// 表单验证
|
|
const formRules = reactive<any>({
|
|
product_id: [{
|
|
required: true,
|
|
message: '请输入产品id',
|
|
trigger: ['blur']
|
|
}],
|
|
code: [{
|
|
required: true,
|
|
message: '请输入设备编码',
|
|
trigger: ['blur']
|
|
}],
|
|
name: [{
|
|
required: true,
|
|
message: '请输入设备名称',
|
|
trigger: ['blur']
|
|
}],
|
|
type: [{
|
|
required: true,
|
|
message: '请选择设备类型',
|
|
trigger: ['blur']
|
|
}],
|
|
status: [{
|
|
required: true,
|
|
message: '请选择设备状态',
|
|
trigger: ['blur']
|
|
}],
|
|
is_online: [{
|
|
required: true,
|
|
message: '请选择是否在线',
|
|
trigger: ['blur']
|
|
}],
|
|
is_bind: [{
|
|
required: true,
|
|
message: '请选择是否绑定土地',
|
|
trigger: ['blur']
|
|
}],
|
|
})
|
|
|
|
|
|
// 获取详情
|
|
const setFormData = async (data: Record<any, any>) => {
|
|
for (const key in formData) {
|
|
if (data[key] != null && data[key] != undefined) {
|
|
//@ts-ignore
|
|
formData[key] = data[key]
|
|
}
|
|
}
|
|
}
|
|
|
|
interface ListItem {
|
|
value: string
|
|
label: string
|
|
}
|
|
const productOptions = ref<ListItem[]>([])
|
|
const loading = ref(false)
|
|
|
|
const queryProduct = async (query: string) => {
|
|
if (query) {
|
|
loading.value = true
|
|
const productList = await apiProductLists({
|
|
name: query
|
|
})
|
|
loading.value = false
|
|
if (productList.count > 0) {
|
|
productOptions.value = productList.lists.map((product: any) => {
|
|
return { value: `${product.id}`, label: `ID: ${product.id} / 名称: ${product.name}` }
|
|
})
|
|
} else {
|
|
productOptions.value = []
|
|
}
|
|
loading.value = false
|
|
} else {
|
|
productOptions.value = []
|
|
}
|
|
}
|
|
|
|
|
|
const getDetail = async (row: Record<string, any>) => {
|
|
const data = await apiDeviceDetail({
|
|
id: row.id
|
|
})
|
|
setFormData(data)
|
|
}
|
|
|
|
|
|
// 提交按钮
|
|
const handleSubmit = async () => {
|
|
await formRef.value?.validate()
|
|
const data = { ...formData, }
|
|
mode.value == 'edit'
|
|
? await apiDeviceEdit(data)
|
|
: await apiDeviceAdd(data)
|
|
popupRef.value?.close()
|
|
emit('success')
|
|
}
|
|
|
|
//打开弹窗
|
|
const open = (type = 'add') => {
|
|
mode.value = type
|
|
popupRef.value?.open()
|
|
}
|
|
|
|
// 关闭回调
|
|
const handleClose = () => {
|
|
emit('close')
|
|
}
|
|
|
|
|
|
|
|
defineExpose({
|
|
open,
|
|
setFormData,
|
|
getDetail
|
|
})
|
|
</script>
|