DeviceBaseInfo.vue 9.8 KB

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