DeviceReportInfo.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <BasicForm ref="FormRef" @register="registerForm" />
  3. <div class="j-box-bottom-button offset-20" style="margin-top: 30px">
  4. <div class="j-box-bottom-button-float">
  5. <a-button preIcon="ant-design:sync-outlined" @click="onReset">重置</a-button>
  6. <a-button type="primary" preIcon="ant-design:save-filled" @click="handleSubmit">保存</a-button>
  7. </div>
  8. </div>
  9. </template>
  10. <script lang="ts" setup>
  11. import { onMounted, ref, defineEmits, onUnmounted, watch, PropType, nextTick, inject, onBeforeMount } from 'vue';
  12. import { BasicForm, useForm } from '/@/components/Form/index';
  13. import { FormSchema } from '/@/components/Form';
  14. import { getFormSchemaColumns } from '/@/hooks/web/useWebColumns';
  15. import { list as substationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
  16. import { list, updateReportInfo, sysList, sysInput } from '../../monitorManager/comment/comment.api';
  17. const deviceData = inject('formData') as any;
  18. const emit = defineEmits(['close', 'register']);
  19. const FormRef = ref();
  20. const tabType = ref('');
  21. const formSchema = ref<any[]>([]);
  22. const formData = ref(deviceData);
  23. const deviceTypeName = ref(deviceData.devicekind ? deviceData.devicekind : deviceData.strtype);
  24. const arrToFormColumns = (tableHeaderColumns = [], devicetype) => {
  25. const columnList: any[] = [];
  26. tableHeaderColumns.forEach((item: any) => {
  27. let columnsItem;
  28. if (item.type == 1 || item.type == 10) {
  29. columnsItem = {
  30. label: item.des, //_dictText
  31. field: item.monitorcode,
  32. component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  33. };
  34. } else {
  35. if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  36. columnsItem = {
  37. label: item.des, //_dictText
  38. field: item.monitorcode,
  39. component: 'ApiSelect',
  40. componentProps: {
  41. api: substationList,
  42. labelField: 'strname',
  43. valueField: 'id',
  44. },
  45. };
  46. }
  47. if (item.type == 3) {
  48. columnsItem = {
  49. label: item.des, //_dictText
  50. field: item.monitorcode,
  51. component: 'RadioGroup',
  52. defaultValue: 1,
  53. componentProps: () => {
  54. return {
  55. options: [
  56. { label: '是', value: 1, key: '1' },
  57. { label: '否', value: 0, key: '2' },
  58. ],
  59. stringToNumber: true,
  60. };
  61. },
  62. };
  63. }
  64. if (item.type == 4) {
  65. columnsItem = {
  66. label: item.des, //_dictText
  67. field: item.monitorcode,
  68. component: 'JDictSelectTag',
  69. componentProps: {
  70. dictCode: item.dict,
  71. placeholder: '请选择',
  72. stringToNumber: true,
  73. },
  74. };
  75. }
  76. }
  77. columnList.push(columnsItem);
  78. });
  79. formSchema.value = columnList;
  80. if (tabType.value === 'deviceInfo') {
  81. formSchema.value.unshift(
  82. {
  83. label: '设备id', //_dictText
  84. field: 'id',
  85. component: 'Input',
  86. componentProps: {
  87. disabled: true,
  88. show: false,
  89. },
  90. },
  91. {
  92. label: '点表',
  93. field: 'strtype',
  94. component: 'JDictSelectTag',
  95. componentProps: {
  96. dictCode: `${devicetype.split('_')[0]}kind`,
  97. placeholder: '请选择点表',
  98. },
  99. }
  100. );
  101. formSchema.value.push({
  102. label: '备用分站',
  103. field: 'stationids',
  104. component: 'ApiSelect',
  105. componentProps: {
  106. api: substationList,
  107. labelField: 'strname',
  108. valueField: 'id',
  109. },
  110. });
  111. } else {
  112. formSchema.value.unshift({
  113. label: '设备id', //_dictText
  114. field: 'id',
  115. component: 'Input',
  116. componentProps: {
  117. disabled: true,
  118. show: false,
  119. },
  120. });
  121. }
  122. };
  123. const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
  124. schemas: <FormSchema[]>formSchema.value,
  125. showActionButtonGroup: false,
  126. });
  127. function getColumns() {
  128. let formSchemaArr = getFormSchemaColumns(`${deviceData.devicekind ? deviceData.devicekind : deviceData.strtype}_input`) || [];
  129. if (formSchemaArr && formSchemaArr.length < 1) {
  130. const arr = deviceTypeName.value.split('_');
  131. formSchemaArr = getFormSchemaColumns(arr[0] + '_input') || [];
  132. }
  133. arrToFormColumns(formSchemaArr, deviceTypeName.value);
  134. resetSchema(formSchema.value);
  135. }
  136. async function onReset() {
  137. await resetFields();
  138. await setFieldsValue({ ...deviceData });
  139. }
  140. async function handleSubmit() {
  141. const data = await getFieldsValue();
  142. if (!deviceData.devicekind) {
  143. await sysInput(data);
  144. } else {
  145. await updateReportInfo(data);
  146. }
  147. }
  148. onBeforeMount(async () => {});
  149. onMounted(async () => {
  150. getColumns();
  151. let result;
  152. if (!deviceData.devicekind) {
  153. result = await sysList({ id: deviceData.id });
  154. } else {
  155. result = await list({ id: deviceData.id });
  156. }
  157. formData.value = result['records'][0] || [];
  158. await setFieldsValue({
  159. ...formData.value,
  160. });
  161. });
  162. onUnmounted(() => {});
  163. </script>
  164. <style scoped lang="less">
  165. @import '/@/design/theme.less';
  166. @import '/@/design/vent/modal.less';
  167. </style>