| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import {danxiangdinge_index} from './utils';
- function copy(input) {
- return JSON.parse(JSON.stringify(input));
- }
- export const shanchu = (hotRef, selectedRow, detailRef) => {
-
- let deleted = hotRef.current?.hotInstance?.getData()[selectedRow.current][2];
- //hotRef.current?.hotInstance?.alter('remove_row', selectedRow.current, 1);
- let qdbm = null;
- for (let i = selectedRow.current - 1; i > -1; i= i - 1) {
- let above = hotRef.current?.hotInstance?.getData()[i];
- if (above[1] != null) {
- qdbm = above[2];
- break;
- }
-
- }
-
- let newData = detailRef.current.map(x=>{
- if (x["清单编码"] == qdbm) {
- let y = copy(x);
- let origin = y["__children"];
- let trans = origin.filter(z=>z["清单编码"]!=deleted);
- y["__children"] = trans;
- return y;
- } else {
- return x;
- }
- });
- detailRef.current = newData;
-
- return newData;
- };
- export const push_op = (memory, mem_pointer, detailRef) => {
- if(memory.current.length == mem_pointer.current + 1) {
- memory.current.push(copy(detailRef.current));
- mem_pointer.current = mem_pointer.current + 1;
- } else{
- memory.current.splice(mem_pointer.current + 1);
- memory.current.push(copy(detailRef.current));
- mem_pointer.current = mem_pointer.current + 1;
- }
- console.log("after op the memory is");
- console.log(memory.current);
- console.log(mem_pointer.current);
- };
- export const quanbushanchu = (hotRef, selectedRow, detailRef) => {
- let qdbm = hotRef.current?.hotInstance?.getData()[selectedRow.current][2];
-
- let newData = detailRef.current.map(x=>{
- if (x["清单编码"] == qdbm) {
- let y = copy(x);
- y["__children"] = [];
- return y;
- } else {
- return x;
- }
- });
- detailRef.current = newData;
- return newData;
- };
- export const danxiangdinge = (hotRef, selectedRow, detailRef) => {
- let bh = danxiangdinge_index(detailRef.current);
- let selected = hotRef.current?.hotInstance?.getData()[selectedRow.current];
- if (selected && selected[1] != null) {
- let danwei = selected[6];
- let newData = detailRef.current.map(
- x => {
- if (x['序号'] == selected[1]) {
- let y = copy(x);
- if (y.hasOwnProperty("__children")) {
- y["__children"].push(
- {
- '操作': '',
- '序号': null,
- '清单编码': bh,
- '名称': '',
- '项目特征': null,
- '计算规则': null,
- '单位': danwei,
- '数量': '1',
- '综合单价': '',
- '合价': '',
- '人工费': '0',
- '主材费': '0',
- '设备费': '0',
- '辅材费': '',
- '材料费': '',
- '机械费': '0',
- '管理费': '0',
- '利润': '0',
- '暂估价': null,
- '综合人工工日': null,
- '备注': null,
- }
- );
- } else {
- y["__children"] = [{
- '操作': '',
- '序号': null,
- '清单编码': bh,
- '名称': '',
- '项目特征': null,
- '计算规则': null,
- '单位': danwei,
- '数量': '1',
- '综合单价': '',
- '合价': '',
- '人工费': '0',
- '主材费': '0',
- '设备费': '0',
- '辅材费': '',
- '材料费': '',
- '机械费': '0',
- '管理费': '0',
- '利润': '0',
- '暂估价': null,
- '综合人工工日': null,
- '备注': null,
- }];
- }
- return y;
- } else {
- return x;
- }
- }
- );
- detailRef.current = newData;
- return [true, newData];
- } else {
- return [false, detailRef.current];
- }
- };
|