多表单验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<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>

  

posted @   abcByme  阅读(7)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
历史上的今天:
2018-09-12 js 数组随机洗牌
点击右上角即可分享
微信分享提示