index3.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="vent-flex-row">
  3. <span style="color: #fff;">关联的控制设备:</span>
  4. <a-select v-model:value="sysDeviceId" style="width: 200px" placeholder="关联的控制设备" :options="sysDeviceOptions"
  5. @change="handleChange" :allowClear="true" />
  6. <a-button class="vent-margin-l-8" type="primary" @click="getDeviceWarningPointList"> 查询 </a-button>
  7. <a-button class="vent-margin-l-8" type="primary" @click="addPoint"> 新增 </a-button>
  8. </div>
  9. <EditRowTableVue v-if="refresh" ref="RefComponent" :columns="BackWindDevicePointColumns" :data-source="dataSource"
  10. @save-or-update="saveOrUpdate" @delete-by-id="handleDelete" :isAdd="false" style="margin-top: 10px">
  11. </EditRowTableVue>
  12. <DevicePointTable @register="registerModal" :data-source="devicePointList" :selection-row-keys="selectionRowKeys"
  13. @reload="reload" />
  14. </template>
  15. <script lang="ts" setup>
  16. import { defineProps, ref, onMounted } from 'vue';
  17. import { BackWindDevicePointColumns } from './warning.data';
  18. import EditRowTableVue from '../../../comment/EditRowTable.vue';
  19. import { backWindControlDevicePointList, backWindControlDevicePointEdit, backWindControlDevicePointDelete, workFaceDeviceList, workFacePointList, backWindControlDevicePointBatchAdd } from './warning.api';
  20. import DevicePointTable from './DevicePointTable.vue';
  21. import { useModal } from '/@/components/Modal';
  22. const props = defineProps({
  23. deviceId: { type: String },
  24. pointType: {
  25. type: String,
  26. requried: true,
  27. },
  28. });
  29. const sysDeviceId = ref('') // 选中的关联设备的id
  30. const sysDeviceType = ref('')
  31. const devicePointList = ref<any[]>([])
  32. const selectionRowKeys = ref<any[]>([])
  33. const sysDeviceOptions = ref<any[]>([])
  34. let sysDeviceList = <any[]>[]
  35. const RefComponent = ref()
  36. const dataSource = ref<any[]>([])
  37. const refresh = ref(true)
  38. const [registerModal, { openModal }] = useModal();
  39. const handleChange = async (value) => {
  40. sysDeviceId.value = value
  41. const obj = sysDeviceList.find((element) => {
  42. return element.id == value
  43. })
  44. sysDeviceType.value = obj['strtype']
  45. await getDeviceWarningPointList()
  46. }
  47. async function getDeviceWarningPointList() {
  48. const result = await backWindControlDevicePointList({ deviceId: sysDeviceId.value })
  49. if (result && result.records.length > 0) {
  50. dataSource.value = result.records
  51. } else {
  52. dataSource.value = []
  53. }
  54. }
  55. async function getDevicePointList() {
  56. try {
  57. const result = await workFacePointList({ deviceType: sysDeviceType.value, valueType: 1 });
  58. devicePointList.value = result
  59. const rowKeys = <any[]>[]
  60. dataSource.value.forEach((item) => {
  61. rowKeys.push(item['monitorId'])
  62. })
  63. selectionRowKeys.value = rowKeys
  64. } catch (error) {
  65. devicePointList.value = []
  66. }
  67. };
  68. async function getDeviceOptions() {
  69. const result = await workFaceDeviceList({ id: props.deviceId })
  70. const options = <any[]>[]
  71. if (result.length > 0) {
  72. result.forEach(element => {
  73. options.push({ value: element.id, label: element.strname })
  74. });
  75. sysDeviceOptions.value = options
  76. sysDeviceList = result
  77. }
  78. }
  79. async function saveOrUpdate(record) {
  80. try {
  81. if (record.id) {
  82. await backWindControlDevicePointEdit({ ...record });
  83. }
  84. RefComponent.value.reload()
  85. } catch (error) { }
  86. }
  87. function handleDelete(id) {
  88. backWindControlDevicePointDelete({ id }).then(() => {
  89. getDeviceWarningPointList()
  90. })
  91. }
  92. async function reload(list) {
  93. const monitorList = <any[]>[]
  94. list.forEach(item => {
  95. monitorList.push({ deviceId: sysDeviceId.value, monitorId: item['id'], monitorName: item['valuename'], sysId: props.deviceId })
  96. })
  97. await backWindControlDevicePointBatchAdd(monitorList)
  98. getDeviceWarningPointList()
  99. }
  100. function addPoint() {
  101. getDevicePointList().then(() => {
  102. openModal();
  103. })
  104. }
  105. onMounted(async () => {
  106. await getDeviceOptions()
  107. await getDeviceWarningPointList()
  108. });
  109. </script>
  110. <style lang="less" scoped>
  111. @ventSpace: zxm;
  112. </style>