DeviceBaseInfo.vue 9.4 KB

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