Selaa lähdekoodia

修改新增现货品种

huangbin 4 vuotta sitten
vanhempi
commit
f1f5cdcf60

+ 13 - 0
src/common/setup/validate/index.ts

@@ -0,0 +1,13 @@
+/**
+ * 通用空值验证方法
+ * @param value 
+ * @param errInfo 
+ * @returns 
+ */
+export function validateCommon(value: any, errInfo: string) {
+    if (value) {
+        return Promise.resolve();
+    } else {
+        return Promise.reject(errInfo);
+    }
+}

+ 8 - 7
src/services/go/ermcp/goodsInfo/index.ts

@@ -1,6 +1,7 @@
 /** ================================= 信息 - 现货商品信息 ================================**/
 
 import APP from '@/services';
+import { getUserId } from "@/services/bus/account";
 import { commonSearch_go } from '@/services/go/index';
 import {
     Ermcp3Brand, Ermcp3GoodsGroup, Ermcp3MiddleGoodsDetailEx,
@@ -9,7 +10,6 @@ import {
     ErmcpDeliveryGoodsReq,
     ErmcpDeliveryGoodsRsp, ErmcpMiddleGoodsModel
 } from './interface';
-import {getUserId} from "@/services/bus/account";
 
 /**
  * 查询现货商品 /Ermcp3/QueryDeliveryGoods
@@ -64,9 +64,10 @@ export function QueryDeliveryGoodsDetail(deliverygoodsid?: number): Promise<Ermc
  * @param excludecfg 排除套保品中已关联的商品组 1-排除
  * @constructor
  */
-export function QueryGoodsfGroup(excludecfg: number): Promise<Ermcp3GoodsGroup[]> {
+export function QueryGoodsfGroup(excludecfg?: number): Promise<Ermcp3GoodsGroup[]> {
     const areauserid = APP.get('userAccount').memberuserid; // 所属机构id
-    return commonSearch_go('Ermcp3/QueryGoodsGroup', { areauserid, excludecfg }).catch((err) => {
+    const param = excludecfg ? { areauserid, excludecfg } : { areauserid }
+    return commonSearch_go('/Ermcp3/QueryGoodsGroup', param).catch((err) => {
         throw new Error(`查询期货商品组: ${err.message}`);
     });
 }
@@ -77,9 +78,9 @@ export function QueryGoodsfGroup(excludecfg: number): Promise<Ermcp3GoodsGroup[]
  * @param status 状态 0-停用 1-正常
  * @constructor
  */
-export function QueryMiddleGoods(status: number):  Promise<ErmcpMiddleGoodsModel[]> {
+export function QueryMiddleGoods(status: number): Promise<ErmcpMiddleGoodsModel[]> {
     const userid = getUserId(); // 所属机构id
-    return commonSearch_go('Ermcp/QueryMiddleGoods', { userid, status }).catch((err) => {
+    return commonSearch_go('/Ermcp/QueryMiddleGoods', { userid, status }).catch((err) => {
         throw new Error(`查询套保品种: ${err.message}`);
     });
 }
@@ -89,9 +90,9 @@ export function QueryMiddleGoods(status: number):  Promise<ErmcpMiddleGoodsModel
  * @param middlegoodsid 套保品种id
  * @constructor
  */
-export function QueryMiddleGoodsDetail(middlegoodsid: number):  Promise<Ermcp3MiddleGoodsDetailEx[]> {
+export function QueryMiddleGoodsDetail(middlegoodsid: number): Promise<Ermcp3MiddleGoodsDetailEx[]> {
     const areauserid = APP.get('userAccount').memberuserid; // 所属机构id
-    return commonSearch_go('Ermcp3/QueryMiddleGoodsDetail', { areauserid, middlegoodsid }).catch((err) => {
+    return commonSearch_go('/Ermcp3/QueryMiddleGoodsDetail', { areauserid, middlegoodsid }).catch((err) => {
         throw new Error(`查询套保品种详情(套保品种/商品详情): ${err.message}`);
     });
 }

+ 34 - 29
src/views/information/goods/components/add/index.vue

@@ -303,21 +303,22 @@
                            :rules="rules.wrsconvertdetails.middlegoodsid">
                 <a-select class="inlineFormSelect"
                           style="width: 200px"
+                          @change="middleChange(domain.middlegoodsid, domain)"
                           v-model:value="domain.middlegoodsid"
-                          placeholder="请选择品类">
-                  <a-select-option v-for="item in unitList"
-                                   :value="item.enumitemname"
-                                   :key="item.autoid">
-                    {{item.enumdicname}}
+                          placeholder="请选择套保品种">
+                  <a-select-option v-for="item in goodsGroup"
+                                   :value="item.groupcategroyid"
+                                   :key="item.groupcategroyid">
+                    {{item.goodsgroupname}}
                   </a-select-option>
                 </a-select>
               </a-form-item>
             </a-col>
             <a-col :span="6">
-              <a-form-item :name="['wrsconvertdetails', index, 'unitid']">
+              <a-form-item :name="['wrsconvertdetails', index, 'unitidName']">
                 <a-input class="dialogInput"
                          readonly
-                         v-model:value="domain.unitid"
+                         v-model:value="domain.unitidName"
                          placeholder="选择套保品种后自动填入"></a-input>
               </a-form-item>
             </a-col>
@@ -405,28 +406,26 @@
 </template>
 
 <script lang="ts">
-import { defineComponent, ref, reactive, toRaw, UnwrapRef } from 'vue';
+import { defineComponent, ref, toRaw } from 'vue';
 import { closeModal } from '@/common/setup/modal/index';
 import { initData } from '@/common/methods/index';
 import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
-import { handleAdd, handleFromState } from './setup';
-import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
+import { handleAdd, handleFromState, handleGoodsGroup, getGoodsUnit } from './setup';
 import { getGoodsUnitList } from '../../setup';
 import { RuleObject, ValidateErrorEntity } from 'ant-design-vue/es/form/interface';
-import { FormState } from './interface';
-
-const validateCommon = (value: any, errInfo: string) => {
-    if (value) {
-        return Promise.resolve();
-    } else {
-        return Promise.reject(errInfo);
-    }
-};
+import { FormState, WRSConvertDetailEx } from './interface';
+import { validateCommon } from '@/common/setup/validate';
 
+/**
+ * 检验单位
+ */
 const validateUnit = async (rule: RuleObject, value: number) => {
     return validateCommon(value, '请选择单位');
 };
 
+/**
+ *
+ */
 const valideteWR = async (rule: RuleObject, value: number) => {
     return validateCommon(value, '请选择品类');
 };
@@ -533,11 +532,6 @@ export default defineComponent({
                 .catch((error: ValidateErrorEntity<FormState>) => {
                     console.log('error', error);
                 });
-            // loading.value = true;
-            // setTimeout(() => {
-            //     loading.value = false;
-            //     cancel();
-            // }, 2000);
         }
 
         // 表单
@@ -559,11 +553,21 @@ export default defineComponent({
                 middlegoodsid: { required: true, validator: valideteWR, trigger: 'change' },
                 convertratio: { required: true, message: '请输入套保系数', trigger: 'blur' },
             },
-            // nickname: [{ required: true, message: '请输入企业简称', trigger: 'blur' }],
-            // cardtype: [{ required: true, message: '请选择证件类型', trigger: 'change' }],
         };
-
-        initData(() => {});
+        const { goodsGroup, getGoodsGroup } = handleGoodsGroup();
+        /**
+         * 切换套保品种时候,获取对应的单位
+         */
+        function middleChange(id: number, value: WRSConvertDetailEx) {
+            const obj = goodsGroup.value.find((e) => e.groupcategroyid === id);
+            if (obj) {
+                value.unitidName = getGoodsUnit(obj.agreeunit);
+                value.unitid = obj.agreeunit;
+            }
+        }
+        initData(() => {
+            getGoodsGroup();
+        });
         return {
             visible,
             cancel,
@@ -573,7 +577,8 @@ export default defineComponent({
             deleteOne,
             rules,
             unitList,
-
+            goodsGroup,
+            middleChange,
             submit,
             loading,
             dataSource,

+ 1 - 0
src/views/information/goods/components/add/interface.ts

@@ -15,6 +15,7 @@ export interface GLDDGFactoryItemEx {
 export interface WRSConvertDetailEx {
     middlegoodsid: number | undefined // uint64 套保品种ID(接口为3.1及以下版本时传套保品种ID,否则传期货品种ID)
     unitid: number | null// uint64 单位ID
+    unitidName: string;
     convertratio: number | null// double 套保系数
 }
 export interface FormState {

+ 39 - 2
src/views/information/goods/components/add/setup.ts

@@ -1,9 +1,16 @@
+import { getItemEnum } from '@/services/bus/allEnum';
+import { QueryGoodsfGroup } from '@/services/go/ermcp/goodsInfo';
+import { Ermcp3GoodsGroup } from '@/services/go/ermcp/goodsInfo/interface';
 import { addDeliveryGoodsApply } from '@/services/proto/delivery';
 import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
 import { message } from 'ant-design-vue';
 import { reactive, ref, UnwrapRef } from 'vue';
 import { FormState } from './interface';
 
+/**
+ * 处理新增
+ * @returns 
+ */
 export function handleAdd() {
     const loading = ref<boolean>(false);
     function addAction(param: DeliveryGoodsApplyReq) {
@@ -17,6 +24,10 @@ export function handleAdd() {
     return { loading, addAction }
 }
 
+/**
+ * 处理表单数据
+ * @returns 
+ */
 export function handleFromState() {
     const formState: UnwrapRef<FormState> = reactive({
         deliverygoodscode: '', // string 交割商品代码(新增时有值)
@@ -32,7 +43,7 @@ export function handleFromState() {
             { dgfactoryitemvalue: '', }
         ], //   GLDDGFactoryItemEx 现货商品品牌数据
         wrsconvertdetails: [
-            { middlegoodsid: undefined, unitid: null, convertratio: null, }
+            { middlegoodsid: undefined, unitid: null, unitidName: '', convertratio: null, }
         ], // WRSConvertDetailEx 现货商品折算配置明细数据
     });
     type Key = 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
@@ -46,7 +57,7 @@ export function handleFromState() {
         } else if (key === 'glddgfactoryItems') {
             formState[key].push({ dgfactoryitemvalue: '', })
         } else if (key === 'wrsconvertdetails') {
-            formState[key].push({ middlegoodsid: undefined, unitid: null, convertratio: null, })
+            formState[key].push({ middlegoodsid: undefined, unitid: null, unitidName: '', convertratio: null, })
         }
     }
     /**
@@ -60,3 +71,29 @@ export function handleFromState() {
     return { formState, addOne, deleteOne }
 }
 
+/**
+ * 获取期货商品组
+ * @returns 
+ */
+export function handleGoodsGroup() {
+    const goodsGroup = ref<Ermcp3GoodsGroup[]>([])
+    function getGoodsGroup() {
+        QueryGoodsfGroup().then(res => {
+            console.log('获取期货商品组', res);
+
+            goodsGroup.value = res;
+        }).catch(err => {
+            message.error(err)
+        })
+    }
+    return { goodsGroup, getGoodsGroup }
+}
+
+/**
+ * 获取合约单位
+ * @returns 
+ */
+export function getGoodsUnit(unit: number): string {
+    const obj = getItemEnum('goodsunit').find(e => e.enumitemname === unit);
+    return obj ? obj.enumdicname : '--'
+}