CuspCustomerProfileModal.vue 4.9 KB

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