xiaoyi
5 天以前 a4025834e2304dc57f6e98d58feeb9416bd90609
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<script lang="ts" setup>
  import type { VbenFormSchema } from '#/adapter/form';
  import type { MesPdProductApi } from '#/api/mes/pd/product';
 
  import { computed, ref } from 'vue';
 
  import { useVbenModal } from '@vben/common-ui';
  import { $t } from '@vben/locales';
 
  import { message } from 'ant-design-vue';
 
  import { useVbenForm } from '#/adapter/form';
  import { auditProduct } from '#/api/mes/pd/product';
 
  const emit = defineEmits(['success']);
  const pass = ref(true); // true=通过 / false=驳回
  const rowData = ref<MesPdProductApi.Product>();
  const getTitle = computed(() => (pass.value ? '审核通过' : '审核驳回'));
 
  const [Form, formApi] = useVbenForm({
    commonConfig: {
      componentProps: {
        class: 'w-full',
      },
      formItemClass: 'col-span-1',
      labelWidth: 130,
    },
    wrapperClass: 'grid-cols-1',
    layout: 'horizontal',
    schema: [],
    showDefaultActions: false,
  });
 
  /** 审核表单字段 */
  function useAuditSchema(): VbenFormSchema[] {
    return [
      {
        fieldName: 'auditRemark',
        label: '审批意见',
        component: 'Textarea',
        formItemClass: 'col-span-1',
        componentProps: {
          rows: 3,
          placeholder: pass.value
            ? '请输入审批意见(可选)'
            : '请输入驳回原因(必填)',
        },
        rules: pass.value ? '' : 'required',
      },
    ];
  }
 
  const [Modal, modalApi] = useVbenModal({
    async onConfirm() {
      const { valid } = await formApi.validate();
      if (!valid) {
        return;
      }
      modalApi.lock();
      const values = await formApi.getValues();
      try {
        await auditProduct({
          id: rowData.value!.id!,
          pass: pass.value,
          auditRemark: values.auditRemark,
        });
        await modalApi.close();
        emit('success');
        message.success(pass.value ? '审批通过' : '审批驳回');
      } finally {
        modalApi.unlock();
      }
    },
    async onOpenChange(isOpen: boolean) {
      if (!isOpen) {
        return;
      }
      const data = modalApi.getData<{
        row: MesPdProductApi.Product;
        pass: boolean;
      }>();
      rowData.value = data.row;
      pass.value = data.pass;
      formApi.setState({ schema: useAuditSchema() });
      formApi.resetForm();
    },
  });
</script>
 
<template>
  <Modal :title="getTitle" class="w-2/5">
    <Form class="mx-4" />
  </Modal>
</template>