Browse Source

修改 新增履约模板

huangbin 4 years ago
parent
commit
e2bcd245f4

+ 1 - 1
src/common/setup/modal/modal.ts

@@ -59,7 +59,7 @@ export function _closeModal(context: SetupContext<emitFn[]>) {
     const visible = ref<boolean>(true);
     /**
      * 关闭弹窗
-     * @param isRefresh 是否需要刷新页面: tur => 刷新;false => 不刷新
+     * @param isRefresh 是否需要刷新页面: true => 刷新;false => 不刷新
      */
     function cancel(isRefresh = false) {
         visible.value = false;

+ 1 - 1
src/services/proto/performance/index.ts

@@ -57,5 +57,5 @@ export const performanceActivate = (param: PerformanceActivateReq): Promise<any>
  * @returns
  */
 export const addPerformanceTemp = (param: AddPerformanceTemp): Promise<any> => {
-    return protoMiddleware<AddPerformanceTemp>(param, 'PerformancePlanTemplateReq', 'PerformancePlanTemplateReq', HeadEnum.tradeMode17)
+    return protoMiddleware<AddPerformanceTemp>(param, 'PerformancePlanTemplateReq', 'PerformancePlanTemplateRsp', HeadEnum.tradeMode17)
 }

+ 3 - 3
src/services/proto/performance/interface.ts

@@ -80,10 +80,10 @@ export interface PerfomanceStempTempInfo {
 export interface AddPerformanceTemp {
     autoid: number // 履约计划模板主键不为0且不为空修改否则新增
     templatename: string // 模板名称
-    takemode: number // 提货方式
-    type: number // 模板类型
+    takemode?: number // 提货方式
+    type?: number // 模板类型
     performancesteps: PerfomanceStempTempInfo[], //履约步骤
     userid: number // 所属用户
-    paymenttype: number // 支付方式
+    paymenttype?: number // 支付方式
     creatorid: number //  操作人
 }

+ 2 - 0
src/services/socket/protobuf/buildReq.ts

@@ -277,6 +277,7 @@ export function protoMiddleware<T>(param: T, reqName: string, rspName: string, h
         const code = rspName ? funCode[rspName] : undefined
         APP.sendTradingServer(package50, code, {
             onSuccess: (res) => {
+                debugger
                 const { isSuccess, result } = parseProtoRsp50(res, rspName);
                 if (isSuccess) {
                     resolve(result);
@@ -285,6 +286,7 @@ export function protoMiddleware<T>(param: T, reqName: string, rspName: string, h
                 }
             },
             onFail: (err) => {
+                debugger
                 console.log(`proto:${reqName}错误消息:${err}`)
                 reject(err.message)
             },

+ 42 - 23
src/views/market/spot_trade/warehouse_receipt_trade/warehouse_receipt_trade_blocs/components/post-buying/addPermance.vue

@@ -18,7 +18,7 @@
                              name="name">
                   <a-input class="commonInput"
                            v-model:value="formState.name"
-                           placeholder="30天账期"
+                           placeholder="请输入模版名称"
                            style="width: 260px" />
                 </a-form-item>
               </a-col>
@@ -88,6 +88,8 @@
                    class="fixedBtns">
               <a-form-item class="btnCenter">
                 <a-button class="listedBtn"
+                          :loading="loading"
+                          :disabled="loading"
                           @click="submit">确定</a-button>
               </a-form-item>
             </a-col>
@@ -113,6 +115,9 @@ import { AddPerformanceTemp, PerfomanceStempTempInfo } from '@/services/proto/pe
 import { validateAction } from '@/common/setup/form';
 import { PermanceTemp, PermanceTempForm } from './interface';
 import { getUserId } from '@/services/bus/account';
+import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
+import { addPerformanceTemp } from '@/services/proto/performance';
+import { geLoginID_number } from '@/services/bus/login';
 
 // 初始化 模板
 const initTemp = (): PermanceTemp => {
@@ -121,8 +126,8 @@ const initTemp = (): PermanceTemp => {
 
 // 新增 模板
 const useAddTemp = (formState: UnwrapRef<PermanceTempForm>) => {
-    const temp = initTemp();
     function addTemp() {
+        const temp = initTemp();
         formState.domains.push(temp);
     }
     function showAddTempBtn(index: number) {
@@ -167,6 +172,13 @@ const userForm = () => {
     const formState: UnwrapRef<PermanceTempForm> = reactive({ domains: [temp], name: '' });
     const findIndex = (name: string): number => formState.domains.findIndex((temp) => temp.steptypename === name);
     const findItem = (name: string) => formState.domains.find((temp) => temp.steptypename === name);
+    const total = (name: string): number =>
+        formState.domains
+            .filter((temp) => temp.steptypename === name)
+            .reduce((acc, cur) => {
+                const { stepvalue } = cur;
+                return stepvalue ? acc + stepvalue : acc;
+            }, 0);
     // 配置卖方收款之前要有买方支付
     function validateSepeTypeId(value: any) {
         const sellIndex = findIndex('卖方收款');
@@ -178,15 +190,11 @@ const userForm = () => {
         }
         return Promise.resolve();
     }
-    function validateStepValue() {
-        const sell = findItem('卖方收款');
-        const buy = findItem('买方支付');
-        if (sell && buy) {
-            const buyValue = sell.stepvalue;
-            const sellValue = sell.stepvalue;
-            if (buyValue && sellValue && sellValue > buyValue) {
-                return Promise.reject('卖方收款不能多于买方付款');
-            }
+    function validateStepValue(value: any) {
+        const buyTotal = total('买方支付');
+        const sellTotal = total('卖方收款');
+        if (sellTotal > buyTotal) {
+            return Promise.reject('卖方收款不能多于买方付款');
         }
         return Promise.resolve();
     }
@@ -198,10 +206,10 @@ const userForm = () => {
                 { required: true, validator: validateSepeTypeId },
             ],
             stepvalue: [
-                { required: true, message: '请输入步骤值', trigger: 'blur' },
+                { required: true, message: '请输入步骤值', trigger: 'blur', type: 'number' },
                 { required: true, validator: validateStepValue },
             ],
-            stepdays: { required: true, message: '请输入距离上一步天数', trigger: 'blur' },
+            stepdays: { required: true, message: '请输入距离上一步天数', trigger: 'blur', type: 'number' },
         },
     };
 
@@ -221,16 +229,27 @@ export default defineComponent({
 
         function submit() {
             validateAction<PermanceTempForm>(formRef, formState).then((res) => {
-                // const performancesteps:PerfomanceStempTempInfo[] = res.domains.map(el => {
-                //   const { }
-                //   return el
-                // })
-                // const param: AddPerformanceTemp  = {
-                //   autoid: 0,
-                //   templatename: res.name,
-                //   userid: getUserId(),
-                //   performancesteps:
-                // }
+                const performancesteps: PerfomanceStempTempInfo[] = res.domains.map((el) => {
+                    const { steptypeid, stepvalue, stepdays, isauto, remark, stepindex } = el;
+                    return {
+                        steptypeid: steptypeid as number,
+                        stepvalue: stepvalue as number,
+                        stepdays: stepdays as number,
+                        isauto,
+                        remark,
+                        stepindex,
+                    };
+                });
+                const param: AddPerformanceTemp = {
+                    autoid: 0,
+                    templatename: res.name,
+                    userid: getUserId(),
+                    performancesteps,
+                    creatorid: geLoginID_number()!,
+                };
+                requestResultLoadingAndInfo(addPerformanceTemp, param, loading, ['新增履约模板成功', '新增履约模板失败:']).then(() => {
+                    cancel(true);
+                });
             });
         }
         return {

+ 9 - 2
src/views/market/spot_trade/warehouse_receipt_trade/warehouse_receipt_trade_blocs/components/post-buying/permancePlanTmp.vue

@@ -37,8 +37,7 @@
     </a-spin>
   </Drawer>
   <Add v-if="show"
-       @cancel="close"
-       @update="close" />
+       @cancel="closeAddTemp" />
 </template>
 
 <script lang="ts">
@@ -72,6 +71,13 @@ export default defineComponent({
         };
         const { loading, tableList, queryTable } = queryTableList<QueryPermancePlanTmpRsp>();
         queryTable(queryQueryPermancePlanTmp, param);
+
+        function closeAddTemp(isRefresh: boolean) {
+            if (isRefresh) {
+                queryTable(queryQueryPermancePlanTmp, param);
+            }
+            close(null);
+        }
         // 选择履约模板
         function chooseTemp(item: QueryPermancePlanTmpRsp) {
             context.emit('update', item);
@@ -86,6 +92,7 @@ export default defineComponent({
             close,
             open,
             chooseTemp,
+            closeAddTemp,
         };
     },
 });