<script setup lang="ts">
import { ref } from 'vue';
import { Modal, message } from 'ant-design-vue';
import { AIRPLANE_MISSION_MODE } from '../enum';
import type { deviceAirPortLoad } from './columns';
import { defaultDeviceKindColumns, deviceAirportLoadColumns, deviceDefaultAbilityColumns } from './columns';
import orgSelectDropTree from './orgSelectDropTree.vue';
import LoadSelect from './loadSelect.vue';
// const emit = defineEmits(['confirm']);
defineOptions({
name: 'DeviceAirportAdd',
});
const loadBind = {
1: '機場 ',
2: '無人機',
};
const loading = {
1: '內置',
2: '外掛',
};
// 獲取默認飛控能力信息
const defaultDeviceUavModelList = ref<API.DeviceModelAbilityBo[]>();
// const deviceUavForm = ref<API.DeviceUavDto>({ deviceName: '', deviceSn: '', orgId: '', deviceType: '', deviceSubType: '' });
function getDefaultAbility(factoryCode: string | undefined, modelId: any) {
const params = ref<API.DeviceUavModelListDto>({
factoryCode,
modelId,
});
postDeviceUavModelGetModelAbility({ ...params.value }).then((res) => {
if (res.success) {
defaultDeviceUavModelList.value = res.data ? res.data : [];
}
});
}
const airportLoadData = ref<deviceAirPortLoad[]>([]); // 機場設備種類
const deviceLoadData = ref<deviceAirPortLoad[]>([]); // 無人機默認設備種類
// 獲取無人機默認設備種類信息
const defaultDeviceKindList = ref<API.DeviceUavModelKindBo[]>([]);
function getDefaultDeviceKindList(factoryCode: string | undefined, modelId: any) {
const params = ref<API.DeviceUavModelListDto>({
factoryCode,
modelId,
});
postDeviceUavModelGetModelKind({ ...params.value }).then((res) => {
if (res.success) {
defaultDeviceKindList.value = res.data?.map((item: any) => {
return {
...item,
abilityName: getDeviceAblity(item),
loadBingName: loadBind[item.loadBind],
loadingName: loading[item.loading],
};
});
}
});
}
const airPlaneUavMode = ref<string[]>([]); // 無人機-航線配置
const deviceAirportAddDetail = ref();
// 表單數據
const airportForm = ref<API.DeviceAirportDto>({
deviceName: '',
orgId: '',
airLine: '',
deviceType: '',
firmwareVersion: '',
deviceSn: '',
deviceSonType: '',
});
// 窗口
const modelValue = ref<boolean>(false);
const deviceUavFormList: any = ref([]);
const factorynametext = ref('');
function openModel(node: API.FlyDockEquipmentDTO, factory: any, factoryname: any) {
// console.log('node', node)
// console.log('factory', factory);
// console.log('factoryname', factoryname);
factorynametext.value = factoryname;
modelValue.value = true;
airportForm.value.deviceName = node.deviceName;
airportForm.value.deviceType = node.deviceType;
airportForm.value.firmwareVersion = node.firmwareVersion;
airportForm.value.deviceSonType = node.deviceSubType;
airportForm.value.deviceSn = node.deviceSn;
airportForm.value.dockerId = node.id;
airportForm.value.modelName = node.deviceName;
airportForm.value.department = node.workspaceName; // 機場
airportForm.value.factoryCode = node.manufacturer; // 廠家id
// console.log('node.uavList列表多個', node.uavList)
deviceUavFormList.value = [];
if (node.uavList) {
// deviceUavForm.value.airportId = node.id; //機場id
// deviceUavForm.value.deviceName = node.uavList[0]?.deviceName;//設備名稱
// deviceUavForm.value.deviceSn = node.uavList[0]?.deviceSn;
// deviceUavForm.value.deviceType = node.uavList[0]?.deviceType;
// deviceUavForm.value.deviceSubType = node.uavList[0]?.deviceSubType;
// deviceUavForm.value.uavId = node.uavList[0]?.id;
// // deviceUavForm.value.factoryId = node.uavList[0]?.manufacturer; //廠家id
// deviceUavForm.value.factoryId = node.manufacturer; //廠家id
// deviceUavForm.value.relStatue = node.uavList[0]?.relStatue;
// // getTypeList(deviceUavForm.value.factoryId);
// 型號下拉
node.uavList.forEach((item) => {
deviceUavFormList.value.push({
airportId: node.id,
deviceName: item.deviceName,
deviceSn: item.deviceSn,
deviceType: item.deviceType,
deviceSubType: item.deviceSubType,
uavId: item.id,
factoryId: node.manufacturer,
relStatue: item.relStatue,
});
});
// console.log('deviceUavFormList', deviceUavFormList.value)
// getTypeList(deviceUavForm.value.factoryId);
getTypeList(node.manufacturer);
}
}
// 校驗表單
const airportRef = ref(); // 機場信息
// const airplaneRef = ref();//無人機信息
const uavDialogRefs: Ref<any> = ref({});
// 確認新增
async function confirmCheck() {
try {
await airportRef.value.validateFields();
// await airplaneRef.value.validateFields();
for (let i = 0; i < deviceUavFormList.value.length; i++) {
await uavDialogRefs.value[deviceUavFormList.value[i].uavId];
}
// deviceUavForm.value.orgId = airportForm.value.orgId;
// deviceUavForm.value.deviceRelKindOtherList = deviceLoadData.value; // 無人機列表
// deviceUavForm.value.uavLine = airPlaneUavMode.value.toString();
// deviceUavForm.value.deviceRelKindList = defaultDeviceKindList.value;
deviceUavFormList.value.forEach((item: any) => {
item.orgId = airportForm.value.orgId;
item.deviceRelKindOtherList = deviceLoadData.value;
item.uavLine = airPlaneUavMode.value.toString();
item.deviceRelKindList = defaultDeviceKindList.value;
});
// console.log('deviceUavFormList.value2222', deviceUavFormList.value)
// airportForm.value.deviceUav = deviceUavForm.value;
airportForm.value.deviceUav = deviceUavFormList.value;
airportForm.value.deviceRelKindList = airportLoadData.value; // 無人機列表
// console.log('保存傳參', airportForm.value)
postDeviceAirportSave(airportForm.value).then((res) => {
if (res.success) {
message.success('新增成功');
modelValue.value = false;
}
});
}
catch (errorInfo) {
}
}
// 根據無人機廠商獲取型號列表
const typeModelList = ref<API.DeviceUavModel[] | undefined>([]);
async function getTypeList(factoryCode: string | undefined) {
const params = { factoryCode };
const res = await postDeviceUavModelGetAll(params);
if (res.success) {
typeModelList.value = res.data;
}
}
// 選取組織
function onSelectOrg(value: string | number) {
airportForm.value.orgId = value;
}
// 打開新增負載窗口
const loadSelectRef = ref();
const loadDataType = ref<number>(1); // 負載掛在哪個設備上 1機場,2無人機
function openLoadDrawer(type: number) {
loadDataType.value = type;
loadSelectRef.value.open();
}
// 設置新增設備種類數據
function setLoadData(data: deviceAirPortLoad[]) {
data.forEach((item) => {
item.open = '1';
item.kindId = item.id; // 將裝置id 轉換為kindId
});
if (loadDataType.value === 1) { // 新增機場設備種類
airportLoadData.value = [...airportLoadData.value, ...data];
}
else { // 新增無人機其他設備種類
deviceLoadData.value = [...deviceLoadData.value, ...data];
}
}
// 復制設備種類
function copyLoad(record: any, index: number, type: number) {
if (type === 1) {
airportLoadData.value.splice(index, 0, JSON.parse(JSON.stringify(record)));
}
else {
deviceLoadData.value.splice(index, 0, JSON.parse(JSON.stringify(record)));
}
}
// 刪除設備種類
function deleteLoad(index: number, type: number) {
if (type === 1) {
airportLoadData.value.splice(index, 1);
}
else {
deviceLoadData.value.splice(index, 1);
}
}
// 無人機型號更改時獲取默認信息
function getModelAbilityAndKind(v: any) {
getDefaultAbility(airportForm.value.factoryCode, v); // 獲取無人機默認飛控能力
getDefaultDeviceKindList(airportForm.value.factoryCode, v); // 獲取無人機默認種類
}
defineExpose({
openModel,
});
// 獲取飛機能力信息
function getDeviceAblity(record: any) {
const str = record.deviceKindAbilityBoList.map((item: any, index: number) => {
return (index + 1) + item.abilityName;
});
return str.join(',');
}
const activeKey = ref(['0']);
// const tableData = ref<API.[]>()
</script>
<template>
<Modal
ref="deviceAirportAddDetail" v-model:open="modelValue" width="1000px" :destroy-on-close="true"
:body-style="{ height: '500px', overflow: 'auto' }" title="新增設備(2/2)" @ok="confirmCheck"
>
<div>
<p class="font-bold mb-2">
機場信息
</p>
<a-form
ref="airportRef" :model="airportForm" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }"
autocomplete="off"
>
<a-row>
<a-col :span="8">
<a-form-item label="廠家">
<a-input v-model:value="factorynametext" :disabled="true" />
</a-form-item>
</a-col>
</a-row>
<a-row>
<a-col :span="8">
<a-form-item label="設備信息" name="deviceName" :rules="[{ required: true, message: '請輸入設備信息!' }]">
<a-input v-model:value="airportForm.deviceName" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="所屬組織" name="orgId" :rules="[{ required: true, message: '請選中組織!' }]">
<orgSelectDropTree :bordered="true" auth="organization" @change="onSelectOrg" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="作業半徑" name="airLine" :rules="[{ required: true, message: '請輸入作業半徑!' }]">
<a-input v-model:value="airportForm.airLine" />
</a-form-item>
</a-col>
</a-row>
<a-row>
<a-col :span="8">
<a-form-item label="機身序列號">
<a-input v-model:value="airportForm.deviceSn" :disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="固件版本">
<a-input v-model:value="airportForm.firmwareVersion" :disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="型號" name="modelName">
<a-input v-model:value="airportForm.modelName" :disabled="true" />
</a-form-item>
</a-col>
</a-row>
<div class="flex justify-between">
<p class="font-bold mb-2">
機場設備種類
</p>
<a-space>
<a-button class="mb-1" type="primary" @click="openLoadDrawer(1)">
添加機場設備種類
</a-button>
</a-space>
</div>
<a-table :columns="deviceAirportLoadColumns" :data-source="airportLoadData" :pagination="false">
<template #bodyCell="{ column, record, index }">
<template v-if="column.dataIndex === 'action'">
<a-space>
<a-button type="primary" @click="copyLoad(record, index, 1)">
<template #icon>
<CopyOutlined />
</template>
</a-button>
<a-button type="primary" danger @click="deleteLoad(index, 1)">
<template #icon>
<DeleteOutlined />
</template>
</a-button>
</a-space>
</template>
<template v-if="column.dataIndex === 'loadIndex'">
<a-input v-model:value="record.loadIndex" />
</template>
<template v-if="column.dataIndex === 'showName'">
<a-input v-model:value="record.showName" />
</template>
<template v-if="column.dataIndex === 'open'">
<a-switch v-model:checked="record.open" checked-value="0" un-checked-value="1" />
</template>
</template>
</a-table>
</a-form>
<!-- 多個設備多個無人機信息 -->
<a-collapse v-model:activeKey="activeKey">
<a-collapse-panel v-for="(item, index) in deviceUavFormList" :key="index" header="無人機配置">
<div>
<p class="font-bold mb-2">
無人機信息
</p>
</div>
<a-form
:ref="(el: any) => {
uavDialogRefs[item.uavId] = el
}" :model="item" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off"
>
<a-row>
<a-col :span="8">
<a-form-item label="設備名稱" name="deviceName" :rules="[{ required: true, message: '請輸入設備信息!' }]">
<a-input v-model:value="item.deviceName" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="廠家" name="factory">
<a-input v-model:value="item.factoryId" :disabled="true" />
</a-form-item>
</a-col>
</a-row>
<a-row>
<a-col :span="8">
<a-form-item label="型號" name="deviceType">
<a-select
v-model:value="item.modelId" :field-names="{ label: 'modelName', value: 'id' }"
:options="typeModelList" @change="getModelAbilityAndKind"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="機身序列號">
<a-input v-model:value="item.deviceSn" :disabled="true" />
</a-form-item>
</a-col>
</a-row>
</a-form>
<div>
<p class="font-bold mb-2">
無人機-默認設備種類
</p>
</div>
<a-table :columns="defaultDeviceKindColumns" :data-source="defaultDeviceKindList" :pagination="false">
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'action'" />
<template v-if="column.dataIndex === 'loadIndex'">
<a-input v-model:value="record.loadIndex" />
</template>
<template v-if="column.dataIndex === 'showName'">
<a-input v-model:value="record.showName" />
</template>
<template v-if="column.dataIndex === 'open'">
<a-switch v-model:checked="record.open" checked-value="0" un-checked-value="1" />
</template>
</template>
</a-table>
<div>
<div class="flex justify-between mr-1">
<p class="font-bold mb-2">
無人機-其他設備種類
</p>
<a-space>
<a-button class="mb-1" type="primary" @click="openLoadDrawer(2)">
添加無人機其他設備種類
</a-button>
</a-space>
</div>
<a-table :columns="deviceAirportLoadColumns" :data-source="deviceLoadData" :pagination="false">
<template #bodyCell="{ column, record, index }">
<template v-if="column.dataIndex === 'action'">
<a-space>
<a-button type="primary" @click="copyLoad(record, index, 1)">
<template #icon>
<CopyOutlined />
</template>
</a-button>
<a-button type="primary" danger @click="deleteLoad(index, 2)">
<template #icon>
<DeleteOutlined />
</template>
</a-button>
</a-space>
</template>
<template v-if="column.dataIndex === 'loadIndex'">
<a-input v-model:value="record.loadIndex" />
</template>
<template v-if="column.dataIndex === 'showName'">
<a-input v-model:value="record.showName" />
</template>
<template v-if="column.dataIndex === 'open'">
<a-switch v-model:checked="record.open" checked-value="0" un-checked-value="1" />
</template>
</template>
</a-table>
</div>
<div>
<div class="flex justify-between">
<p class="font-bold mb-2">
無人機-默認飛控能力
</p>
</div>
<a-table
:columns="deviceDefaultAbilityColumns" :data-source="defaultDeviceUavModelList"
:pagination="false"
>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'action'" />
<template v-if="column.dataIndex === 'loadIndex'">
<a-input v-model:value="record.loadIndex" />
</template>
<template v-if="column.dataIndex === 'showName'">
<a-input v-model:value="record.showName" />
</template>
<template v-if="column.dataIndex === 'open'">
<a-switch v-model:checked="record.open" checked-value="0" un-checked-value="1" />
</template>
</template>
</a-table>
</div>
<div>
<p class="font-bold mb-2">
無人機-航線模式配置
</p>
<a-checkbox-group v-model:value="airPlaneUavMode" name="checkboxgroup" :options="AIRPLANE_MISSION_MODE" />
</div>
</a-collapse-panel>
</a-collapse>
</div>
<LoadSelect ref="loadSelectRef" @select-load-data="setLoadData" />
</Modal>
</template>