123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- <template>
- <BasicModal
- @register="register"
- :title="tabType == 'deviceInfo' ? '设备编辑' : '报表录入'"
- width="1000px"
- v-bind="$attrs"
- @ok="onSubmit"
- :mask-closable="false"
- >
- <BasicForm ref="FormRef" @register="registerForm" />
- </BasicModal>
- </template>
- <script lang="ts" setup>
- import { onMounted, ref, defineEmits, onUnmounted, watch, computed } from 'vue';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, useForm } from '/@/components/Form/index';
- import { FormSchema } from '/@/components/Form';
- import { getFormSchemaColumns } from '/@/hooks/web/useWebColumns';
- import { list as substationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
- import { getRegulation as getRegulationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
- import { list, updateDeviceInfo, updateReportInfo } from '../comment.api';
- import { getAutoScrollContainer } from '/@/utils/common/compUtils';
- import { on } from 'events';
- const emit = defineEmits(['close', 'register']);
- const props = defineProps({
- // formSchema: {
- // type: Array as PropType<FormSchema[]>,
- // default: () => [],
- // },
- deviceType: {
- type: String,
- default: '',
- },
- });
- const FormRef = ref();
- const tabType = ref('deviceInfo');
- const formSchema = ref<Array<FormSchema>>([]);
- const formData = ref({});
- // const props.deviceType ref('');
- const deviceType = computed(() => props.deviceType);
- // const arrToFormColumns = (tableHeaderColumns = [], devicetype) => {
- // const columnList: any[] = [];
- // tableHeaderColumns.forEach((item: any) => {
- // let columnsItem;
- // if (item.type == 1 || item.type == 10) {
- // columnsItem = {
- // label: item.des, //_dictText
- // field: item.monitorcode,
- // component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
- // };
- // } else {
- // if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
- // columnsItem = {
- // label: item.des, //_dictText
- // field: item.monitorcode,
- // component: 'ApiSelect',
- // componentProps: {
- // api: substationList,
- // labelField: 'strname',
- // valueField: 'id',
- // },
- // };
- // }
- // if (item.type == 3) {
- // columnsItem = {
- // label: item.des, //_dictText
- // field: item.monitorcode,
- // component: 'RadioGroup',
- // defaultValue: 1,
- // componentProps: () => {
- // return {
- // options: [
- // { label: '是', value: 1, key: '1' },
- // { label: '否', value: 0, key: '2' },
- // ],
- // stringToNumber: true,
- // };
- // },
- // };
- // }
- // if (item.type == 4) {
- // columnsItem = {
- // label: item.des, //_dictText
- // field: item.monitorcode,
- // component: 'JDictSelectTag',
- // componentProps: {
- // dictCode: item.dict,
- // placeholder: '请选择',
- // stringToNumber: true,
- // },
- // };
- // }
- // }
- // columnList.push(columnsItem);
- // });
- // formSchema.value = columnList
- // if(tabType.value === 'deviceInfo'){
- // formSchema.value.unshift(
- // {
- // label: '设备id', //_dictText
- // field: 'id',
- // component: 'Input',
- // componentProps: {
- // disabled: true,
- // show: false
- // },
- // },
- // {
- // label: '点表',
- // field: 'strtype',
- // component: 'JDictSelectTag',
- // componentProps: {
- // dictCode: `${devicetype.split('_')[0]}kind`,
- // placeholder: '请选择点表',
- // },
- // })
- // formSchema.value.push(
- // {
- // label: '备用分站',
- // field: 'stationids',
- // component: 'ApiSelect',
- // componentProps: {
- // api: substationList,
- // labelField: 'strname',
- // valueField: 'id',
- // },
- // },
- // )
- // }else{
- // formSchema.value.unshift(
- // {
- // label: '设备id', //_dictText
- // field: 'id',
- // component: 'Input',
- // componentProps: {
- // disabled: true,
- // show: false
- // },
- // })
- // }
- // };
- const arrToFormColumns = (tableHeaderColumns = []) => {
- const columnList: any[] = [];
- tableHeaderColumns.forEach((item: any) => {
- let columnsItem;
- if (item.type == 1 || item.type == 10) {
- columnsItem = {
- label: item.des, //_dictText
- field: item.monitorcode,
- component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
- };
- } else {
- if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
- columnsItem = {
- label: item.des, //_dictText
- field: item.monitorcode,
- component: 'ApiSelect',
- componentProps: {
- api: substationList,
- labelField: 'strname',
- valueField: 'id',
- },
- };
- }
- if (item.type == 3) {
- columnsItem = {
- label: item.des, //_dictText
- field: item.monitorcode,
- component: 'RadioGroup',
- defaultValue: 1,
- componentProps: () => {
- return {
- options: [
- { label: '是', value: 1, key: '1' },
- { label: '否', value: 0, key: '2' },
- ],
- stringToNumber: true,
- };
- },
- };
- }
- if (item.type == 4) {
- columnsItem = {
- label: item.des, //_dictText
- field: item.monitorcode,
- component: 'JDictSelectTag',
- componentProps: {
- dictCode: item.dict,
- placeholder: '请选择',
- // stringToNumber: true,
- },
- };
- }
- // date日期
- if (item.type == 8) {
- columnsItem = {
- label: item.des, //_dictText
- field: item.monitorcode,
- component: 'DatePicker',
- componentProps: {
- showTime: false,
- valueFormat: 'YYYY-MM-DD',
- getPopupContainer: getAutoScrollContainer,
- },
- };
- }
- // 日期+时间
- if (item.type == 9) {
- columnsItem = {
- label: item.des, //_dictText
- field: item.monitorcode,
- component: 'DatePicker',
- componentProps: {
- showTime: true,
- valueFormat: 'YYYY-MM-DD HH:mm:ss',
- getPopupContainer: getAutoScrollContainer,
- },
- };
- }
- }
- columnList.push(columnsItem);
- });
- formSchema.value = columnList;
- formSchema.value.unshift(
- {
- label: '设备id', //_dictText
- field: 'id',
- component: 'Input',
- componentProps: {
- disabled: true,
- },
- },
- {
- label: '点表',
- field: 'strtype',
- component: 'JDictSelectTag',
- componentProps: {
- dictCode: `${deviceType.value.split('_')[0]}kind`, //${deviceType.value}kind
- placeholder: '请选择点表',
- // stringToNumber: true,
- },
- },
- {
- label: '规程值',
- field: 'regulation',
- component: 'ApiSelect',
- // componentProps: {
- // api: getRegulationList({ deviceKind: deviceType.value.split('_')[0] }),
- // labelField: 'name',
- // valueField: 'id',
- // },
- componentProps: ({ formModel }) => {
- return {
- api: getRegulationList.bind(null, { deviceKind: deviceType.value.split('_')[0] }),
- labelField: 'name',
- valueField: 'id',
- onChange: (e, option) => {
- if (option) formModel['regulation'] = option['name'];
- },
- };
- },
- }
- );
- formSchema.value.push(
- {
- label: '备用分站',
- field: 'stationids',
- component: 'ApiSelect',
- componentProps: {
- api: substationList,
- labelField: 'strname',
- valueField: 'id',
- },
- },
- {
- label: '是否显示',
- field: 'linkId',
- component: 'RadioGroup',
- defaultValue: 1,
- componentProps: () => {
- return {
- options: [
- { label: '是', value: 1, key: '1' },
- { label: '否', value: 0, key: '2' },
- ],
- stringToNumber: true,
- };
- },
- }
- );
- };
- // 注册 modal
- const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
- tabType.value = data.type;
- const deviceId = data.deviceId;
- if (FormRef.value) {
- setModalProps({ confirmLoading: false });
- getColumns();
- resetSchema(formSchema.value);
- resetFields();
- const result = await list({ id: deviceId });
- formData.value = result['records'][0];
- await setFieldsValue({
- ...formData.value,
- });
- }
- });
- const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
- schemas: formSchema.value,
- showActionButtonGroup: false,
- });
- function getColumns() {
- let formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? `${props.deviceType}_edit` : `${props.deviceType}_input`) || [];
- if (formSchemaArr && formSchemaArr.length < 1) {
- const arr = props.deviceType.split('_');
- formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? arr[0] + '_edit' : arr[0] + '_input') || [];
- }
- arrToFormColumns(formSchemaArr);
- }
- watch(
- () => props.deviceType,
- () => {
- getColumns();
- if (FormRef.value) resetSchema(formSchema.value);
- }
- );
- async function onSubmit() {
- let formValue = getFieldsValue();
- setModalProps({ confirmLoading: true });
- if (tabType.value === 'deviceInfo') {
- await updateDeviceInfo(formValue);
- } else {
- await updateReportInfo(formValue);
- }
- setModalProps({ confirmLoading: false });
- emit('close');
- closeModal();
- }
- onMounted(async () => {});
- onUnmounted(() => {});
- </script>
- <style scoped lang="less">
- @import '/@/design/theme.less';
- @import '/@/design/vent/modal.less';
- </style>
|