DeviceBaseInfo.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. if (item.type == 1 || item.type == 10) {
  147. columnsItem = {
  148. label: item.des, //_dictText
  149. field: item.monitorcode,
  150. component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  151. };
  152. } else {
  153. if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  154. columnsItem = {
  155. label: item.des, //_dictText
  156. field: item.monitorcode,
  157. component: 'ApiSelect',
  158. componentProps: {
  159. api: substationList,
  160. labelField: 'strname',
  161. valueField: 'id',
  162. },
  163. };
  164. }
  165. if (item.type == 3) {
  166. columnsItem = {
  167. label: item.des, //_dictText
  168. field: item.monitorcode,
  169. component: 'RadioGroup',
  170. defaultValue: 1,
  171. componentProps: () => {
  172. return {
  173. options: [
  174. { label: '是', value: 1, key: '1' },
  175. { label: '否', value: 0, key: '2' },
  176. ],
  177. stringToNumber: true,
  178. };
  179. },
  180. };
  181. }
  182. if (item.type == 4) {
  183. columnsItem = {
  184. label: item.des, //_dictText
  185. field: item.monitorcode,
  186. component: 'JDictSelectTag',
  187. componentProps: {
  188. dictCode: item.dict,
  189. placeholder: '请选择',
  190. // stringToNumber: true,
  191. },
  192. };
  193. }
  194. // date日期
  195. if (item.type == 8) {
  196. columnsItem = {
  197. label: item.des, //_dictText
  198. field: item.monitorcode,
  199. component: 'DatePicker',
  200. componentProps: {
  201. showTime: false,
  202. valueFormat: 'YYYY-MM-DD',
  203. getPopupContainer: getAutoScrollContainer,
  204. },
  205. };
  206. }
  207. // 日期+时间
  208. if (item.type == 9) {
  209. columnsItem = {
  210. label: item.des, //_dictText
  211. field: item.monitorcode,
  212. component: 'DatePicker',
  213. componentProps: {
  214. showTime: true,
  215. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  216. getPopupContainer: getAutoScrollContainer,
  217. },
  218. };
  219. }
  220. }
  221. columnList.push(columnsItem);
  222. });
  223. formSchema.value = columnList;
  224. formSchema.value.unshift(
  225. {
  226. label: '设备id', //_dictText
  227. field: 'id',
  228. component: 'Input',
  229. componentProps: {
  230. disabled: true,
  231. },
  232. },
  233. {
  234. label: '点表',
  235. field: 'strtype',
  236. component: 'JDictSelectTag',
  237. componentProps: {
  238. dictCode: `${deviceType.value.split('_')[0]}kind`, //${deviceType.value}kind
  239. placeholder: '请选择点表',
  240. // stringToNumber: true,
  241. },
  242. },
  243. {
  244. label: '规程值',
  245. field: 'regulation',
  246. component: 'ApiSelect',
  247. // componentProps: {
  248. // api: getRegulationList({ deviceKind: deviceType.value.split('_')[0] }),
  249. // labelField: 'name',
  250. // valueField: 'id',
  251. // },
  252. componentProps: ({ formModel }) => {
  253. return {
  254. api: getRegulationList.bind(null, { deviceKind: deviceType.value.split('_')[0] }),
  255. labelField: 'name',
  256. valueField: 'id',
  257. onChange: (e, option) => {
  258. if (option) formModel['regulation'] = option['name'];
  259. },
  260. };
  261. },
  262. }
  263. );
  264. formSchema.value.push(
  265. {
  266. label: '备用分站',
  267. field: 'stationids',
  268. component: 'ApiSelect',
  269. componentProps: {
  270. api: substationList,
  271. labelField: 'strname',
  272. valueField: 'id',
  273. },
  274. },
  275. {
  276. label: '是否显示',
  277. field: 'linkId',
  278. component: 'RadioGroup',
  279. defaultValue: 1,
  280. componentProps: () => {
  281. return {
  282. options: [
  283. { label: '是', value: 1, key: '1' },
  284. { label: '否', value: 0, key: '2' },
  285. ],
  286. stringToNumber: true,
  287. };
  288. },
  289. }
  290. );
  291. };
  292. // 注册 modal
  293. const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
  294. tabType.value = data.type;
  295. const deviceId = data.deviceId;
  296. if (FormRef.value) {
  297. setModalProps({ confirmLoading: false });
  298. getColumns();
  299. resetSchema(formSchema.value);
  300. resetFields();
  301. const result = await list({ id: deviceId });
  302. formData.value = result['records'][0];
  303. await setFieldsValue({
  304. ...formData.value,
  305. });
  306. }
  307. });
  308. const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
  309. schemas: formSchema.value,
  310. showActionButtonGroup: false,
  311. });
  312. function getColumns() {
  313. let formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? `${props.deviceType}_edit` : `${props.deviceType}_input`) || [];
  314. if (formSchemaArr && formSchemaArr.length < 1) {
  315. const arr = props.deviceType.split('_');
  316. formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? arr[0] + '_edit' : arr[0] + '_input') || [];
  317. }
  318. arrToFormColumns(formSchemaArr);
  319. }
  320. watch(
  321. () => props.deviceType,
  322. () => {
  323. getColumns();
  324. if (FormRef.value) resetSchema(formSchema.value);
  325. }
  326. );
  327. async function onSubmit() {
  328. let formValue = getFieldsValue();
  329. setModalProps({ confirmLoading: true });
  330. if (tabType.value === 'deviceInfo') {
  331. await updateDeviceInfo(formValue);
  332. } else {
  333. await updateReportInfo(formValue);
  334. }
  335. setModalProps({ confirmLoading: false });
  336. emit('close');
  337. closeModal();
  338. }
  339. onMounted(async () => {});
  340. onUnmounted(() => {});
  341. </script>
  342. <style scoped lang="less">
  343. @import '/@/design/theme.less';
  344. @import '/@/design/vent/modal.less';
  345. </style>