Procházet zdrojové kódy

采购合同-发票登记

huangbin před 4 roky
rodič
revize
f2ccf1536e

+ 12 - 27
src/views/business/purchase/components/invoice/index.vue

@@ -88,7 +88,7 @@
       <a-form class="inlineForm"
               ref="formRef"
               :model="formState"
-              :rules="formStateRules">
+              :rules="rules">
         <a-row :gutter="24">
           <a-col :span="12">
             <a-form-item label="点价价格"
@@ -153,8 +153,9 @@ import { getPriceTypeName } from '@/views/business/purchase/setup';
 import { operationContractReq } from '@/services/proto/contract';
 import { message } from 'ant-design-vue';
 import { objectToUint8Array } from '@/utils/objHandle';
-import {InvoiceReq, SettlementReq} from "@/services/proto/contract/interface";
-import {invoiceReq, settlementReq} from "@/views/business/purchase/components/setup";
+import { InvoiceReq, SettlementReq } from '@/services/proto/contract/interface';
+import { invoiceReq, settlementReq } from '@/views/business/purchase/components/setup';
+import { handleForm } from './setup';
 
 export default defineComponent({
     name: 'purchase_pending_invoice',
@@ -165,40 +166,24 @@ export default defineComponent({
             default: {},
         },
     },
-    setup(props,context) {
+    setup(props, context) {
         const { visible, cancel } = closeModal('purchase_pending_invoice');
         const loading = ref<boolean>(false);
-        const formRef = ref();
-        const formState = reactive({ PricedPrice: 0, PricedQty: 0 });
-        const numberIstrue = (rule: any, value: any) => {
-            if (!value) {
-                return Promise.reject(new Error('请输入正确的值'));
-            } else {
-                return Promise.resolve();
-            }
-        };
-        const formStateRules = {
-            PricedPrice: [{ required: true, validator: numberIstrue, trigger: 'blur', type: 'number' }],
-            PricedQty: [{ required: true, validator: numberIstrue, trigger: 'blur', type: 'number' }],
-        };
+        const { rules, formState, formRef } = handleForm();
         function submit() {
             const wrapEl = unref(formRef);
             wrapEl.validate().then(() => {
                 loading.value = true;
-                const params : InvoiceReq = {
+                const params: InvoiceReq = {
                     InvoiceAmount: 123,
-                }
+                };
                 // 发出发票登记
-                invoiceReq(
-                    props.selectedRow.spotcontractid,
-                    params,
-                    loading)
+                invoiceReq(props.selectedRow.spotcontractid, params, loading)
                     .then(() => {
                         cancel();
-                        context.emit('refresh')
+                        context.emit('refresh');
                     })
-                    .catch((err) => {
-                    });
+                    .catch((err) => {});
             });
         }
 
@@ -210,7 +195,7 @@ export default defineComponent({
             formRef,
             formState,
             formatValue,
-            formStateRules,
+            rules,
             getPriceTypeName,
         };
     },

+ 19 - 0
src/views/business/purchase/components/invoice/setup.ts

@@ -0,0 +1,19 @@
+import { reactive, ref, UnwrapRef } from "vue";
+/**
+ * 表单
+ * @returns 
+ */
+export function handleForm() {
+    interface FormState {
+        InvoiceAmount: number | null
+    }
+    const formRef = ref();
+    const formState: UnwrapRef<FormState> = reactive({
+        InvoiceAmount: null,
+    })
+    const rules = {
+        // PricedPrice: [{ required: true, message: '请输入点价价格', trigger: 'blur', type: 'number' }],
+        // PricedQty: [{ required: true, message: '请输入点价数量', trigger: 'blur', type: 'number' }],
+    }
+    return { rules, formState, formRef }
+}