SupplierManageModal.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="registerModal"
  5. destroyOnClose
  6. :title="title"
  7. :width="1200"
  8. :bodyStyle="{ padding: '20px' }"
  9. @ok="handleSubmit"
  10. >
  11. <BasicForm style="width: 90%" @register="registerForm" ref="formRef" name="SupplierManageForm" />
  12. <!-- 子表单区域 -->
  13. <a-tabs v-model:activeKey="activeKey" animated @change="handleChangeTabs">
  14. <a-tab-pane tab="供应商联系人信息" key="supplyContacts" :forceRender="true">
  15. <JVxeTable
  16. keep-source
  17. resizable
  18. ref="supplyContacts"
  19. :loading="supplyContactsTable.loading"
  20. :columns="supplyContactsTable.columns"
  21. :dataSource="supplyContactsTable.dataSource"
  22. :height="340"
  23. :rowNumber="true"
  24. :rowSelection="true"
  25. :disabled="formDisabled"
  26. :toolbar="true"
  27. />
  28. </a-tab-pane>
  29. </a-tabs>
  30. </BasicModal>
  31. </template>
  32. <script lang="ts" setup>
  33. import { ref, computed, unref, reactive } from 'vue';
  34. import { BasicModal, useModalInner } from '/@/components/Modal';
  35. import { BasicForm, useForm } from '/@/components/Form/index';
  36. import { JVxeTable } from '/@/components/jeecg/JVxeTable';
  37. import { useJvxeMethod } from '/@/hooks/system/useJvxeMethods';
  38. import { formSchema, supplyContactsColumns } from '../SupplierManage.data';
  39. import { saveOrUpdate, supplyContactsList } from '../SupplierManage.api';
  40. // import { VALIDATE_FAILED } from '/@/utils/common/vxeUtils';
  41. // Emits声明
  42. const emit = defineEmits(['register', 'success']);
  43. const isUpdate = ref(true);
  44. const formDisabled = ref(false);
  45. const refKeys = ref(['supplyContacts']);
  46. const activeKey = ref('supplyContacts');
  47. const supplyContacts = ref();
  48. const tableRefs = { supplyContacts };
  49. const supplyContactsTable = reactive({
  50. loading: false,
  51. dataSource: [],
  52. columns: supplyContactsColumns,
  53. });
  54. //表单配置
  55. const [registerForm, { setProps, resetFields, setFieldsValue }] = useForm({
  56. labelWidth: 150,
  57. schemas: formSchema,
  58. showActionButtonGroup: false,
  59. baseColProps: { span: 24 },
  60. });
  61. //表单赋值
  62. const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  63. //重置表单
  64. await reset();
  65. setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
  66. isUpdate.value = !!data?.isUpdate;
  67. formDisabled.value = !data?.showFooter;
  68. if (unref(isUpdate)) {
  69. //表单赋值
  70. await setFieldsValue({
  71. ...data.record,
  72. grade: data.record.grade ? Number(data.record.grade) : 0,
  73. });
  74. console.log(supplyContacts.value);
  75. if (typeof requestSubTableData === 'function') {
  76. requestSubTableData(supplyContactsList, { id: data?.record?.id }, supplyContactsTable);
  77. }
  78. }
  79. // 隐藏底部时禁用整个表单
  80. setProps({ disabled: !data?.showFooter });
  81. });
  82. //方法配置
  83. const [handleChangeTabs, handleSubmit, requestSubTableData, formRef] = useJvxeMethod(
  84. requestAddOrEdit,
  85. classifyIntoFormData,
  86. tableRefs,
  87. activeKey,
  88. refKeys
  89. );
  90. //设置标题
  91. const title = computed(() => (!unref(isUpdate) ? '新增' : !unref(formDisabled) ? '编辑' : '详情'));
  92. async function reset() {
  93. await resetFields();
  94. activeKey.value = 'supplyContacts';
  95. supplyContactsTable.dataSource = [];
  96. }
  97. function classifyIntoFormData(allValues) {
  98. let main = Object.assign({}, allValues.formValue);
  99. return {
  100. ...main, // 展开
  101. supplyContactsList: allValues.tablesValue[0].tableData,
  102. };
  103. }
  104. //表单提交事件
  105. async function requestAddOrEdit(values) {
  106. try {
  107. setModalProps({ confirmLoading: true });
  108. //提交表单
  109. await saveOrUpdate(values, isUpdate.value);
  110. //关闭弹窗
  111. closeModal();
  112. //刷新列表
  113. emit('success');
  114. } finally {
  115. setModalProps({ confirmLoading: false });
  116. }
  117. }
  118. </script>
  119. <style lang="less" scoped>
  120. /** 时间和数字输入框样式 */
  121. :deep(.ant-input-number) {
  122. width: 100%;
  123. }
  124. :deep(.ant-calendar-picker) {
  125. width: 100%;
  126. }
  127. </style>