/* * @Author: mzr * @PageInfo: 供应商价目表批量粘贴编辑事件 * @Date: 2025-06-20 * @Last Modified by: mzr * @Last Modified time: 2025-06-20 */ import {ajax, base} from 'nc-lightapp-front'; import { createGridAfterEventDataBatch4Excel, processGridEditResultBatchByCard } from '../../../../../scmpub/scmpub/pub/tool/afterEditUtil'; import {URL, AREA, PAGECODE, PAGEID} from "../../constance"; import {RownoUtils} from "../../../../../scmpub/scmpub/pub/tool/editTableTools"; import {dateFormat} from "../../../../public"; import {getLangByResId} from "../../../../../scmpub/scmpub/pub/tool/multiLangUtil"; const BATCHITEM = [ 'pk_supplier_v', // 供应商 'pk_supplier', // 供应商 'pk_org', // 组织 'pk_org_v', // 组织 'pk_material', // 物料 'pk_bizpsn', // 采购员 'pk_dept', // 采购部门 'corigcurrencyid', // 币种 'ftaxtypeflag', // 扣税类别 'vchangerate', // 换算率 'castunitid', // 单位 'ntaxrate', // 税率 'nastorigtaxprice', // 含税单价 'nastorigprice', // 无税单价 'dvaliddate', // 价格生效日期 'dinvaliddate', // 价格失效日期 'fpricesrctype', // 价格来源 'vbdef15', // 招标项目号 'vbdef16', // 比例 'vbdef17' // 备注 ]; export default async function batchEvents(obj) { // console.log('batchEvents-obj = ', obj); // console.log('batchEvents-obj-record = ', obj.record); let areaCode = obj.areaCode; //区域编码 let column = obj.column; //列信息 let newValue = obj.newValue; //变更的行信息 let queryValue = []; let changedrows = obj.changedrows; //变更的信息,仅包含newValue和OldValue let currentIndex = obj.currentIndex; //当前行 let indexs = []; let rows = []; let attrcode = column.attrcode; //列code let queryCondition; //统一过滤的过滤条件 let isManyCondition = null; //是否多个过滤条件 let pasteData = obj.pasteData; //粘贴的值 // 不在 BATCHITEM 里面的列,直接返回 if (!BATCHITEM.includes(attrcode) && !attrcode.startsWith('vbdef')) { return; } if (attrcode == 'pk_material') { // 物料 } else if (attrcode == 'corigcurrencyid') { // 币种 } else if (attrcode == 'pk_org') { // 采购组织 } else if (attrcode == 'ntaxrate') { // 税率 } for (let i = 0; i < newValue.length; i++) { queryValue.push(newValue[i]); indexs[i] = currentIndex + i; // rows[i] = [i]; } this.props.cardTable .updateAfterBatchChange({ areaCode, //区域code column, //对应的列,可直接使用上面获取到的column对象 indexs, //满足并需要处理的行(可能存在第一行允许编辑,第二行不允许编辑的场景,所以indexs数组中的行数并不一定与粘贴的行数相等)) queryValue, //与indexs对应的行数据数组(包含前过滤条件) changedrows, //变更行的数组(仅有newValue与oldValue) pasteData, //粘贴的具体内容,对于参照类型的列,此字段必传,不然无法翻译 queryCondition, //该列统一的前过滤条件,比如物料都是根据表头主组织进行过滤 isManyCondition //是否多个过滤条件,如物料都根据表头主组织进行过滤,此参数传false,如表体的部门根据表体的某个组织过滤,此参数传true }) .then((res) => { let props = res.props; changedrows = res.changedrows; indexs = res.indexs || []; // console.log('batchEvents-res:', res); // console.log('batchEvents-indexs:', indexs); //执行业务的批量编辑后事件 batchUpdateData(props, areaCode, attrcode, changedrows, indexs, queryValue); /* for (let i = 0; i < changedrows.length; i++) { // let changedrow = changedrows[i]; // console.log('batchEvents-changedrow = ', changedrow); postEvent(props, areaCode, attrcode, null, changedrows, null, i); } */ }); } // 批量编辑后事件 function batchUpdateData(props, areaCode, attrcode, changedrows, indexs, queryValue) { /*let rows = props.editTable.getAllRows(areaCode, false); if (changedrows.length > rows.length) { let num = changedrows.length - rows.length; for (let i = 0; i < num; i++) { let _this = this; addRow1(props, _this); } }*/ let data = createGridAfterEventDataBatch4Excel(props, PAGECODE.listPagecode, AREA.listTable,//区域编码 areaCode, attrcode, changedrows, indexs, null, queryValue, ''); console.log('data = ', data); ajax({ url: URL.afterEdit, data: data, async: false, success: (res) => { if (res && res.data && res.data.listTable) { let dataRows = res.data[AREA.listTable].rows; console.log('dataRows = ', dataRows); processResultBatchByCard(props, AREA.listTable, dataRows, indexs) } // props.editTable.setStatus(AREA.listTable, 'edit'); } }); } function processResultBatchByCard(props, moduleId, rows, indexs) { // debugger; if (rows && rows.length > 0) { let insertArray = []; let updateArray = []; let allRows = props.editTable.getAllRows(moduleId); let i = allRows.length; for (let j = 0; j < rows.length; j++) { let row = rows[j]; let obj = {index: indexs[j], data: row}; if (indexs[j] < i) { updateArray.push(obj); } else { insertArray.push(obj); } } if (updateArray.length > 0) { props.editTable.updateDataByIndexs(moduleId, updateArray); if (insertArray.length > 0) { let updateRow = updateArray[0].data; for (let i = 0; i < insertArray.length; i++) { let row = insertArray[i].data; row.values.norigtaxprice = updateRow.values.norigtaxprice; row.values.ftaxtypeflag = updateRow.values.ftaxtypeflag; row.values.bsc = updateRow.values.bsc; row.values.bsc = updateRow.values.bsc; row.values.ntransportmny = updateRow.values.ntransportmny; row.values.dvaliddate = updateRow.values.dvaliddate; row.values.corigcurrencyid = updateRow.values.corigcurrencyid; row.values.bcanorder = updateRow.values.bcanorder; row.values.tcreatetime = updateRow.values.tcreatetime; row.values.pk_org = updateRow.values.pk_org; row.values.pk_org_v = updateRow.values.pk_org_v; row.values.ninsurance = updateRow.values.ninsurance; row.values.fpricesrctype = updateRow.values.fpricesrctype; row.values.nastorigtaxprice = updateRow.values.nastorigtaxprice; row.values.norigprice = updateRow.values.norigprice; // row.crowno = updateRow.values.crowno; row.values.nastorigprice = updateRow.values.nastorigprice; row.values.nimpost = updateRow.values.nimpost; row.values.ntaxrate = updateRow.values.ntaxrate; //税率 } } } if (insertArray.length > 0) { props.editTable.insertDataByIndexs(moduleId, insertArray, true); } } } // 单个编辑后事件 function postEvent(props, moduleId, key, value, changedrows, record, index) { let changedrow = changedrows[index]; let event = props.createGridAfterEventData(PAGEID, AREA.listTable, moduleId, key, changedrows); console.log('rows1 = ', event.grid[AREA.listTable].rows); /* event.grid[AREA.listTable].rows = event.grid[AREA.listTable].rows.filter((row) => { return row.rowid == changedrow.rowid; }); */ event.grid[AREA.listTable].rows = [changedrow]; event.changedrows = [changedrow]; console.log('event = ', event); ajax({ method: 'POST', url: URL.afterEdit, data: event, async: false, success: (res) => { if (res && res.data && res.data.listTable) { if (index == 0) { props.editTable.updateDataByIndexs(AREA.listTable, [{ index: index, data: res.data[AREA.listTable].rows[0] }]); } else if (index > 0) { props.editTable.insertDataByIndexs(AREA.listTable, [{ index: index, data: res.data[AREA.listTable].rows[0] }]); } } props.editTable.setStatus(AREA.listTable, 'edit'); } }); } function batchUpdateData1(props, areaCode, attrcode, changedrows, indexs, queryValue) { let data = createGridAfterEventDataBatch4Excel(props, PAGECODE.listPagecode, AREA.listTable,//区域编码 areaCode, attrcode, changedrows, indexs, null, queryValue, ''); // console.log('data = ', data); let rows = data.grid[AREA.listTable].rows; for (let i = 0; i < rows.length; i++) { let row = rows[i]; let data1 = data; data1.grid[AREA.listTable].rows = [row]; data1.changedrows = changedrows.filter((changedrow) => { return changedrow.rowid == row.rowid; }); ajax({ url: URL.afterEdit, data: data1, async: false, success: (res) => { if (res && res.data && res.data.listTable) { let dataRows = res.data[AREA.listTable].rows; console.log('dataRows = ', dataRows); // processGridEditResultBatchByCard(props, AREA.listTable, dataRows, indexs) if (i == 0) { props.editTable.updateDataByIndexs(AREA.listTable, [{ index: i, data: dataRows[0] }]); } else if (i > 0) { props.editTable.insertDataByIndexs(AREA.listTable, [{ index: i, data: dataRows[0] }]); } } // props.editTable.setStatus(AREA.listTable, 'edit'); } }); } } function addRow1(props, _this) { let row = props.editTable.getNumberOfRows(AREA.listTable); props.editTable.addRow(AREA.listTable, undefined, true); RownoUtils.setRowNoByIndex(props, AREA.listTable, 'crowno', row); let defaultKey = ['pk_org', 'pk_org_v', 'pk_group', 'corigcurrencyid', 'tcreatetime']; /* defaultKey.forEach((key) => { props.editTable.setValByKeyAndIndex(AREA.listTable, row, key, props.state.defaultVO.values[key]); });*/ //设置自制 生效时间 生成时间 dateFormat(); let time = new Date(); props.editTable.setValByKeyAndIndex(AREA.listTable, row, 'dvaliddate', { value: time.Format('yyyy-MM-dd') + ' 00:00:00', display: time.Format('yyyy-MM-dd') }); props.editTable.setValByKeyAndIndex(AREA.listTable, row, 'tcreatetime', { value: time.Format('yyyy-MM-dd hh:mm:ss'), display: time.Format('yyyy-MM-dd') }); props.editTable.setValByKeyAndIndex(AREA.listTable, row, 'ftaxtypeflag', { value: '1', display: getLangByResId(props, '4005SUPPLIERPRICE-000007') }); /* 国际化处理: 应税外加*/ props.editTable.setValByKeyAndIndex(AREA.listTable, row, 'fpricesrctype', { value: '3', display: getLangByResId(props, '4005SUPPLIERPRICE-000008') }); /* 国际化处理: 自制*/ }