2025-03-20 09:26:41 +08:00
|
|
|
<template>
|
|
|
|
<BasicDrawer
|
|
|
|
v-bind="$attrs"
|
|
|
|
@register="registerDrawer"
|
|
|
|
:title="getTitle"
|
|
|
|
:width="adaptiveWidth"
|
|
|
|
@ok="handleSubmit"
|
|
|
|
:showFooter="showFooter"
|
|
|
|
destroyOnClose
|
|
|
|
>
|
2025-03-27 14:13:59 +08:00
|
|
|
<BasicForm @register="registerForm">
|
|
|
|
<template #areaSelect ="{model,field}">
|
|
|
|
<a-select v-model:value="model[field]" @change="(value,option) => handleChange(value,option,model)">
|
|
|
|
<template v-for="item in areaOptions" :key="`${item.id}`">
|
|
|
|
<a-select-option :value="item.id" :label="item.instName">
|
|
|
|
{{item.instName}}
|
|
|
|
</a-select-option>
|
|
|
|
</template>
|
|
|
|
</a-select>
|
|
|
|
</template>
|
|
|
|
</BasicForm>
|
2025-03-20 09:26:41 +08:00
|
|
|
</BasicDrawer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { defineComponent, ref, computed, unref, useAttrs } from 'vue';
|
|
|
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
|
|
|
import { formSchema } from "@/views/iot/tplink/region/RegionInfo.data";
|
|
|
|
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
|
|
|
import { useDrawerAdaptiveWidth } from '/@/hooks/jeecg/useAdaptiveWidth';
|
|
|
|
import { getTenantId } from "/@/utils/auth";
|
2025-03-27 14:13:59 +08:00
|
|
|
import {queryArea, saveOrUpdateRegion} from "@/views/iot/tplink/region/RegionInfo.api";
|
2025-03-20 09:26:41 +08:00
|
|
|
|
|
|
|
// 声明Emits
|
|
|
|
const emit = defineEmits(['success', 'register']);
|
|
|
|
const attrs = useAttrs();
|
|
|
|
const isUpdate = ref(true);
|
|
|
|
const rowId = ref('');
|
|
|
|
let isFormDepartUser = false;
|
|
|
|
//表单配置
|
|
|
|
const [registerForm, { setProps, resetFields, setFieldsValue, validate, updateSchema }] = useForm({
|
|
|
|
labelWidth: 90,
|
|
|
|
schemas: formSchema,
|
|
|
|
showActionButtonGroup: false,
|
|
|
|
});
|
|
|
|
const showFooter = ref(true);
|
2025-03-27 14:13:59 +08:00
|
|
|
const areaOptions = ref<any[]>([]);
|
2025-03-20 09:26:41 +08:00
|
|
|
//表单赋值
|
|
|
|
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
|
|
|
await resetFields();
|
|
|
|
showFooter.value = data?.showFooter ?? true;
|
|
|
|
setDrawerProps({ confirmLoading: false, showFooter: showFooter.value });
|
|
|
|
isUpdate.value = !!data?.isUpdate;
|
|
|
|
// 无论新增还是编辑,都可以设置表单值
|
|
|
|
if (typeof data.record === 'object') {
|
|
|
|
setFieldsValue({
|
|
|
|
...data.record,
|
|
|
|
});
|
2025-03-27 14:13:59 +08:00
|
|
|
await fetchArea(data.record.institutionId);
|
2025-03-20 09:26:41 +08:00
|
|
|
}
|
|
|
|
// 隐藏底部时禁用整个表单
|
|
|
|
setProps({ disabled: !showFooter.value });
|
|
|
|
});
|
|
|
|
//获取标题
|
|
|
|
const getTitle = computed(() => {
|
|
|
|
if (!unref(isUpdate)) {
|
|
|
|
return '新增区域';
|
|
|
|
} else {
|
|
|
|
return unref(showFooter) ? '编辑区域' : '区域详情';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const { adaptiveWidth } = useDrawerAdaptiveWidth();
|
|
|
|
|
|
|
|
//提交事件
|
|
|
|
async function handleSubmit() {
|
|
|
|
try {
|
|
|
|
let values = await validate();
|
|
|
|
setDrawerProps({ confirmLoading: true });
|
|
|
|
let params = values;
|
|
|
|
let isUpdateVal = unref(isUpdate);
|
|
|
|
await saveOrUpdateRegion(params,isUpdateVal);
|
|
|
|
//关闭弹窗
|
|
|
|
closeDrawer();
|
|
|
|
//刷新列表
|
|
|
|
emit('success');
|
|
|
|
} finally {
|
|
|
|
setDrawerProps({ confirmLoading: false });
|
|
|
|
}
|
|
|
|
}
|
2025-03-27 14:13:59 +08:00
|
|
|
|
|
|
|
const fetchArea = async (institutionId) => {
|
|
|
|
if (!institutionId){
|
|
|
|
institutionId = '-1';
|
|
|
|
}
|
|
|
|
areaOptions.value = [];
|
|
|
|
const data = await queryArea({ pid : institutionId });
|
|
|
|
Object.assign(areaOptions.value, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleChange(value,option:Option,formData){
|
|
|
|
if(value == null){
|
|
|
|
formData["regionName"] = "";
|
|
|
|
}else{
|
|
|
|
formData["regionName"] = option.label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-03-20 09:26:41 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|