BaseModal1.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <BasicModal @register="register" :title="title" :width="800" :min-height="400" v-bind="$attrs" @ok="onSubmit">
  3. <BasicForm @register="registerForm">
  4. <template #monitor="{ model, field }">
  5. <div class="vent-flex-row-between">
  6. <Select ref="selectRef" disabled v-model:value="pointData" :options="option" style="width: calc(100% - 65px)" />
  7. <a-button class="vent-margin-b-5" type="primary" @click="selectPoint(model['strtype'])" style="position: absolute; right: 0; top: 1px"
  8. >选择</a-button
  9. >
  10. </div>
  11. </template>
  12. </BasicForm>
  13. </BasicModal>
  14. <DevicePointTable @register="registerModal" :data-source="devicePointList" :selection-row-keys="pointData" @reload="setPoint" />
  15. </template>
  16. <script lang="ts" setup>
  17. import { onMounted, ref, defineEmits, unref, nextTick } from 'vue';
  18. import { BasicForm, useForm } from '/@/components/Form/index';
  19. import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
  20. import type { FormSchema } from '/@/components/Form/src/types/form';
  21. import { Select, message } from 'ant-design-vue';
  22. import DevicePointTable from './DevicePointTable.vue';
  23. import { workFacePointList } from './warning.api';
  24. const props = defineProps({
  25. formSchemas: {
  26. type: Array as PropType<FormSchema[]>,
  27. default: () => [],
  28. },
  29. deviceId: { type: String },
  30. monitorType: {
  31. type: String,
  32. default: '2',
  33. },
  34. });
  35. const emit = defineEmits(['add', 'update', 'register']);
  36. const option = ref<any[]>([]);
  37. const devicePointList = ref<any[]>([]);
  38. const pointData = ref<String[]>([]);
  39. const title = ref('');
  40. const isUpdate = ref(false);
  41. // 注册 form
  42. const [registerForm, { resetFields, setFieldsValue, validate, getFieldsValue }] = useForm({
  43. schemas: props.formSchemas,
  44. showActionButtonGroup: false,
  45. });
  46. // 注册 modal
  47. const [register, { setModalProps }] = useModalInner(async (data) => {
  48. isUpdate.value = unref(data.isUpdate);
  49. title.value = unref(data.title);
  50. await resetFields();
  51. debugger;
  52. if (data.isUpdate) {
  53. await setFieldsValue({ ...data.record });
  54. pointData.value = [data.record['monitorId']];
  55. // debugger
  56. // 初始打开有数据时候要查点表
  57. // await getDevicePointList(data.record['deviceId'])
  58. // devicePointList.value.forEach(item => {
  59. // if(item['id'] == pointData.value){
  60. // setPoint([item])
  61. // }
  62. // })
  63. } else if (data.record) {
  64. // 新增
  65. await setFieldsValue({ relId: data.record['relId'] || data.record['id'], monitorId: '' });
  66. }
  67. });
  68. const [registerModal, { openModal }] = useModal();
  69. async function getDevicePointList(strtype) {
  70. try {
  71. const result = await workFacePointList({ deviceType: strtype, valueTypes: '2,3,9' });
  72. devicePointList.value = result;
  73. } catch (error) {
  74. devicePointList.value = [];
  75. }
  76. }
  77. async function onSubmit() {
  78. try {
  79. const data = await getFieldsValue();
  80. await setFieldsValue({ ...data, monitorId: pointData.value[0] });
  81. const values = await validate();
  82. setModalProps({ confirmLoading: true });
  83. // 提交表单
  84. if (!isUpdate.value) {
  85. emit('add', 'add', values);
  86. } else {
  87. emit('update', 'update', values);
  88. }
  89. // //关闭弹窗
  90. // closeModal();
  91. // //刷新列表
  92. // reload()
  93. } finally {
  94. setModalProps({ confirmLoading: false });
  95. }
  96. }
  97. async function selectPoint(strtype) {
  98. if (strtype) {
  99. await getDevicePointList(strtype);
  100. openModal();
  101. } else {
  102. message.info('请先选择设备!');
  103. }
  104. }
  105. function setPoint(value) {
  106. const data = value[0];
  107. option.value = [
  108. {
  109. value: data.id,
  110. label: data.valuename,
  111. },
  112. ];
  113. nextTick(() => {
  114. pointData.value = [data.id];
  115. });
  116. }
  117. onMounted(async () => {});
  118. </script>
  119. <style scoped lang="less"></style>