DeviceBaseInfo.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <BasicModal @register="register" :title="tabType =='deviceInfo' ? '设备编辑' : '报表录入'" width="1000px" v-bind="$attrs" @ok="onSubmit" :mask-closable="false">
  3. <BasicForm ref="FormRef" @register="registerForm"/>
  4. </BasicModal>
  5. </template>
  6. <script lang="ts" setup>
  7. import { onMounted, ref, defineEmits, onUnmounted, watch, PropType, nextTick } from 'vue';
  8. import { BasicModal, useModalInner } from '/@/components/Modal';
  9. import { BasicForm, useForm } from '/@/components/Form/index';
  10. import { FormSchema } from '/@/components/Form';
  11. import { getFormSchemaColumns } from '/@/hooks/web/useWebColumns';
  12. import { list as substationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
  13. import {list, updateDeviceInfo, updateReportInfo } from '../comment.api'
  14. const emit = defineEmits(['close', 'register'])
  15. const props = defineProps({
  16. formSchema: {
  17. type: Array as PropType <FormSchema[]> ,
  18. default: () => []
  19. },
  20. deviceType: {
  21. type: String,
  22. default: ''
  23. },
  24. })
  25. const FormRef = ref()
  26. const tabType = ref('deviceInfo')
  27. const formSchema = ref<FormSchema[]>([])
  28. const formData = ref({})
  29. const deviceTypeName = ref('')
  30. const arrToFormColumns = (tableHeaderColumns = [], devicetype) => {
  31. const columnList: any[] = [];
  32. tableHeaderColumns.forEach((item: any) => {
  33. let columnsItem;
  34. if (item.type == 1 || item.type == 10) {
  35. columnsItem = {
  36. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  37. field: item.monitorcode,
  38. component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  39. };
  40. } else {
  41. if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  42. columnsItem = {
  43. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  44. field: item.monitorcode,
  45. component: 'ApiSelect',
  46. componentProps: {
  47. api: substationList,
  48. labelField: 'strname',
  49. valueField: 'id',
  50. },
  51. };
  52. }
  53. if (item.type == 3) {
  54. columnsItem = {
  55. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  56. field: item.monitorcode,
  57. component: 'RadioGroup',
  58. defaultValue: 1,
  59. componentProps: () => {
  60. return {
  61. options: [
  62. { label: '是', value: 1, key: '1' },
  63. { label: '否', value: 0, key: '2' },
  64. ],
  65. stringToNumber: true,
  66. };
  67. },
  68. };
  69. }
  70. if (item.type == 4) {
  71. columnsItem = {
  72. label: item.unit ? `${item.des}(${item.unit})` : item.des, //_dictText
  73. field: item.monitorcode,
  74. component: 'JDictSelectTag',
  75. componentProps: {
  76. dictCode: item.dict,
  77. placeholder: '请选择',
  78. stringToNumber: true,
  79. },
  80. };
  81. }
  82. }
  83. columnList.push(columnsItem);
  84. });
  85. formSchema.value = columnList
  86. if(tabType.value === 'deviceInfo'){
  87. formSchema.value.unshift(
  88. {
  89. label: '设备id', //_dictText
  90. field: 'id',
  91. component: 'Input',
  92. componentProps: {
  93. disabled: true,
  94. show: false
  95. },
  96. },
  97. {
  98. label: '点表',
  99. field: 'strtype',
  100. component: 'JDictSelectTag',
  101. componentProps: {
  102. dictCode: `${devicetype.split('_')[0]}kind`,
  103. placeholder: '请选择点表',
  104. },
  105. })
  106. formSchema.value.push(
  107. {
  108. label: '备用分站',
  109. field: 'stationids',
  110. component: 'ApiSelect',
  111. componentProps: {
  112. api: substationList,
  113. labelField: 'strname',
  114. valueField: 'id',
  115. },
  116. },
  117. )
  118. }else{
  119. formSchema.value.unshift(
  120. {
  121. label: '设备id', //_dictText
  122. field: 'id',
  123. component: 'Input',
  124. componentProps: {
  125. disabled: true,
  126. show: false
  127. },
  128. })
  129. }
  130. };
  131. // 注册 modal
  132. const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
  133. debugger
  134. tabType.value = data.type
  135. const deviceId = data.deviceId
  136. if (FormRef.value) {
  137. setModalProps({ confirmLoading: false });
  138. getColumns()
  139. resetSchema(formSchema.value)
  140. resetFields()
  141. const result = await list({ id: deviceId })
  142. formData.value = result['records'][0]
  143. await setFieldsValue({
  144. ...formData.value,
  145. });
  146. }
  147. });
  148. const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
  149. schemas: <FormSchema[]>formSchema.value,
  150. showActionButtonGroup: false,
  151. });
  152. function getColumns() {
  153. let formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? `${deviceTypeName.value}_edit` : `${deviceTypeName.value}_input`) || []
  154. if (formSchemaArr && formSchemaArr.length < 1) {
  155. const arr = deviceTypeName.value.split('_')
  156. formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? arr[0] + '_edit' : arr[0] + '_input') || []
  157. }
  158. arrToFormColumns(formSchemaArr, deviceTypeName.value)
  159. }
  160. watch(() => props.deviceType, (devicetype) => {
  161. deviceTypeName.value = devicetype
  162. getColumns()
  163. if(FormRef.value)resetSchema(formSchema.value)
  164. })
  165. async function onSubmit() {
  166. let formValue = getFieldsValue();
  167. setModalProps({ confirmLoading: true });
  168. if(tabType.value === 'deviceInfo'){
  169. await updateDeviceInfo(formValue)
  170. }else{
  171. await updateReportInfo(formValue)
  172. }
  173. setModalProps({ confirmLoading: false });
  174. emit('close')
  175. closeModal();
  176. }
  177. onMounted(async () => {
  178. debugger
  179. });
  180. onUnmounted(() => {
  181. });
  182. </script>
  183. <style scoped lang="less">
  184. @import '/@/design/vent/color.less';
  185. @import '/@/design/vent/modal.less';
  186. </style>