AdsAccountModal.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
  3. <BasicForm @register="registerForm"/>
  4. </BasicModal>
  5. </template>
  6. <script lang="ts" setup>
  7. import {ref, computed, unref} from 'vue';
  8. import {BasicModal, useModalInner} from '/src/components/Modal';
  9. import {BasicForm, useForm} from '/src/components/Form';
  10. import {formSchema} from '../AdsAccount.data';
  11. import {saveOrUpdate} from '../AdsAccount.api';
  12. // Emits声明
  13. const emit = defineEmits(['register','success']);
  14. const isUpdate = ref(true);
  15. const isDetail = ref(false);
  16. const isAudit = ref(false);
  17. //表单配置
  18. const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({
  19. //labelWidth: 150,
  20. schemas: formSchema,
  21. showActionButtonGroup: false,
  22. baseColProps: {span: 24}
  23. });
  24. //表单赋值
  25. const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
  26. //重置表单
  27. await resetFields();
  28. setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
  29. isUpdate.value = !!data?.isUpdate;
  30. isDetail.value = !!data?.showFooter;
  31. isAudit.value = !!data?.isAudit;
  32. // 赋值所有字段
  33. await setFieldsValue({
  34. ...data.record,
  35. });
  36. if (unref(isAudit)) {
  37. const limitedFields = ['reviewStatus', 'remark', 'accountName'];
  38. const updatedSchema = formSchema.map(field => ({
  39. ...field,
  40. show: limitedFields.includes(field.field),
  41. dynamicDisabled: field.field === 'accountName',
  42. }));
  43. setProps({ schemas: updatedSchema });
  44. } else {
  45. // 如果不是审核模式,则检查是否为更新状态,禁用 reviewStatus 字段
  46. const updatedSchema = formSchema.map(field => {
  47. if (field.field === 'reviewStatus' && unref(isUpdate)) {
  48. return {
  49. ...field,
  50. dynamicDisabled: true, // 禁用 reviewStatus 字段
  51. };
  52. }
  53. return field;
  54. });
  55. setProps({ schemas: updatedSchema });
  56. }
  57. setProps({ disabled: !data?.showFooter })
  58. });
  59. //设置标题
  60. const title = computed(() => unref(isAudit) ? '审核' : (!unref(isUpdate) ? '新增' : (!unref(isDetail) ? '详情' : '编辑')));
  61. //表单提交事件
  62. async function handleSubmit(v) {
  63. try {
  64. let values = await validate();
  65. setModalProps({confirmLoading: true});
  66. //提交表单
  67. await saveOrUpdate(values, isUpdate.value, isAudit.value);
  68. //关闭弹窗
  69. closeModal();
  70. //刷新列表
  71. emit('success');
  72. } finally {
  73. setModalProps({confirmLoading: false});
  74. }
  75. }
  76. </script>
  77. <style lang="less" scoped>
  78. /** 时间和数字输入框样式 */
  79. :deep(.ant-input-number) {
  80. width: 100%;
  81. }
  82. :deep(.ant-calendar-picker) {
  83. width: 100%;
  84. }
  85. </style>