DeviceReportInfo.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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: false,
  73. },
  74. };
  75. }
  76. }
  77. columnList.push(columnsItem);
  78. });
  79. formSchema.value = columnList;
  80. console.log(formSchema.value, 'sssssssssssssssssssss');
  81. if (tabType.value === 'deviceInfo') {
  82. formSchema.value.unshift(
  83. {
  84. label: '设备id', //_dictText
  85. field: 'id',
  86. component: 'Input',
  87. componentProps: {
  88. disabled: true,
  89. show: false,
  90. },
  91. },
  92. {
  93. label: '点表',
  94. field: 'strtype',
  95. component: 'JDictSelectTag',
  96. componentProps: {
  97. dictCode: `${devicetype.split('_')[0]}kind`,
  98. placeholder: '请选择点表',
  99. },
  100. }
  101. );
  102. formSchema.value.push({
  103. label: '备用分站',
  104. field: 'stationids',
  105. component: 'ApiSelect',
  106. componentProps: {
  107. api: substationList,
  108. labelField: 'strname',
  109. valueField: 'id',
  110. },
  111. });
  112. } else {
  113. formSchema.value.unshift({
  114. label: '设备id', //_dictText
  115. field: 'id',
  116. component: 'Input',
  117. componentProps: {
  118. disabled: true,
  119. show: false,
  120. },
  121. });
  122. }
  123. };
  124. const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
  125. schemas: <FormSchema[]>formSchema.value,
  126. showActionButtonGroup: false,
  127. });
  128. function getColumns() {
  129. let formSchemaArr = getFormSchemaColumns(`${deviceData.devicekind ? deviceData.devicekind : deviceData.strtype}_input`) || [];
  130. if (formSchemaArr && formSchemaArr.length < 1) {
  131. const arr = deviceTypeName.value.split('_');
  132. formSchemaArr = getFormSchemaColumns(arr[0] + '_input') || [];
  133. }
  134. arrToFormColumns(formSchemaArr, deviceTypeName.value);
  135. resetSchema(formSchema.value);
  136. }
  137. async function onReset() {
  138. await resetFields();
  139. await setFieldsValue({ ...deviceData });
  140. }
  141. async function handleSubmit() {
  142. const data = await getFieldsValue();
  143. if (!deviceData.devicekind) {
  144. await sysInput(data);
  145. } else {
  146. await updateReportInfo(data);
  147. }
  148. }
  149. onBeforeMount(async () => {});
  150. onMounted(async () => {
  151. getColumns();
  152. let result;
  153. if (!deviceData.devicekind) {
  154. result = await sysList({ id: deviceData.id });
  155. } else {
  156. result = await list({ id: deviceData.id });
  157. }
  158. formData.value = result['records'][0] || [];
  159. await setFieldsValue({
  160. ...formData.value,
  161. });
  162. });
  163. onUnmounted(() => {});
  164. </script>
  165. <style scoped lang="less">
  166. @import '/@/design/theme.less';
  167. @import '/@/design/vent/modal.less';
  168. </style>