DeviceBaseInfo.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. const emit = defineEmits(['close', 'register']);
  24. const props = defineProps({
  25. // formSchema: {
  26. // type: Array as PropType<FormSchema[]>,
  27. // default: () => [],
  28. // },
  29. deviceType: {
  30. type: String,
  31. default: '',
  32. },
  33. });
  34. const FormRef = ref();
  35. const tabType = ref('deviceInfo');
  36. const formSchema = ref<Array<FormSchema>>([]);
  37. const formData = ref({});
  38. // const props.deviceType ref('');
  39. const deviceType = computed(() => props.deviceType);
  40. // const arrToFormColumns = (tableHeaderColumns = [], devicetype) => {
  41. // const columnList: any[] = [];
  42. // tableHeaderColumns.forEach((item: any) => {
  43. // let columnsItem;
  44. // if (item.type == 1 || item.type == 10) {
  45. // columnsItem = {
  46. // label: item.des, //_dictText
  47. // field: item.monitorcode,
  48. // component: item.type == 1 ? 'Input' : item.type == 10 ? 'InputTextArea' : '',
  49. // };
  50. // } else {
  51. // if (item.type == 2 && item['monitorcode'] == 'nsubstationid') {
  52. // columnsItem = {
  53. // label: item.des, //_dictText
  54. // field: item.monitorcode,
  55. // component: 'ApiSelect',
  56. // componentProps: {
  57. // api: substationList,
  58. // labelField: 'strname',
  59. // valueField: 'id',
  60. // },
  61. // };
  62. // }
  63. // if (item.type == 3) {
  64. // columnsItem = {
  65. // label: item.des, //_dictText
  66. // field: item.monitorcode,
  67. // component: 'RadioGroup',
  68. // defaultValue: 1,
  69. // componentProps: () => {
  70. // return {
  71. // options: [
  72. // { label: '是', value: 1, key: '1' },
  73. // { label: '否', value: 0, key: '2' },
  74. // ],
  75. // stringToNumber: true,
  76. // };
  77. // },
  78. // };
  79. // }
  80. // if (item.type == 4) {
  81. // columnsItem = {
  82. // label: item.des, //_dictText
  83. // field: item.monitorcode,
  84. // component: 'JDictSelectTag',
  85. // componentProps: {
  86. // dictCode: item.dict,
  87. // placeholder: '请选择',
  88. // stringToNumber: true,
  89. // },
  90. // };
  91. // }
  92. // }
  93. // columnList.push(columnsItem);
  94. // });
  95. // formSchema.value = columnList
  96. // if(tabType.value === 'deviceInfo'){
  97. // formSchema.value.unshift(
  98. // {
  99. // label: '设备id', //_dictText
  100. // field: 'id',
  101. // component: 'Input',
  102. // componentProps: {
  103. // disabled: true,
  104. // show: false
  105. // },
  106. // },
  107. // {
  108. // label: '点表',
  109. // field: 'strtype',
  110. // component: 'JDictSelectTag',
  111. // componentProps: {
  112. // dictCode: `${devicetype.split('_')[0]}kind`,
  113. // placeholder: '请选择点表',
  114. // },
  115. // })
  116. // formSchema.value.push(
  117. // {
  118. // label: '备用分站',
  119. // field: 'stationids',
  120. // component: 'ApiSelect',
  121. // componentProps: {
  122. // api: substationList,
  123. // labelField: 'strname',
  124. // valueField: 'id',
  125. // },
  126. // },
  127. // )
  128. // }else{
  129. // formSchema.value.unshift(
  130. // {
  131. // label: '设备id', //_dictText
  132. // field: 'id',
  133. // component: 'Input',
  134. // componentProps: {
  135. // disabled: true,
  136. // show: false
  137. // },
  138. // })
  139. // }
  140. // };
  141. const arrToFormColumns = (tableHeaderColumns = []) => {
  142. const columnList: any[] = [];
  143. console.log(tableHeaderColumns, 'tableHeaderColumns');
  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,
  249. labelField: 'name',
  250. valueField: 'id',
  251. },
  252. }
  253. );
  254. formSchema.value.push(
  255. {
  256. label: '备用分站',
  257. field: 'stationids',
  258. component: 'ApiSelect',
  259. componentProps: {
  260. api: substationList,
  261. labelField: 'strname',
  262. valueField: 'id',
  263. },
  264. },
  265. {
  266. label: '是否显示',
  267. field: 'linkId',
  268. component: 'RadioGroup',
  269. defaultValue: 1,
  270. componentProps: () => {
  271. return {
  272. options: [
  273. { label: '是', value: 1, key: '1' },
  274. { label: '否', value: 0, key: '2' },
  275. ],
  276. stringToNumber: true,
  277. };
  278. },
  279. }
  280. );
  281. };
  282. // 注册 modal
  283. const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
  284. tabType.value = data.type;
  285. const deviceId = data.deviceId;
  286. if (FormRef.value) {
  287. setModalProps({ confirmLoading: false });
  288. getColumns();
  289. resetSchema(formSchema.value);
  290. resetFields();
  291. const result = await list({ id: deviceId });
  292. formData.value = result['records'][0];
  293. await setFieldsValue({
  294. ...formData.value,
  295. });
  296. }
  297. });
  298. const [registerForm, { resetSchema, getFieldsValue, setFieldsValue, resetFields }] = useForm({
  299. schemas: formSchema.value,
  300. showActionButtonGroup: false,
  301. });
  302. function getColumns() {
  303. let formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? `${props.deviceType}_edit` : `${props.deviceType}_input`) || [];
  304. if (formSchemaArr && formSchemaArr.length < 1) {
  305. const arr = props.deviceType.split('_');
  306. formSchemaArr = getFormSchemaColumns(tabType.value === 'deviceInfo' ? arr[0] + '_edit' : arr[0] + '_input') || [];
  307. }
  308. arrToFormColumns(formSchemaArr);
  309. }
  310. watch(
  311. () => props.deviceType,
  312. () => {
  313. getColumns();
  314. if (FormRef.value) resetSchema(formSchema.value);
  315. }
  316. );
  317. async function onSubmit() {
  318. let formValue = getFieldsValue();
  319. setModalProps({ confirmLoading: true });
  320. if (tabType.value === 'deviceInfo') {
  321. await updateDeviceInfo(formValue);
  322. } else {
  323. await updateReportInfo(formValue);
  324. }
  325. setModalProps({ confirmLoading: false });
  326. emit('close');
  327. closeModal();
  328. }
  329. onMounted(async () => {});
  330. onUnmounted(() => {});
  331. </script>
  332. <style scoped lang="less">
  333. @import '/@/design/theme.less';
  334. @import '/@/design/vent/modal.less';
  335. </style>