index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div>
  3. <EditRowTableVue
  4. v-if="refreshParent"
  5. :columns="warningColumns"
  6. :list="list.bind(null, { deviceid: deviceId })"
  7. @save-or-update="saveOrUpdateParent"
  8. @delete-by-id="parentDeleteById"
  9. @row-change="changeParentRow"
  10. :isAdd="true"
  11. :isRadio="true"
  12. :scroll="{y: 200}"
  13. >
  14. <template #filterCell="{ column, record }">
  15. <template v-if="record.editable && column.dataIndex === 'monitorcode'">
  16. <div style="position: relative">
  17. <Select
  18. :options="options"
  19. v-model:value="record.editValueRefs['monitorcode']"
  20. :fieldNames="{ label: 'valuename', value: 'valuecode' }"
  21. size="small"
  22. style="min-width: 100px"
  23. />
  24. <!-- <a-popover placement="monitorcode" :visible="true">
  25. <template #content>
  26. <p>Content</p>
  27. </template>
  28. </a-popover> -->
  29. </div>
  30. </template>
  31. </template>
  32. </EditRowTableVue>
  33. <div style="color: #efefef; margin-top: 8px;">注: 请先选中监测参数才能添加报警等级</div>
  34. <EditRowTableVue
  35. v-if="refresh && warningProId !== ''"
  36. ref="RefChildComponent"
  37. :columns="levelColumns"
  38. :list="limitList.bind(null, { limitid: warningProId })"
  39. @save-or-update="saveOrUpdateChild"
  40. @delete-by-id="childDeleteById"
  41. :isAdd="true"
  42. style="margin-top: 10px"
  43. :scroll="{ y: 200 }"
  44. />
  45. <a-table v-else :dataSource="[]" :columns="levelColumns" style="margin-top: 10px" />
  46. </div>
  47. </template>
  48. <script lang="ts" setup>
  49. import { Select } from 'ant-design-vue';
  50. import EditRowTableVue from '../../../comment/EditRowTable.vue';
  51. import { warningColumns, levelColumns } from './warning.data';
  52. import { list, limitList, edit, save, limitSave, limitEdit, deleteById, limitDeleteById } from './warning.api';
  53. import { list as pointList } from '../pointTabel/point.api';
  54. import { defineProps, ref, nextTick, inject, onMounted } from 'vue';
  55. const props = defineProps({
  56. deviceId: { type: String },
  57. pointType: {
  58. type: String,
  59. requried: true,
  60. },
  61. });
  62. // const
  63. const options = ref([]);
  64. const RefChildComponent = ref(null);
  65. const warningProId = ref('');
  66. const currentParent = ref({});
  67. const refresh = ref(true);
  68. const refreshParent = ref(true);
  69. async function saveOrUpdateParent(record) {
  70. try {
  71. if (record.id) {
  72. await edit({ ...record });
  73. } else {
  74. await save({ ...record, deviceid: props.deviceId });
  75. }
  76. refreshParent.value = false;
  77. nextTick(() => {
  78. refreshParent.value = true;
  79. });
  80. } catch (error) {}
  81. }
  82. async function saveOrUpdateChild(record) {
  83. if (record.id) {
  84. await limitEdit({ ...record });
  85. } else {
  86. await limitSave({ ...record, limitid: warningProId.value, code: currentParent.value['monitorcode'] });
  87. }
  88. refresh.value = false;
  89. nextTick(() => {
  90. refresh.value = true;
  91. });
  92. }
  93. function parentDeleteById(id, reload) {
  94. deleteById({ id: id }, reload);
  95. }
  96. function childDeleteById(id, reload) {
  97. limitDeleteById({ id: id }, reload);
  98. }
  99. function changeParentRow(id, rowData) {
  100. warningProId.value = id;
  101. currentParent.value = rowData;
  102. refresh.value = false;
  103. nextTick(() => {
  104. refresh.value = true;
  105. });
  106. }
  107. onMounted(async () => {
  108. const res = await pointList({ devicetype: props.pointType, valuetype_begin: 2 });
  109. options.value = res && res['records'] ? res['records'] : [];
  110. });
  111. </script>
  112. <style scoped></style>