Explorar o código

1、优化软床报价换料逻辑

MY hai 1 mes
pai
achega
e4afaf9c7e

+ 1 - 0
JLHHJSvr/Com/Model/u_configure_codemxbom.cs

@@ -38,6 +38,7 @@ namespace JLHHJSvr.Com.Model
         public string mtrlmode { get; set; }
         public string unit { get; set; }
         public byte has_type { get; set; }
+        public int? typeid { get; set; }
         #endregion
     }
 }

+ 8 - 3
JLHHJSvr/DataStore/web_configure_codemxbomlist.xml

@@ -18,10 +18,15 @@ SELECT u_configure_codemxbom.pzid
 	,u_configure_codemxbom.default_length
 	,u_configure_codemxbom.default_width
 	,u_configure_codemxbom.default_qty
-	,u_mtrl_price.name AS mtrlname
-	,u_mtrl_price.priceunit AS unit
+	,u_mtrldef.mtrlcode
+	,u_mtrldef.mtrlname
+	,u_mtrldef.mtrlmode
+	,u_mtrldef.unit
+	,u_mtrldef.mtrlsectype
+	,u_mtrldef.zxmtrlmode
+	,u_mtrldef.usermtrlmode
 FROM u_configure_codemxbom
-INNER JOIN u_mtrl_price ON u_configure_codemxbom.mtrlid = u_mtrl_price.mtrlid
+INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid
   </selectstr>
   <where>
 	<when notnull="@pzid">

+ 128 - 74
JLHHJSvr/Helper/SoftBedHelper.cs

@@ -95,30 +95,23 @@ namespace JLHHJSvr.Helper
 			// 换料清单
 			var bomList = GetSoftBedMxBomList(codeMxList);
             // 排除不存在配置的物料
-            var skipList = new List<int>();
-            var mxMtrlIds = mxList.Select(t => t.mtrlid).ToList();
-            if (mxMtrlIds.Count > 0)
-            {
-                cmd.CommandText = $@"SELECT mtrlid FROM u_configure_codemxbom WHERE mtrlid NOT IN {ListEx.getString(mxMtrlIds)}";
-                cmd.Parameters.Clear();
-                using (var reader = cmd.ExecuteReader())
-                {
-                    while (reader.Read())
-                    {
-                        skipList.Add(Convert.ToInt32(reader["mtrlid"]));
-                    }
-                }
-            }
+            //var skipList = new List<int>();
+            //var mxMtrlIds = mxList.Select(t => t.mtrlid).ToList();
+            //if (mxMtrlIds.Count > 0)
+            //{
+            //    cmd.CommandText = $@"SELECT mtrlid FROM u_configure_codemxbom WHERE mtrlid NOT IN {ListEx.getString(mxMtrlIds)}";
+            //    cmd.Parameters.Clear();
+            //    using (var reader = cmd.ExecuteReader())
+            //    {
+            //        while (reader.Read())
+            //        {
+            //            skipList.Add(Convert.ToInt32(reader["mtrlid"]));
+            //        }
+            //    }
+            //}
 
 			foreach (var mx in mxList)
 			{
-				if(skipList.Contains(mx.mtrlid))
-				{
-					mx.printid = newList.Count + 1;
-					newList.Add(mx);
-					continue;
-				}
-
 				if (mx.pzid > 0)
 				{
 					// 部件
@@ -170,7 +163,7 @@ namespace JLHHJSvr.Helper
 						}
 					}
 
-					if (pzid > 1) throw new LJCommonException($"换料失败,原因:{contfigtypename}的{mx.mtrlname}存在多个清单,但没有部件!");
+					if (cnt > 1) throw new LJCommonException($"换料失败,原因:{contfigtypename}的{mx.mtrlname}存在多个清单,但没有部件!");
 
 					var tmp_bomList = bomList.FindAll(t => t.pzid == pzid);
                     if (tmp_bomList.Count > 0)
@@ -193,6 +186,7 @@ namespace JLHHJSvr.Helper
                 }
 			}
 
+			if (newList.Count <= 0) newList.AddRange(bomList);
 			return newList;
         }
         /// <summary>
@@ -206,8 +200,8 @@ namespace JLHHJSvr.Helper
 			foreach(var code in codeList)
 			{
 				var resultList = new List<u_configure_codemxbom>();
-				var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,cost_emp,cost_date,sonloss,sonloss_formula,
-									sondecloss,sondecloss_formula,deptid_scll,default_length,default_width,default_qty,mtrlcode,mtrlname,mtrlmode,unit,
+				var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,sonloss,sonloss_formula,
+									sondecloss,sondecloss_formula,default_length,default_width,default_qty,mtrlcode,mtrlname,mtrlmode,unit,
 									mtrlsectype,zxmtrlmode,usermtrlmode,price";
 				var selectStr = @"SELECT u_configure_codemxbom.pzid
 										,u_configure_codemxbom.printid
@@ -219,13 +213,10 @@ namespace JLHHJSvr.Helper
 										,u_configure_codemxbom.profit_rate
 										,u_configure_codemxbom.realqty
 										,u_configure_codemxbom.cost
-										,u_configure_codemxbom.cost_emp
-										,u_configure_codemxbom.cost_date
 										,u_configure_codemxbom.sonloss
 										,u_configure_codemxbom.sonloss_formula
 										,u_configure_codemxbom.sondecloss
 										,u_configure_codemxbom.sondecloss_formula
-										,u_configure_codemxbom.deptid_scll
 										,u_configure_codemxbom.default_length
 										,u_configure_codemxbom.default_width
 										,u_configure_codemxbom.default_qty
@@ -367,6 +358,54 @@ namespace JLHHJSvr.Helper
 				var _softbed = GetSoftBed(softbed.softbed_id, "softbed_id,softbed_code,version,update_emp");
 				if (_softbed.version != softbed.version) throw new LJCommonException($"单据:{_softbed.softbed_code}已被{_softbed.update_emp}修改,请重新加载最新数据再操作!");
 			}
+
+			if(softbed.softbed_id > 0 && softbed.is_template != 0)
+			{
+                // 
+				var configureList = GetSoftBedConfigureName(softbed);
+                var bomSet = new Dictionary<int,List<u_configure_codemxbom>>();
+
+				foreach(var configure in configureList)
+				{
+                    cmd.CommandText = @"SELECT u_configure_code.pzid
+											,u_configure_codemxbom.mtrlid
+											,LTRIM(RTRIM(u_configure_type.contfigtypename))
+											,u_configure_type.contfigtypeid
+										FROM u_configure_codemxbom
+										INNER JOIN u_configure_codemx ON u_configure_codemxbom.pzid = u_configure_codemx.pzid
+											AND u_configure_codemxbom.printid = u_configure_codemx.printid
+										INNER JOIN u_configure_code ON u_configure_codemx.pzid = u_configure_code.pzid
+										INNER JOIN u_configure_type ON u_configure_code.typeid = u_configure_type.contfigtypeid
+										WHERE LTRIM(RTRIM(u_configure_type.contfigtypename)) = @contfigtypename";
+                    cmd.Parameters.Clear();
+                    cmd.Parameters.AddWithValue("@contfigtypename", configure.Value.contfigtypename);
+                    using (var reader = cmd.ExecuteReader())
+                    {
+                        while (reader.Read())
+                        {
+							if (!bomSet.ContainsKey(configure.Key)) bomSet.Add(configure.Key, new List<u_configure_codemxbom>());
+
+                            bomSet[configure.Key].Add(new u_configure_codemxbom()
+							{
+								pzid = Convert.ToInt32(reader["pzid"]),
+								mtrlid = Convert.ToInt32(reader["mtrlid"]),
+								typeid = Convert.ToInt32(reader["contfigtypeid"]),
+								has_type = configure.Key
+							});
+                        }
+                    }
+                }
+                foreach (var mx in softbed.mxList)
+				{
+					if(!bomSet.TryGetValue(mx.has_type, out var bomList))
+					{
+						throw new LJCommonException($"保存失败,原因:{configureList[mx.has_type].contfigtypename}没有设置物料清单");
+					}
+					var cnt = bomList.Where(t => t.has_type == mx.has_type && t.mtrlid == mx.mtrlid).Count();
+					if (cnt > 1) throw new LJCommonException($"保存失败,原因:{configureList[mx.has_type].contfigtypename}的{mx.mtrlname}存在多个清单,但没有设置部件!");
+					else if (cnt == 0) throw new LJCommonException($"保存失败,原因:{configureList[mx.has_type].contfigtypename}的{mx.mtrlname}不存在于物料清单中,请检查!");
+                }
+            }
         }
         /// <summary>
         /// 新建软床报价模板
@@ -382,45 +421,9 @@ namespace JLHHJSvr.Helper
 			}
 
 			string prefix = $"{softbed.softbed_code}|";
-			var configureList = new List<u_configure_type>();
-			if(softbed.has_headboard == 1)
-			{
-                configureList.Add(new u_configure_type()
-				{
-					contfigtypeid = 0,
-                    contfigtypename = $"{prefix}床头",
-                    contfigtype = 0,
-                    usechflag = 1,
-					flag = 0
-                });
-			}
+			var configureList = GetSoftBedConfigureName(softbed).Values.ToList();
 
-			if(softbed.has_bedframe == 1)
-			{
-                configureList.Add(new u_configure_type()
-                {
-                    contfigtypeid = 0,
-                    contfigtypename = $"{prefix}床架",
-                    contfigtype = 0,
-                    usechflag = 1,
-                    flag = 0
-                });
-            }
-
-            if (softbed.has_nightstand == 1)
-            {
-                configureList.Add(new u_configure_type()
-                {
-                    contfigtypeid = 0,
-                    contfigtypename = $"{prefix}床头柜",
-                    contfigtype = 0,
-                    usechflag = 1,
-                    flag = 0
-                });
-            }
-
-
-			var baseInfoHelper = GetHelper<BasicInfoHelper>(cmd, context);
+            var baseInfoHelper = GetHelper<BasicInfoHelper>(cmd, context);
 			foreach(var configure in configureList)
             {
                 // 判断是否已存在
@@ -457,6 +460,53 @@ namespace JLHHJSvr.Helper
                     DbSqlHelper.Update(cmd, "u_configure_codemx", null, codeMx, "pzid,printid", "ifdft");
                 }
             }
+        }
+		/// <summary>
+		/// 返回软床报价相关配置名
+		/// </summary>
+		/// <param name="softbed"></param>
+		/// <returns></returns>
+		private Dictionary<byte, u_configure_type> GetSoftBedConfigureName(u_softbed softbed)
+		{
+			var dict = new Dictionary<byte, u_configure_type>();
+            string prefix = $"{softbed.softbed_code}|";
+            if (softbed.has_headboard == 1)
+            {
+				dict.Add(1, new u_configure_type()
+				{
+					contfigtypeid = 0,
+					contfigtypename = $"{prefix}床头",
+					contfigtype = 0,
+					usechflag = 1,
+					flag = 0
+				});
+            }
+
+            if (softbed.has_nightstand == 1)
+            {
+                dict.Add(2, new u_configure_type()
+                {
+                    contfigtypeid = 0,
+                    contfigtypename = $"{prefix}床头柜",
+                    contfigtype = 0,
+                    usechflag = 1,
+                    flag = 0
+                });
+            }
+
+            if (softbed.has_bedframe == 1)
+            {
+                dict.Add(4,new u_configure_type()
+                {
+                    contfigtypeid = 0,
+                    contfigtypename = $"{prefix}床架",
+                    contfigtype = 0,
+                    usechflag = 1,
+                    flag = 0
+                });
+            }
+
+			return dict;
         }
 		/// <summary>
 		/// 获取软床报价配置
@@ -669,15 +719,19 @@ namespace JLHHJSvr.Helper
 				// 总人力成本
 				total_hr_cost += 0;
             }
-			softbed.total_mtrl_cost = total_mtrl_cost;
-			softbed.total_hr_cost = total_hr_cost;
-			softbed.total_cost = formula.GetFormulaItem("【车间成本】").value;
-
-			softbed.nottax_factory_cost = formula.GetFormulaItem("【不含税出厂价】").value;
-			softbed.nottax_dept_cost = formula.GetFormulaItem("【部门不含税价】").value;
-			softbed.dept_cost = formula.GetFormulaItem("【部门含税价】").value;
-			softbed.taxes = formula.GetFormulaItem("【税金】").value;
-			softbed.foreign_cost = formula.GetFormulaItem("【外币价】").value;
+
+			if(softbed.mxList != null && softbed.mxList.Count > 0)
+			{
+                softbed.total_mtrl_cost = total_mtrl_cost;
+                softbed.total_hr_cost = total_hr_cost;
+                softbed.total_cost = formula.GetFormulaItem("【车间成本】").value;
+
+                softbed.nottax_factory_cost = formula.GetFormulaItem("【不含税出厂价】").value;
+                softbed.nottax_dept_cost = formula.GetFormulaItem("【部门不含税价】").value;
+                softbed.dept_cost = formula.GetFormulaItem("【部门含税价】").value;
+                softbed.taxes = formula.GetFormulaItem("【税金】").value;
+                softbed.foreign_cost = formula.GetFormulaItem("【外币价】").value;
+            }
             //formula.CalculateAll();
         }
 

+ 4 - 0
JLHWEB/src/api/interface/index.ts

@@ -1423,4 +1423,8 @@ export namespace SoftBed {
   export interface ResGetSoftBedConfigureList {
     typeList: any[];
   }
+  export interface ReqGetChangeSoftBedMxList {
+    billid: number;
+    codeList: any[];
+  }
 }

+ 7 - 0
JLHWEB/src/api/modules/quote.ts

@@ -295,3 +295,10 @@ export const GetSoftBedMxList = (params: SoftBed.ResGetSoftBedMxList) => {
 export const GetSoftBedConfigureList = (params: SoftBed.ReqSoftBed) => {
   return http.post<SoftBed.ResGetSoftBedConfigureList>(PORT1 + `/GetSoftBedConfigureList`, params);
 };
+
+/**
+ * @name 软床报价:获取软床报价部件选配清单
+ */
+export const GetChangeSoftBedMxList = (params: SoftBed.ReqGetChangeSoftBedMxList) => {
+  return http.post<SoftBed.ResSoftBed>(PORT1 + `/GetChangeSoftBedMxList`, params);
+};

+ 109 - 37
JLHWEB/src/views/quote/softbedQuote/hooks/index.tsx

@@ -1,6 +1,6 @@
 import { ref, reactive, computed, toRefs, nextTick } from "vue";
 import { ColumnProps } from "@/components/LjVxeTable/interface";
-import { GetSoftBedMxList, SaveSoftBedQuote, GetSoftBedConfigureList } from "@/api/modules/quote";
+import { GetSoftBedMxList, SaveSoftBedQuote, GetSoftBedConfigureList, GetChangeSoftBedMxList } from "@/api/modules/quote";
 import { ALLOW_EDIT_STATE } from "@/config/index";
 import { ElButton, ElMessage, ElMessageBox, ElRow, ElCol, ElNotification } from "element-plus";
 import { AuditSoftBedQuote, DeleteSoftBedQuote } from "@/api/modules/quote";
@@ -44,10 +44,6 @@ interface defaultState {
    * @description 详情页主表数据
    */
   softBed: any;
-  /**
-   * @description 详情页主表明细数据
-   */
-  softBedMx: any[];
   /**
    * @description 详情页主表明细数据-床头
    */
@@ -108,7 +104,6 @@ export const useHooks = (t?: any) => {
     VxeTableBedFrameMxRef: null,
     VxeTableNightStandMxRef: null,
     softBed: {},
-    softBedMx: [],
     headBoardMx: [],
     nightStandMx: [],
     bedFrameMx: [],
@@ -790,35 +785,36 @@ export const useHooks = (t?: any) => {
       title: "行号",
       width: 50
     },
-    {
-      field: "allow_edit",
-      title: "业务修改",
-      width: 88,
-      align: "center",
-      datatype: "checkbox",
-      editRender: {},
-      editColRender: (scope: any) => {
-        const { row } = scope;
-        const { _mainData } = state.LjDetailRef;
-        if (Number(row.allow_edit) == 0) {
-          row.allow_edit = 0;
-        }
+    // {
+    //   field: "allow_edit",
+    //   title: "业务修改",
+    //   width: 88,
+    //   align: "center",
+    //   datatype: "checkbox",
+    //   visiable: false,
+    //   editRender: {},
+    //   editColRender: (scope: any) => {
+    //     const { row } = scope;
+    //     const { _mainData } = state.LjDetailRef;
+    //     if (Number(row.allow_edit) == 0) {
+    //       row.allow_edit = 0;
+    //     }
 
-        const _disabled = !row.allow_edit && !_mainData.is_template;
+    //     const _disabled = !row.allow_edit && !_mainData.is_template;
 
-        return (
-          <>
-            <el-checkbox
-              v-model={row.allow_edit}
-              true-value={1}
-              false-value={0}
-              class="vxe-edit-col-middle"
-              disabled={_disabled}
-            ></el-checkbox>
-          </>
-        );
-      }
-    },
+    //     return (
+    //       <>
+    //         <el-checkbox
+    //           v-model={row.allow_edit}
+    //           true-value={1}
+    //           false-value={0}
+    //           class="vxe-edit-col-middle"
+    //           disabled={_disabled}
+    //         ></el-checkbox>
+    //       </>
+    //     );
+    //   }
+    // },
     {
       field: "pzname",
       title: "部件选配项",
@@ -1051,7 +1047,6 @@ export const useHooks = (t?: any) => {
     }
     //
     state.softBed = [result.softbed];
-    state.softBedMx = result.mxList;
     state.headBoardMx = result.mxList.filter(item => item.has_type === 1);
     state.nightStandMx = result.mxList.filter(item => item.has_type === 2);
     state.bedFrameMx = result.mxList.filter(item => item.has_type === 4);
@@ -1061,6 +1056,7 @@ export const useHooks = (t?: any) => {
    */
   const onOpenConfigureDialog = async () => {
     const { _mainData } = state.LjDetailRef;
+
     const result = await GetSoftBedConfigureList({ softbed: _mainData });
 
     state.nightstandConfigOptions = [];
@@ -1086,6 +1082,12 @@ export const useHooks = (t?: any) => {
       state.isModalVisible = true;
     });
   };
+  /**
+   *
+   * @param item
+   * @param targetOption
+   * @param targetConfig
+   */
   const handleConfigItem = (item: any, targetOption: any[], targetConfig: any[]) => {
     if (item.codeList?.length > 0) {
       for (const code of item.codeList) {
@@ -1114,10 +1116,9 @@ export const useHooks = (t?: any) => {
    * 确认部件配置项值
    * @param params 返回内容
    */
-  const onConfirmConfigureDialog = (params: any) => {
+  const onConfirmConfigureDialog = async (params: any) => {
     const { _mainData } = state.LjDetailRef;
 
-    console.log("partsConfig :>>> ", state.partsConfig);
     nextTick(() => {
       _mainData.has_headboard = Number(state.showHeadboard);
       _mainData.has_nightstand = Number(state.showNightstand);
@@ -1125,6 +1126,78 @@ export const useHooks = (t?: any) => {
 
       state.isModalVisible = false;
     });
+
+    const _codeMxList = [];
+    if (_mainData.has_headboard) {
+      _codeMxList.push(
+        ...state.partsConfig.headboard.map(t => {
+          return { pzid: t.pzid, printid: t.selectedId, has_type: 1 };
+        })
+      );
+    }
+    if (_mainData.has_nightstand) {
+      _codeMxList.push(
+        ...state.partsConfig.nightstand.map(t => {
+          return { pzid: t.pzid, printid: t.selectedId, has_type: 2 };
+        })
+      );
+    }
+    if (_mainData.has_bedframe) {
+      _codeMxList.push(
+        ...state.partsConfig.bedframe.map(t => {
+          return { pzid: t.pzid, printid: t.selectedId, has_type: 4 };
+        })
+      );
+    }
+
+    const billid = _mainData.template_id > 0 ? Number(_mainData.template_id) : Number(_mainData.softbed_id);
+    const result = await GetChangeSoftBedMxList({ billid, codeList: _codeMxList });
+    const copyMap = new Map();
+    const { fullData: headboard_table } = state.VxeTableHeadBoardMxRef?.element.getTableData();
+    const { fullData: nightstand_table } = state.VxeTableNightStandMxRef?.element.getTableData();
+    const { fullData: bedframe_table } = state.VxeTableBedFrameMxRef?.element.getTableData();
+    headboard_table?.forEach(mx => {
+      copyMap.set(`${mx.has_type}|${mx.pzid}|${mx.mtrlid}`, mx);
+    });
+    nightstand_table?.forEach(mx => {
+      copyMap.set(`${mx.has_type}|${mx.pzid}|${mx.mtrlid}`, mx);
+    });
+    bedframe_table?.forEach(mx => {
+      copyMap.set(`${mx.has_type}|${mx.pzid}|${mx.mtrlid}`, mx);
+    });
+
+    const newHeadBoardMx = [];
+    const newNightStandMx = [];
+    const newBedFrameMx = [];
+    result.mxList.forEach(mx => {
+      const key = `${mx.has_type}|${mx.pzid}|${mx.mtrlid}`;
+      if (copyMap.has(key)) {
+        // matchQty++;
+        const mx2 = copyMap.get(key);
+        mx = mx2;
+        // mx.haschange = 1;
+      }
+
+      if (mx.has_type === 1) newHeadBoardMx.push(mx);
+      else if (mx.has_type === 2) newNightStandMx.push(mx);
+      else if (mx.has_type === 4) newBedFrameMx.push(mx);
+    });
+
+    state.headBoardMx = newHeadBoardMx;
+    state.nightStandMx = newNightStandMx;
+    state.bedFrameMx = newBedFrameMx;
+
+    if (result.mxList.length > 0) {
+      ElNotification({
+        title: "导入成功",
+        type: "success"
+      });
+    } else {
+      ElNotification({
+        title: "导入失败",
+        type: "warning"
+      });
+    }
   };
   /**
    * 保存报价
@@ -1396,7 +1469,6 @@ export const useHooks = (t?: any) => {
       data[key] = result.softbed[key];
     }
     //
-    state.softBedMx = result.mxList;
     state.headBoardMx = result.mxList.filter(item => item.has_type === 1);
     state.nightStandMx = result.mxList.filter(item => item.has_type === 2);
     state.bedFrameMx = result.mxList.filter(item => item.has_type === 4);