BaseModal1.vue 3.9 KB

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