DeviceBaseInfo.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <BasicModal
  3. @register="register"
  4. :title="tabType == 'deviceInfo' ? '设备编辑' : '报表录入'"
  5. width="1000px"
  6. v-bind="$attrs"
  7. @ok="onSubmit"
  8. :mask-closable="false"
  9. >
  10. <BasicForm ref="FormRef" @register="registerForm" />
  11. </BasicModal>
  12. </template>
  13. <script lang="ts" setup>
  14. import { onMounted, ref, defineEmits, onUnmounted, watch, computed } from 'vue';
  15. import { BasicModal, useModalInner } from '/@/components/Modal';
  16. import { BasicForm, useForm } from '/@/components/Form/index';
  17. import { FormSchema } from '/@/components/Form';
  18. import { getFormSchemaColumns } from '/@/hooks/web/useWebColumns';
  19. import { list as substationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
  20. import { getRegulation as getRegulationList } from '/@/views/vent/deviceManager/substationTabel/substation.api';
  21. import { list, updateDeviceInfo, updateReportInfo } from '../comment.api';
  22. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  23. import { on } from 'events';
  24. const emit = defineEmits(['close', 'register']);
  25. const props = defineProps({
  26. // formSchema: {
  27. // type: Array as PropType<FormSchema[]>,
  28. // default: () => [],
  29. // },
  30. deviceType: {
  31. type: String,
  32. default: '',
  33. },
  34. });
  35. const FormRef = ref();
  36. const tabType = ref('deviceInfo');
  37. const formSchema = ref<Array<FormSchema>>([]);
  38. const formData = ref({});
  39. // const props.deviceType ref('');
  40. const deviceType = computed(() => props.deviceType);
  41. // const arrToFormColumns = (tableHeaderColumns = [], devicetype) => {
  42. // const columnList: any[] = [];
  43. // tableHeaderColumns.forEach((item: any) => {
  44. // let columnsItem;
  45. // if (item.type == 1 || item.type == 10) {
  46. // columnsItem = {
  47. // label: item.des, //_dictText
  48. // field: item.monitorcode,
  49. // component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  50. // };
  51. // } else {
  52. // if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  53. // columnsItem = {
  54. // label: item.des, //_dictText
  55. // field: item.monitorcode,
  56. // component: 'ApiSelect',
  57. // componentProps: {
  58. // api: substationList,
  59. // labelField: 'strname',
  60. // valueField: 'id',
  61. // },
  62. // };
  63. // }
  64. // if (item.type == 3) {
  65. // columnsItem = {
  66. // label: item.des, //_dictText
  67. // field: item.monitorcode,
  68. // component: 'RadioGroup',
  69. // defaultValue: 1,
  70. // componentProps: () => {
  71. // return {
  72. // options: [
  73. // { label: '是', value: 1, key: '1' },
  74. // { label: '否', value: 0, key: '2' },
  75. // ],
  76. // stringToNumber: true,
  77. // };
  78. // },
  79. // };
  80. // }
  81. // if (item.type == 4) {
  82. // columnsItem = {
  83. // label: item.des, //_dictText
  84. // field: item.monitorcode,
  85. // component: 'JDictSelectTag',
  86. // componentProps: {
  87. // dictCode: item.dict,
  88. // placeholder: '请选择',
  89. // stringToNumber: true,
  90. // },
  91. // };
  92. // }
  93. // }
  94. // columnList.push(columnsItem);
  95. // });
  96. // formSchema.value = columnList
  97. // if(tabType.value === 'deviceInfo'){
  98. // formSchema.value.unshift(
  99. // {
  100. // label: '设备id', //_dictText
  101. // field: 'id',
  102. // component: 'Input',
  103. // componentProps: {
  104. // disabled: true,
  105. // show: false
  106. // },
  107. // },
  108. // {
  109. // label: '点表',
  110. // field: 'strtype',
  111. // component: 'JDictSelectTag',
  112. // componentProps: {
  113. // dictCode: `${devicetype.split('_')[0]}kind`,
  114. // placeholder: '请选择点表',
  115. // },
  116. // })
  117. // formSchema.value.push(
  118. // {
  119. // label: '备用分站',
  120. // field: 'stationids',
  121. // component: 'ApiSelect',
  122. // componentProps: {
  123. // api: substationList,
  124. // labelField: 'strname',
  125. // valueField: 'id',
  126. // },
  127. // },
  128. // )
  129. // }else{
  130. // formSchema.value.unshift(
  131. // {
  132. // label: '设备id', //_dictText
  133. // field: 'id',
  134. // component: 'Input',
  135. // componentProps: {
  136. // disabled: true,
  137. // show: false
  138. // },
  139. // })
  140. // }
  141. // };
  142. const arrToFormColumns = (tableHeaderColumns = []) => {
  143. const columnList: any[] = [];
  144. tableHeaderColumns.forEach((item: any) => {
  145. let columnsItem;
  146. switch (item.type) {
  147. case 1:
  148. columnsItem = { label: item.des, field: item.monitorcode, component: 'Input' };
  149. break;
  150. case 10:
  151. columnsItem = { label: item.des, field: item.monitorcode, component: 'InputTextArea' };
  152. break;
  153. case 2:
  154. if (item.monitorcode !== 'nsubstationid') break;
  155. columnsItem = {
  156. label: item.des,
  157. field: item.monitorcode,
  158. component: 'ApiSelect',
  159. componentProps: { api: substationList, labelField: 'strname', valueField: 'id' },
  160. };
  161. break;
  162. case 3:
  163. columnsItem = {
  164. label: item.des,
  165. field: item.monitorcode,
  166. component: 'RadioGroup',
  167. defaultValue: 1,
  168. componentProps: () => ({
  169. options: [
  170. { label: '是', value: 1, key: '1' },
  171. { label: '否', value: 0, key: '2' },
  172. ],
  173. stringToNumber: true,
  174. }),
  175. };
  176. break;
  177. case 4:
  178. columnsItem = {
  179. label: item.des,
  180. field: item.monitorcode,
  181. component: 'JDictSelectTag',
  182. componentProps: { dictCode: item.dict, placeholder: '请选择' },
  183. };
  184. break;
  185. case 8:
  186. columnsItem = {
  187. label: item.des,
  188. field: item.monitorcode,
  189. component: 'DatePicker',
  190. componentProps: { showTime: false, valueFormat: 'YYYY-MM-DD', getPopupContainer: getAutoScrollContainer },
  191. };
  192. break;
  193. case 9:
  194. columnsItem = {
  195. label: item.des,
  196. field: item.monitorcode,
  197. component: 'DatePicker',
  198. componentProps: { showTime: true, valueFormat: 'YYYY-MM-DD HH:mm:ss', getPopupContainer: getAutoScrollContainer },
  199. };
  200. break;
  201. case 11:
  202. columnsItem = {
  203. label: item.des,
  204. field: item.monitorcode,
  205. component: 'ModelSelect',
  206. componentProps: { deviceType: props.deviceType },
  207. };
  208. break;
  209. }
  210. if (!!columnsItem) {
  211. columnList.push(columnsItem);
  212. }
  213. });
  214. formSchema.value = columnList;
  215. formSchema.value.unshift(
  216. {
  217. label: '设备id', //_dictText
  218. field: 'id',
  219. component: 'Input',
  220. componentProps: {
  221. disabled: true,
  222. },
  223. },
  224. {
  225. label: '点表',
  226. field: 'strtype',
  227. component: 'JDictSelectTag',
  228. componentProps: {
  229. dictCode: `${deviceType.value.split('_')[0]}kind`, //${deviceType.value}kind
  230. placeholder: '请选择点表',
  231. // stringToNumber: true,
  232. },
  233. },
  234. {
  235. label: '规程值',
  236. field: 'regulation',
  237. component: 'ApiSelect',
  238. // componentProps: {
  239. // api: getRegulationList({ deviceKind: deviceType.value.split('_')[0] }),
  240. // labelField: 'name',
  241. // valueField: 'id',
  242. // },
  243. componentProps: ({ formModel }) => {
  244. return {
  245. api: getRegulationList.bind(null, { deviceKind: deviceType.value.split('_')[0] }),
  246. labelField: 'name',
  247. valueField: 'id',
  248. onChange: (e, option) => {
  249. if (option) formModel['regulation'] = option['name'];
  250. },
  251. };
  252. },
  253. }
  254. );
  255. formSchema.value.push(
  256. {
  257. label: '备用分站',
  258. field: 'stationids',
  259. component: 'ApiSelect',
  260. componentProps: {
  261. api: substationList,
  262. labelField: 'strname',
  263. valueField: 'id',
  264. },
  265. },
  266. {
  267. label: '是否显示',
  268. field: 'linkId',
  269. component: 'RadioGroup',
  270. defaultValue: 1,
  271. componentProps: () => {
  272. return {
  273. options: [
  274. { label: '是', value: 1, key: '1' },
  275. { label: '否', value: 0, key: '2' },
  276. ],
  277. stringToNumber: true,
  278. };
  279. },
  280. }
  281. );
  282. };
  283. // 注册 modal
  284. const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
  285. tabType.value = data.type;
  286. const deviceId = data.deviceId;
  287. if (FormRef.value) {
  288. setModalProps({ confirmLoading: false });
  289. getColumns();
  290. resetSchema(formSchema.value);
  291. resetFields();
  292. const result = await list({ id: deviceId });
  293. formData.value = result['records'][0];
  294. await setFieldsValue({
  295. ...formData.value,
  296. });
  297. }
  298. });
  299. const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
  300. schemas: formSchema.value,
  301. showActionButtonGroup: false,
  302. });
  303. function getColumns() {
  304. let formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? `${props.deviceType}_edit` : `${props.deviceType}_input`) || [];
  305. if (formSchemaArr && formSchemaArr.length < 1) {
  306. const arr = props.deviceType.split('_');
  307. formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? arr[0] + '_edit' : arr[0] + '_input') || [];
  308. }
  309. arrToFormColumns(formSchemaArr);
  310. }
  311. watch(
  312. () => props.deviceType,
  313. () => {
  314. getColumns();
  315. if (FormRef.value) resetSchema(formSchema.value);
  316. }
  317. );
  318. async function onSubmit() {
  319. let formValue = getFieldsValue();
  320. setModalProps({ confirmLoading: true });
  321. if (tabType.value === 'deviceInfo') {
  322. await updateDeviceInfo(formValue);
  323. } else {
  324. await updateReportInfo(formValue);
  325. }
  326. setModalProps({ confirmLoading: false });
  327. emit('close');
  328. closeModal();
  329. }
  330. onMounted(async () => {});
  331. onUnmounted(() => {});
  332. </script>
  333. <style scoped lang="less">
  334. @import '/@/design/theme.less';
  335. @import '/@/design/vent/modal.less';
  336. </style>