Pārlūkot izejas kodu

修改商品信息

huangbin 4 gadi atpakaļ
vecāks
revīzija
97fb9ecc37

+ 162 - 32
src/views/information/goods/components/add/index.vue

@@ -98,7 +98,7 @@
           <template v-for="(domain, index) in formState.gldwrstandards"
                     :key="domain.index + 'domain'">
             <a-col :span="6">
-              <a-form-item :name="['wrstandardname', index]"
+              <a-form-item :name="['gldwrstandards',index, 'wrstandardname', ]"
                            :rules="rules.gldwrstandards.wrstandardname">
                 <a-input class="dialogInput"
                          v-model:value="domain.wrstandardname"
@@ -106,7 +106,7 @@
               </a-form-item>
             </a-col>
             <a-col :span="6">
-              <a-form-item :name="['unitid', index]"
+              <a-form-item :name="['gldwrstandards',index,'unitid' ]"
                            :rules="rules.gldwrstandards.unitid">
                 <a-select class="inlineFormSelect"
                           style="width: 200px"
@@ -121,21 +121,24 @@
               </a-form-item>
             </a-col>
             <a-col :span="6">
-              <a-form-item :name="['convertfactor', index]"
+              <a-form-item :name="['gldwrstandards',index,'convertfactor']"
                            :rules="rules.gldwrstandards.convertfactor">
                 <a-input class="dialogInput"
                          v-model:value="domain.convertfactor"
+                         type="number"
                          placeholder="请输入标仓系数"></a-input>
               </a-form-item>
             </a-col>
             <a-col :span="6">
               <a-button class="plusBtn"
+                        @click="deleteOne('gldwrstandards', index)"
                         v-if="index > 0">
                 <template #icon>
                   <MinusOutlined />
                 </template>
               </a-button>
-              <a-button class="minusBtn">
+              <a-button class="minusBtn"
+                        @click="addOne('gldwrstandards')">
                 <template #icon>
                   <PlusOutlined />
                 </template>
@@ -143,20 +146,7 @@
             </a-col>
           </template>
         </a-row>
-        <!-- <a-form-item
-      v-for="(domain, index) in dynamicValidateForm.gldwrstandards"
-      :key="domain.index + 'domain'"
-      v-bind="index === 0 ? formItemLayout : {}"
-      :name="['domains', index, 'value']"
-      :rules="{
-        required: true,
-        message: 'domain can not be null',
-        trigger: 'change',
-      }"
-    >
-
-            </a-form-item> -->
-        <a-table class="dialogTable"
+        <!-- <a-table class="dialogTable"
                  :columns="columns"
                  :data-source="dataSource"
                  :pagination="false">
@@ -209,11 +199,50 @@
               </template>
             </a-button>
           </template>
-        </a-table>
+        </a-table> -->
       </fieldset>
       <fieldset class="formFieldSet">
         <legend>品牌信息</legend>
-        <a-table class="dialogTable"
+        <a-row :gutter="24">
+          <a-col :span="12">
+            <span>
+              <span class="red">*</span>
+              品牌
+            </span>
+          </a-col>
+          <a-col :span="12">
+            <span>
+              操作
+            </span>
+          </a-col>
+          <template v-for="(domain, index) in formState.glddgfactoryItems"
+                    :key="domain.index + 'domain'">
+            <a-col :span="12">
+              <a-form-item :name="['glddgfactoryItems',index,'dgfactoryitemvalue']"
+                           :rules="rules.glddgfactoryItems.dgfactoryitemvalue">
+                <a-input class="dialogInput"
+                         v-model:value="domain.dgfactoryitemvalue"
+                         placeholder="请输入品牌"></a-input>
+              </a-form-item>
+            </a-col>
+            <a-col :span="12">
+              <a-button class="plusBtn"
+                        @click="deleteOne('glddgfactoryItems', index)"
+                        v-if="index > 0">
+                <template #icon>
+                  <MinusOutlined />
+                </template>
+              </a-button>
+              <a-button class="minusBtn"
+                        @click="addOne('glddgfactoryItems')">
+                <template #icon>
+                  <PlusOutlined />
+                </template>
+              </a-button>
+            </a-col>
+          </template>
+        </a-row>
+        <!-- <a-table class="dialogTable"
                  :columns="columns1"
                  :data-source="dataSource1"
                  :pagination="false">
@@ -239,11 +268,86 @@
               </template>
             </a-button>
           </template>
-        </a-table>
+        </a-table> -->
       </fieldset>
       <fieldset class="formFieldSet">
         <legend>套保品种信息</legend>
-        <a-table class="dialogTable"
+        <a-row :gutter="24">
+          <a-col :span="6">
+            <span>
+              <span class="red">*</span>
+              套保品种
+            </span>
+          </a-col>
+          <a-col :span="6">
+            <span>
+              <span class="red">*</span>
+              单位
+            </span>
+          </a-col>
+          <a-col :span="6">
+            <span>
+              <span class="red">*</span>
+              套保系数
+            </span>
+          </a-col>
+          <a-col :span="6">
+            <span>
+              操作
+            </span>
+          </a-col>
+          <template v-for="(domain, index) in formState.wrsconvertdetails"
+                    :key="domain.index + 'domain'">
+            <a-col :span="6">
+              <a-form-item :name="['wrsconvertdetails',index,'middlegoodsid']"
+                           :rules="rules.wrsconvertdetails.middlegoodsid">
+                <a-select class="inlineFormSelect"
+                          style="width: 200px"
+                          v-model:value="domain.middlegoodsid"
+                          placeholder="请选择品类">
+                  <a-select-option v-for="item in unitList"
+                                   :value="item.enumitemname"
+                                   :key="item.autoid">
+                    {{item.enumdicname}}
+                  </a-select-option>
+                </a-select>
+              </a-form-item>
+            </a-col>
+            <a-col :span="6">
+              <a-form-item :name="['wrsconvertdetails', index, 'unitid']">
+                <a-input class="dialogInput"
+                         readonly
+                         v-model:value="domain.unitid"
+                         placeholder="选择套保品种后自动填入"></a-input>
+              </a-form-item>
+            </a-col>
+            <a-col :span="6">
+              <a-form-item :name="['wrsconvertdetails', index, 'convertratio']"
+                           :rules="rules.wrsconvertdetails.convertratio">
+                <a-input class="dialogInput"
+                         v-model:value="domain.convertratio"
+                         type="number"
+                         placeholder="请输入套保系数"></a-input>
+              </a-form-item>
+            </a-col>
+            <a-col :span="6">
+              <a-button class="plusBtn"
+                        @click="deleteOne('wrsconvertdetails', index)"
+                        v-if="index > 0">
+                <template #icon>
+                  <MinusOutlined />
+                </template>
+              </a-button>
+              <a-button class="minusBtn"
+                        @click="addOne('wrsconvertdetails')">
+                <template #icon>
+                  <PlusOutlined />
+                </template>
+              </a-button>
+            </a-col>
+          </template>
+        </a-row>
+        <!-- <a-table class="dialogTable"
                  :columns="columns"
                  :data-source="dataSource"
                  :pagination="false">
@@ -294,7 +398,7 @@
               </template>
             </a-button>
           </template>
-        </a-table>
+        </a-table> -->
       </fieldset>
     </a-form>
   </a-modal>
@@ -305,20 +409,28 @@ import { defineComponent, ref, reactive, toRaw, UnwrapRef } 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, initFormState } from './setup';
+import { handleAdd, handleFromState } from './setup';
 import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
 import { getGoodsUnitList } from '../../setup';
 import { RuleObject, ValidateErrorEntity } from 'ant-design-vue/es/form/interface';
 import { FormState } from './interface';
 
-const validateUnit = async (rule: RuleObject, value: number) => {
+const validateCommon = (value: any, errInfo: string) => {
     if (value) {
         return Promise.resolve();
     } else {
-        return Promise.reject('请选择单位');
+        return Promise.reject(errInfo);
     }
 };
 
+const validateUnit = async (rule: RuleObject, value: number) => {
+    return validateCommon(value, '请选择单位');
+};
+
+const valideteWR = async (rule: RuleObject, value: number) => {
+    return validateCommon(value, '请选择品类');
+};
+
 export default defineComponent({
     name: 'addSpotVariety',
     components: {
@@ -412,16 +524,25 @@ export default defineComponent({
             },
         ];
         function submit() {
-            loading.value = true;
-            setTimeout(() => {
-                loading.value = false;
-                cancel();
-            }, 2000);
+            formRef.value
+                .validate()
+                .then(() => {
+                    const param = toRaw(formState);
+                    console.log('param', param);
+                })
+                .catch((error: ValidateErrorEntity<FormState>) => {
+                    console.log('error', error);
+                });
+            // loading.value = true;
+            // setTimeout(() => {
+            //     loading.value = false;
+            //     cancel();
+            // }, 2000);
         }
 
         // 表单
         const formRef = ref();
-        const formState: UnwrapRef<FormState> = reactive(initFormState(() => {}));
+        const { formState, addOne, deleteOne } = handleFromState();
         const rules = {
             deliverygoodsname: [{ required: true, message: '请输入现货品种名称', trigger: 'blur' }],
             // unitid: [{ required: true, message: '请选择单位', trigger: 'change' }],
@@ -431,6 +552,13 @@ export default defineComponent({
                 wrstandardname: { required: true, message: '请输入品类', trigger: 'blur' },
                 convertfactor: { required: true, message: '请输入标仓系数', trigger: 'blur' },
             },
+            glddgfactoryItems: {
+                dgfactoryitemvalue: { required: true, message: '请输入品牌', trigger: 'blur' },
+            },
+            wrsconvertdetails: {
+                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' }],
         };
@@ -441,6 +569,8 @@ export default defineComponent({
             cancel,
             formRef,
             formState,
+            addOne,
+            deleteOne,
             rules,
             unitList,
 

+ 4 - 7
src/views/information/goods/components/add/interface.ts

@@ -2,23 +2,20 @@ export interface GLDWRStandardEx {
     wrstandardid?: number // uint64 型号ID(修改时有值)
     wrstandardname: string // string 型号名称
     unitid: number | undefined// uint64 单位ID
-    convertfactor: number// double 标仓系数(接口为3.1及以上版本时传)
-    callback?: Function;
+    convertfactor: number | null// double 标仓系数(接口为3.1及以上版本时传)
 }
 
 // 现货商品品牌数据 0 29 173
 export interface GLDDGFactoryItemEx {
     dgfactoryitemid?: number // uint64 品牌ID(修改时有值)
     dgfactoryitemvalue: string // string 品牌名称
-    callback?: Function;
 }
 
 // 现货商品折算配置明细数据 0 29 127
 export interface WRSConvertDetailEx {
-    middlegoodsid: number // uint64 套保品种ID(接口为3.1及以下版本时传套保品种ID,否则传期货品种ID)
-    unitid: number // uint64 单位ID
-    convertratio: number // double 套保系数
-    callback?: Function;
+    middlegoodsid: number | undefined // uint64 套保品种ID(接口为3.1及以下版本时传套保品种ID,否则传期货品种ID)
+    unitid: number | null// uint64 单位ID
+    convertratio: number | null// double 套保系数
 }
 export interface FormState {
     deliverygoodscode?: string // string 交割商品代码(新增时有值)

+ 35 - 7
src/views/information/goods/components/add/setup.ts

@@ -1,7 +1,7 @@
 import { addDeliveryGoodsApply } from '@/services/proto/delivery';
 import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
 import { message } from 'ant-design-vue';
-import { ref } from 'vue';
+import { reactive, ref, UnwrapRef } from 'vue';
 import { FormState } from './interface';
 
 export function handleAdd() {
@@ -17,8 +17,8 @@ export function handleAdd() {
     return { loading, addAction }
 }
 
-export function initFormState(callback: Function): FormState {
-    return {
+export function handleFromState() {
+    const formState: UnwrapRef<FormState> = reactive({
         deliverygoodscode: '', // string 交割商品代码(新增时有值)
         deliverygoodsname: '', // string 交割商品名称(新增时有值)
         deliverygoodsid: 0,// uint64 交割商品id(修改时有值)
@@ -26,9 +26,37 @@ export function initFormState(callback: Function): FormState {
         type: 1,// int32 类型 1 新增 2 修改
         remark: '', // string 备注
         gldwrstandards: [
-            { wrstandardname: '', unitid: undefined, convertfactor: 0, callback }
+            { wrstandardname: '', unitid: undefined, convertfactor: null, }
         ], //        GLDWRStandardEx 现货商品型号数据
-        glddgfactoryItems: [], //   GLDDGFactoryItemEx 现货商品品牌数据
-        wrsconvertdetails: [], // WRSConvertDetailEx 现货商品折算配置明细数据
+        glddgfactoryItems: [
+            { dgfactoryitemvalue: '', }
+        ], //   GLDDGFactoryItemEx 现货商品品牌数据
+        wrsconvertdetails: [
+            { middlegoodsid: undefined, unitid: null, convertratio: null, }
+        ], // WRSConvertDetailEx 现货商品折算配置明细数据
+    });
+    type Key = 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
+    /**
+     *  向动态表单里添加一条数据
+     * @param key 'gldwrstandards' | 'glddgfactoryItems' | 'wrsconvertdetails'
+     */
+    function addOne(key: Key): void {
+        if (key === 'gldwrstandards') {
+            formState[key].push({ wrstandardname: '', unitid: undefined, convertfactor: null })
+        } else if (key === 'glddgfactoryItems') {
+            formState[key].push({ dgfactoryitemvalue: '', })
+        } else if (key === 'wrsconvertdetails') {
+            formState[key].push({ middlegoodsid: undefined, unitid: null, convertratio: null, })
+        }
     }
-}
+    /**
+     * 删除动态表单一条数据
+     * @param key 
+     * @param i 
+     */
+    function deleteOne(key: Key, i: number): void {
+        formState[key].splice(i, 1)
+    }
+    return { formState, addOne, deleteOne }
+}
+