CuspCustomerProfileModal.vue 4.2 KB

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