This commit is contained in:
jiashuai 2025-09-17 10:17:53 +08:00
parent 88372b072f
commit 346e1142fe
7 changed files with 485 additions and 0 deletions

View File

@ -0,0 +1,269 @@
import { ajax, toast, base } from 'nc-lightapp-front';
let { NCModal, NCButton, NCTooltip, NCHotKeys } = base;
import { AREA, URL, DIALOGCODE, FIELD, PAGECARDCODE } from '../../constance';
import { initLang, getLangByResId } from '../../../../../mmpub/mmpub/pub/tool/multiLangUtil';
import PickmReplaceDlg from '../../pickmreplace/list';
import { RownoUtils } from '../../../../../mmpub/mmpub/pub/tool/cardTableTools';
import { buttonController } from '../viewController/index';
import { showSuccessInfo, showErrorInfo, showWarningInfo, showWarningDialog } from '../../../../../mmpub/mmpub/pub/tool/messageUtil';
const TABLE_HEAD = 'replace_head';
const TABLE_BODY = 'replace_body'
export default function replaceBtnClick(props, data) {
let _this = this;
this.headDatas = [];
this.bodyDatas = {};
let setHeadDatas = (val) => {
this.headDatas = val;
};
let setBodyDatas = (val) => {
this.bodyDatas = val;
};
let getBodyDatas = () => {
return this.bodyDatas;
}
this.replaceProps = {};
let setReplaceProps = (val) => {
this.replaceProps = val;
}
ajax({
url: URL.replaceQueryURL,
data: data,
success: res => {
if (res.success && res.data) {
props.modal.show('ReplaceDlg', {
size: 'xlg',
title: getLangByResId(this, '5008Pickm-000093'),/* 国际化处理: 替代*/
content: <PickmReplaceDlg showdata={res.data} setHeadDatas={setHeadDatas} setBodyDatas={setBodyDatas} getBodyDatas={getBodyDatas} setReplaceProps={setReplaceProps} />,
userControl: true,
leftBtnName: '',
rightBtnName: getLangByResId(this, '5008Pickm-000013'),/* 国际化处理: 取消*/
beSureBtnClick: replaceOKBtnClicks.bind(this, props, true),
cancelBtnClick: () => {
props.modal.close('ReplaceDlg');
},
showCustomBtns: true,
customBtns: <div><NCButton fieldid="autoMatch" onClick={() => { autoMatchBtnClick.call(this, props) }}>{getLangByResId(this, '5008Pickm-000103')}</NCButton>
<NCTooltip
placement="top"
inverse
overlay={`${getLangByResId(this, '5008Pickm-000102')} (${NCHotKeys.USUAL_KEYS.NC_MODAL_CONFIRM})`}
trigger={['hover', 'focus']}
className="model-helper-overlay"
>
<NCButton fieldid="confirm" colors="primary" onClick={() => {
replaceOKBtnClicks.call(this, props, true);
}}>{getLangByResId(this, '5008Pickm-000102')}(<u>Y</u>)</NCButton>{/* */}
</NCTooltip>
<NCTooltip
placement="top"
inverse
overlay={`${getLangByResId(this, '5008Pickm-000013')} (${NCHotKeys.USUAL_KEYS.NC_MODAL_CALCEL})`}
trigger={['focus', 'hover']}
className="model-helper-overlay"
>
<NCButton fieldid="cancel" onClick={() => {
props.modal.close('ReplaceDlg');
}}>{getLangByResId(this, '5008Pickm-000013')}(<u>N</u>)</NCButton>{/* */}
</NCTooltip></div>,
hideRightBtn: false, //隐藏足部右边的按钮默认是false不隐藏隐藏是true
hideLeftBtn: false //隐藏足部左边的按钮默认是false不隐藏隐藏是true
});
}
}
});
}
function autoMatchBtnClick(props) {
let repBodys = {};
let repHeads = this.replaceProps.editTable.getAllRows('replace_head');
let pickmbid;
let headbid = repHeads[0].values.cpickm_bid.value;
let bodys = [];
repHeads.forEach((head) => {
pickmbid = head.values.cpickm_bid.value;
if (this.bodyDatas && this.bodyDatas[pickmbid]) {
bodys = [];
this.bodyDatas[pickmbid].forEach((item) => {
bodys.push(item);
});
if (bodys.length > 0) {
repBodys[pickmbid] = JSON.stringify({
pageid: DIALOGCODE.REPLACEDLG,
model: {
areaType: "table",
pageinfo: null,
rows: bodys,
areacode: 'replace_body'
}
});
}
}
});
let param = {
pageid: PAGECARDCODE,
repHeads: JSON.stringify({
pageid: DIALOGCODE.REPLACEDLG,
model: {
areaType: "table",
pageinfo: null,
rows: repHeads,
areacode: 'replace_head',
}
}),
repBodys: repBodys
}
ajax({
url: URL.replaceAutoMatchURL,
data: param,
success: res => {
if (res.success && res.data) {
this.bodyDatas = res.data.body;
this.replaceProps.setBodyDatas(res.data.body)
this.replaceProps.setHeadDatas( res.data.head[TABLE_HEAD]);
this.replaceProps.editTable.setTableData(TABLE_HEAD, { rows: res.data.head[TABLE_HEAD].rows });
let bodys = [];
if (res.data.body[headbid]) {
bodys = res.data.body[headbid]
}
this.replaceProps.editTable.setTableData(TABLE_BODY, { rows: bodys });
if (res.data.msg) {
showWarningInfo(res.data.msg);
}
else{
showSuccessInfo(getLangByResId(this, '5008Pickm-000104'));
}
}
},
error: (error) => {
toast({
color: 'warning',
content: error.message
});
}
});
}
function replaceOKBtnClicks(props, flag) {
let repHeads = [];
let repBodys = {};
let bodys = [];
let mainIds = [];
let heads = this.replaceProps.editTable.getAllRows('replace_head');
if (heads) {
let pickmbid;
heads.forEach((head) => {
pickmbid = head.values.cpickm_bid.value;
if (this.bodyDatas && this.bodyDatas[pickmbid]) {
bodys = [];
this.bodyDatas[pickmbid].forEach((item) => {
if (item.values.rep_repnum && item.values.rep_repnum.value && item.values.rep_repnum.value > 0) {
bodys.push(item);
}
});
if (bodys.length > 0) {
mainIds.push(pickmbid);
repHeads.push(head);
repBodys[pickmbid] = JSON.stringify({
pageid: DIALOGCODE.REPLACEDLG,
model: {
areaType: "table",
pageinfo: null,
rows: bodys,
areacode: 'replace_body'
}
});
}
}
});
}
if (repHeads.length < 1) {
props.modal.close('ReplaceDlg');
return;
}
let bodyData = props.cardTable.getAllRows(AREA.bodyTable);
let oldReplaces=[];
let rownos=[];
bodyData.map((item, i) => {
if(item.values.vrowno && item.values.vrowno.value){
rownos.push(item.values.vrowno.value);
}
if (item.values.creplacesrcid && item.values.creplacesrcid.value && mainIds.includes(item.values.creplacesrcid.value)) {
oldReplaces.push(item);
}
});
let param = {
pageid: PAGECARDCODE,
isCheckAtp: flag,
repHeads: JSON.stringify({
pageid: DIALOGCODE.REPLACEDLG,
model: {
areaType: "table",
pageinfo: null,
rows: repHeads,
areacode: 'replace_head',
}
}),
repBodys: repBodys,
rownos:rownos,
oldRepBodys:JSON.stringify({
pageid: PAGECARDCODE,
model: {
areaType: "table",
pageinfo: null,
rows: oldReplaces,
areacode: AREA.bodyTable,
}
})
}
ajax({
url: URL.replaceDoURL,
data: param,
success: res => {
if (res.success && res.data) {
if (res.data && res.data.isAtpCheckResume && res.data.isAtpCheckResume == true) {
showWarningDialog(getLangByResId(this, '5008Pickm-000001')/* 国际化处理: 提示*/, res.data.atpCheckMsg
, {
beSureBtnClick: replaceOKBtnClicks.bind(this, props, false)
});
return;
}
props.modal.close('ReplaceDlg');
let len=props.cardTable.getNumberOfRows(AREA.bodyTable);
let cpcikmbid;
let updateArray = [];
let indexs=[];
let repItem={};
for (let i = 0; i < len; i++) {
cpcikmbid=props.cardTable.getValByKeyAndIndex(AREA.bodyTable,i,'cpickm_bid');
if(cpcikmbid&&cpcikmbid.value&&res.data[cpcikmbid.value]){
let obj = { index: i, data: res.data[cpcikmbid.value].mainItem };
updateArray.push(obj);
repItem[i]=res.data[cpcikmbid.value].repItems;
indexs.push(i);
}
}
if (updateArray.length > 0) {
props.cardTable.updateDataByIndexs(AREA.bodyTable, updateArray);
for(let j=indexs.length-1;j>=0;j--){
props.cardTable.insertRowsAfterIndex(AREA.bodyTable,repItem[indexs[j]],indexs[j]);
}
RownoUtils.setRowNo(props, AREA.bodyTable, FIELD.vrowno);
props.cardTable.selectAllRows(AREA.bodyTable, false);
props.cardTable.setAllCheckboxAble(AREA.bodyTable, true);
buttonController.lineSelected.call(this);
}
}
},
error: (error) => {
toast({
color: 'warning',
content: error.message
});
}
});
}

View File

@ -0,0 +1,4 @@
export default async function headAfterEvent(props, moduleId, key, value, changedrows, i) {
let headData = props.editTable.getAllData('replace_head', true);
this.props.setHeadDatas(headData);
}

View File

@ -0,0 +1,15 @@
export default function headBeforeEvent(props, moduleId, item, index, value, record) {
let key = item.attrcode;
let editFields = ['freplacetype'];
if (!editFields.includes(key)) {
return false;
}
else if (key == 'freplacetype') {
//以替代的备料计划表体不能修改替代类型
let replaceInfo = props.editTable.getValByKeyAndIndex(moduleId, index, 'freplaceinfo').value;
if (replaceInfo == 2) {
return false;
}
} return true;
}

View File

@ -0,0 +1,5 @@
import headBeforeEvent from './headBeforeEvent';
import headAfterEvent from './headAfterEvent';
import bodyAfterEvent from './bodyAfterEvent';
import bodyBeforeEvent from './bodyBeforeEvent';
export { headBeforeEvent,headAfterEvent,bodyAfterEvent, bodyBeforeEvent };

View File

@ -0,0 +1,147 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { createPage, ajax, base, high } from 'nc-lightapp-front';
const { Refer } = high;
import { initTemplate } from './init';
import { initLang, getLangByResId } from '../../../../../mmpub/mmpub/pub/tool/multiLangUtil';
import { headAfterEvent, headBeforeEvent, bodyAfterEvent, bodyBeforeEvent } from './events';
import { AREA, URL, DIALOGCODE, FIELD, PAGECARDCODE } from '../../constance';
const { NCModal } = base;
const TABLE_HEAD = 'replace_head';
const TABLE_BODY = 'replace_body'
class PickmReplaceDlg extends Component {
constructor(props) {
super(props);
props.use.editTable(TABLE_HEAD);
props.use.editTable(TABLE_BODY);
this.state = {
totalRepNum: {}
};
initLang(this, ['5008Pickm'], 'mmpac', initTemplate.bind(this, this.props));
}
componentDidMount() {
this.initData();
}
//请求列表数据
initData = () => {
let showdata = this.props.showdata;
let heads = [];
let bodys = [];
if (showdata && showdata.head) {
heads = showdata.head[TABLE_HEAD].rows;
if (showdata.body) {
bodys = showdata.body[TABLE_BODY].rows;
}
let cpickmbid = showdata.head[TABLE_HEAD].rows[0].values.cpickm_bid.value;
let bodyData = {};
bodyData[cpickmbid] = bodys;
this.setState({
bodyDatas: bodyData
});
}
this.props.editTable.setTableData(TABLE_HEAD, { rows: heads });
this.props.editTable.setTableData(TABLE_BODY, { rows: bodys });
this.props.setReplaceProps(this.props);
};
onRowClick = (props, moduleId, record, index, e) => {
this.loadBodyInfo(props, record, index);
}
loadBodyInfo(props, record, index) {
let bodyData = this.props.getBodyDatas();
let cpickmbid = this.props.editTable.getValByKeyAndIndex(TABLE_HEAD, index, 'cpickm_bid');
let bodys = [];
let totalRepNum = this.state.totalRepNum;
if (bodyData && bodyData[cpickmbid.value]) {
let cmatreilvid;
let devOrg;
bodys = bodyData[cpickmbid.value];
if (bodys && bodys.length > 0) {
bodys.forEach(body => {
cmatreilvid = body.values.cbmaterialvid.value;
devOrg = body.values.cdeliverorgid.value;
if (totalRepNum && totalRepNum[devOrg + cmatreilvid]) {
body.values.rep_totalrepnum = totalRepNum[devOrg + cmatreilvid].num;
body.values.rep_totalrepastnum = totalRepNum[devOrg + cmatreilvid].astNum;
}
});
}
this.props.editTable.setTableData(TABLE_BODY, { rows: bodys });
}
else {
let userjson = {};
if (totalRepNum) {
Object.keys(totalRepNum).forEach(key => {
userjson[key] = totalRepNum[key].num.value;
})
}
let param = {
pageid: DIALOGCODE.REPLACEDLG,
model: {
areaType: "table",
pageinfo: null,
rows: [record],
areacode: TABLE_HEAD,
},
userjson: JSON.stringify(
userjson
)
};
ajax({
url: URL.replaceBodyQueryURL,
data: param,
success: res => {
if (res.success) {
if (res.data) {
bodys = res.data[TABLE_BODY].rows;
}
bodyData[cpickmbid.value] = bodys;
this.props.editTable.setTableData(TABLE_BODY, { rows: bodys });
}
}
});
}
}
onRowDoubleClick = (record, index, props, e) => {
this.loadBodyInfo(props, record, index);
}
render() {
let { editTable } = this.props;
let { createEditTable } = editTable;
return <div class="flex-container" style={{ height: '100%' }}>
<div className='flex-container'>
{createEditTable(TABLE_HEAD, {
showIndex: true,
// height: 100,
onRowClick: this.onRowClick.bind(this),
onRowDoubleClick: this.onRowDoubleClick.bind(this),
onBeforeEvent: headBeforeEvent.bind(this),
onAfterEvent: headAfterEvent.bind(this),
isAddRow: false,
showCheck: false
})}
</div>
<div className='flex-container'>
{createEditTable(TABLE_BODY, {
onBeforeEvent: bodyBeforeEvent.bind(this),
onAfterEvent: bodyAfterEvent.bind(this),
showCheck: false,
showIndex: true,
hideAdd: false,
adaptionHeight: true
})}
</div>
</div>;
}
}
PickmReplaceDlg = createPage({
billinfo: {
billtype: 'grid',
pagecode: '50080102_replace',
bodycode: 'replace_body'
}//,
})(PickmReplaceDlg);
export default PickmReplaceDlg;

View File

@ -0,0 +1,2 @@
import initTemplate from './initTemplate';
export { initTemplate };

View File

@ -0,0 +1,43 @@
import { DIALOGCODE } from '../../../constance';
import { getLangByResId } from '../../../../../../mmpub/mmpub/pub/tool/multiLangUtil';
const TABLE_HEAD = 'replace_head';
const TABLE_BODY = 'replace_body'
export default function (props) {
let appcode = props.getAppCode();
if (props.getAppCode().startsWith('5009')) {
appcode = '50090102';
}
else if (props.getAppCode().startsWith('5008')) {
appcode = '50080102';
}
//请求模板数据
props.createUIDom(
{
appcode: appcode,
pagecode: DIALOGCODE.REPLACEDLG
},
(templedata) => {
if (templedata.template) {
let meta = templedata.template;
modifierMeta.call(this, this.props, meta);
props.meta.setMeta(meta);
props.editTable.setStatus(TABLE_HEAD, 'edit');
props.editTable.setStatus(TABLE_BODY, 'edit');
}
});
}
function modifierMeta(props, meta) {
meta[TABLE_HEAD].items.map((item) => {
if (item.attrcode == 'freplacetype') {
item.options = [{
display: getLangByResId(this, '5008Pickm-000096')/* 国际化处理: "全部替代"*/,
value: "1"
}, {
display: getLangByResId(this, '5008Pickm-000097')/* 国际化处理: ""部分替代"*/,
value: "2"
}
];
}
});
return meta;
}