conversion.js 51.6 KB
Newer Older
hehongwei's avatar
hehongwei committed
1
import { selectActSuppliesHistorydataAcc } from "@/api/Actsupplies/cleaning_rule";
2
// import { Tangshan } from "@/conversion/TangshanMine";
chengwenlong's avatar
chengwenlong committed
3
import { Tangshan } from "@/conversion/TangshanMin";
hehongwei's avatar
hehongwei committed
4 5 6 7 8 9
import { Linxi } from "@/conversion/LinxiMine";
import { lvMine } from "@/conversion/lvMine";
import { fanMine } from "@/conversion/fanMine";
import { DongMine } from "@/conversion/DonghuantuoMine";
import { danMine } from "@/conversion/danhouMine";
import { hongMine } from "@/conversion/hongMine";
chengwenlong's avatar
chengwenlong committed
10
import { YunFei } from "@/conversion/YunFei";
11
import { MoneyMine } from "@/conversion/MoneyMine";
chengwenlong's avatar
chengwenlong committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import { ZhongRun } from "@/conversion/ZhongRun";
import {
    getSuppliesTemplate,
    listSuppliesTemplate,
    roleList,
    materialListPZ,
    accountingcode,
    department,
    roleListid,
    code,
} from "@/api/ruoyi-myLuckyexcel/myluckyexcel";
import {
    addInsert,
    addInsertAccount1,
    addInsertAccount2,
    datahistoryContentCopy
} from "@/api/system/historydata";
hehongwei's avatar
hehongwei committed
29
/*import luckysheet from 'luckysheet'*/
chengwenlong's avatar
chengwenlong committed
30
import LuckyExcel from "luckyexcel";
hehongwei's avatar
hehongwei committed
31 32
//导入库export.js 这个文件是es6的,不能在普通的HTML文件直接引入js文件(虽然都是js文件,但是有区别,具体请百度es6与es5)!需要把es6转es5才可以直接引入使用!
/*import {materialList} from "@/api/ruoyi-myLuckyexcel/myluckyexcel";*/
chengwenlong's avatar
chengwenlong committed
33 34
import { exportExcel } from "../../public/exportExcel";
import { v4 as uuidv4 } from "uuid";
35
import { min } from "moment/moment";
36
import { setXRow, setXColumn } from '@/utils/tzc'
chengwenlong's avatar
chengwenlong committed
37

hehongwei's avatar
hehongwei committed
38 39 40 41 42 43 44 45 46 47 48
var fileName = "新建XLSX工作表"; //定义表名
var rule = [];
var tempId;
var roleId;
var uuid1;
var trueORfalse = false;
var modify = false;
export default {
    name: "Mymodule",
    data() {
        return {
chengwenlong's avatar
chengwenlong committed
49 50
            research: [],
            result: '',
hehongwei's avatar
hehongwei committed
51 52
            dialogTableVisible: false,
            //清洗规则名字
chengwenlong's avatar
chengwenlong committed
53
            selectname: "",
hehongwei's avatar
hehongwei committed
54
            //kuang
chengwenlong's avatar
chengwenlong committed
55
            mine: "",
hehongwei's avatar
hehongwei committed
56 57 58 59
            //传入后台清洗规则
            historyContent: [],
            num: 1,
            nums: 1,
chengwenlong's avatar
chengwenlong committed
60 61 62 63 64 65
            value: "",
            VoucherForm: "",
            miningValue: "",
            Cleaningrole: "",
            phone: "",
            classify: "",
hehongwei's avatar
hehongwei committed
66
            //选择的矿区
chengwenlong's avatar
chengwenlong committed
67
            select: "",
hehongwei's avatar
hehongwei committed
68
            //转换完成成本材料的所有数据
chengwenlong's avatar
chengwenlong committed
69
            middle: "",
hehongwei's avatar
hehongwei committed
70
            //未导入成本材料表模板所有数据
chengwenlong's avatar
chengwenlong committed
71
            jsondata: "",
hehongwei's avatar
hehongwei committed
72
            //编码数据
chengwenlong's avatar
chengwenlong committed
73
            codess: "",
hehongwei's avatar
hehongwei committed
74 75 76
            luckyrule: [],
            showMask: false,
            //选中的表的数据
chengwenlong's avatar
chengwenlong committed
77 78
            selected: "",
            uuid: "",
hehongwei's avatar
hehongwei committed
79 80 81
            //弹出页面的表名
            from_name: "",
            //单侯煤矿的成本表
chengwenlong's avatar
chengwenlong committed
82
            newArray: "",
hehongwei's avatar
hehongwei committed
83
            //宏丰的成本表
chengwenlong's avatar
chengwenlong committed
84
            newArrayhong: "",
hehongwei's avatar
hehongwei committed
85 86 87 88
            //往后台穿的导入表的东西
            ImportTables: {},
            //往后台传生成表的数据
            generate: {},
chengwenlong's avatar
chengwenlong committed
89
            cleaning: "",
hehongwei's avatar
hehongwei committed
90 91
            // 是否显示弹出层
            dialogVisible: false,
chengwenlong's avatar
chengwenlong committed
92 93 94
            selectedOption: "",
            selectedRule: "",
            luckysheetData: "",
hehongwei's avatar
hehongwei committed
95 96 97 98 99
            fileList: [],
            disableNextButton: true,
            depss: [],
            // 表单参数
            from: {},
chengwenlong's avatar
chengwenlong committed
100 101
            date: "",
            mining: "",
hehongwei's avatar
hehongwei committed
102 103 104 105 106 107 108 109 110 111 112 113
            duplicateData: [],
            froms: {
                hId: "",
                projectId: "",
                projectName: "",
                departmentName: "",
                number: "",
                nuitPrice: "",
                money: "",
                createBy: "",
                hDate: null,
            },
chengwenlong's avatar
chengwenlong committed
114
            synthesis: "",
hehongwei's avatar
hehongwei committed
115 116 117 118 119 120
            historyRole: [],
            dfrom: {},
            imp: {},
            ssd: {},
            // 查询参数
            queryParams: {
chengwenlong's avatar
chengwenlong committed
121
                status: 0,
hehongwei's avatar
hehongwei committed
122 123 124 125 126 127 128 129 130 131 132
            },
        };
    },
    created() {
        //刷新页面时进行的操作
        this.delect();
        this.getList();
    },
    mounted() {
        this.init();
        fileName = "新建XLSX工作表";
chengwenlong's avatar
chengwenlong committed
133
        // this.list()
hehongwei's avatar
hehongwei committed
134 135
    },
    methods: {
136

hehongwei's avatar
hehongwei committed
137
        delect() {
chengwenlong's avatar
chengwenlong committed
138 139
            this.mine = "";
            this.selectname = "";
hehongwei's avatar
hehongwei committed
140 141
        },
        //查询材料编码
chengwenlong's avatar
chengwenlong committed
142 143
        list(excelid) {
            getSuppliesTemplate(1248).then((response) => {
hehongwei's avatar
hehongwei committed
144 145 146
                const sysSupplies = response.rows;
                this.luckysheetData = sysSupplies[0].templateContent;
                let VoucherForm = JSON.parse(sysSupplies[0].templateContent);
chengwenlong's avatar
chengwenlong committed
147 148 149 150 151
                this.VoucherForm = JSON.stringify(VoucherForm);
            });
            getSuppliesTemplate(excelid).then((response) => {
                this.generate.historyName =
                    response.rows[0].templateName + "(生成文件)";
hehongwei's avatar
hehongwei committed
152 153 154 155 156
                const sysSupplies = response.rows;
                this.luckysheetData = sysSupplies[0].templateContent;
                //将接收到的json存到json_data中
                //const json_data = response.data;
                this.jsondata = JSON.parse(sysSupplies[0].templateContent);
chengwenlong's avatar
chengwenlong committed
157
            });
158

hehongwei's avatar
hehongwei committed
159 160 161
        },
        //手机号
        open(evt) {
chengwenlong's avatar
chengwenlong committed
162 163 164
            this.$prompt("请输入用友系统的用户名", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
hehongwei's avatar
hehongwei committed
165
                inputPattern: /^(?:\+?86)?1[3-9]\d{9}$/,
chengwenlong's avatar
chengwenlong committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
                inputErrorMessage: "手机号格式不正确",
            })
                .then(({ value }) => {
                    this.$message({
                        type: "success",
                        message: "你的用户名是: " + value,
                    });
                    this.phone = value;
                    this.zhuan(evt);
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "取消输入",
                    });
                    this.showMask = false;
hehongwei's avatar
hehongwei committed
182 183 184 185
                });
        },
        /** 判断是否选择时间*/
        rulesdate() {
chengwenlong's avatar
chengwenlong committed
186 187 188 189 190
            this.handleminingChange(this.mining);
            code(this.mining).then((response) => {
                this.codess = response.data;
            });
            if (this.date == "" || this.date == null) {
hehongwei's avatar
hehongwei committed
191
                this.disableNextButton = true;
chengwenlong's avatar
chengwenlong committed
192 193
                this.$message.error("请选择时间日期!");
            } else if (this.cleaning == "") {
hehongwei's avatar
hehongwei committed
194
                this.disableNextButton = true;
chengwenlong's avatar
chengwenlong committed
195
                this.$message.error("请选择清洗规则!");
hehongwei's avatar
hehongwei committed
196 197
            } else if (!this.selectname.includes(this.mine)) {
                this.disableNextButton = true;
chengwenlong's avatar
chengwenlong committed
198
                this.$message.error("清洗规则和所属矿区必须一致!");
hehongwei's avatar
hehongwei committed
199 200 201 202 203 204 205 206 207 208 209
            }
        },
        handledateChange(value) {
            const date = new Date(value);
            // 获取年份和月份
            const year = date.getFullYear(); // 获取年份
            const month = (date.getMonth() + 1).toString().padStart(2, "0"); // 获取月份并补零处理

            // 将年份和月份拼接成 "YYYY-MM" 的格式
            const formattedDate = year + "-" + month;

chengwenlong's avatar
chengwenlong committed
210 211 212 213 214 215
            this.date = formattedDate;
            if (
                this.date == "" ||
                this.date == null ||
                this.date == undefined
            ) {
hehongwei's avatar
hehongwei committed
216 217 218 219 220 221
                this.disableNextButton = true;
            } else {
                this.disableNextButton = false;
            }
        },
        handleminingChange(value) {
chengwenlong's avatar
chengwenlong committed
222 223 224 225
            department(value).then((response) => {
                this.classify = response;
            });
            const selectedItem = this.miningValue;
hehongwei's avatar
hehongwei committed
226
            if (selectedItem) {
chengwenlong's avatar
chengwenlong committed
227
                this.mine = selectedItem.name;
hehongwei's avatar
hehongwei committed
228
            }
chengwenlong's avatar
chengwenlong committed
229 230 231 232 233 234
            this.select = value;
            if (
                this.date == "" ||
                this.date == null ||
                this.date == undefined
            ) {
hehongwei's avatar
hehongwei committed
235 236 237 238 239 240 241
                this.disableNextButton = true;
            } else {
                this.disableNextButton = false;
            }
        },
        /** 页面刷新时展示的数据*/
        getList() {
chengwenlong's avatar
chengwenlong committed
242 243 244
            listSuppliesTemplate(this.queryParams).then((response) => {
                response.rows.forEach((row) => {
                    if (row.templateName.includes("六矿")) {
hehongwei's avatar
hehongwei committed
245 246 247 248 249 250 251
                        row.disabled = true;
                    }
                });
                this.depss = response.rows;
            });
        },
        /** 下拉选和页面luckysheet绑定 */
chengwenlong's avatar
chengwenlong committed
252 253 254 255 256 257 258 259 260
        handleOptionChange(value, miningValue, mining, excelid) {
            this.list(excelid);
            this.miningValue = miningValue;
            this.mining = mining;
            this.date = "";
            this.ImportTables.templateId = value;
            this.generate.templateId = value;
            this.selectedRule = "";
            this.disableNextButton = this.selectedRule === "";
hehongwei's avatar
hehongwei committed
261
            //根据选中的下拉选项值获取相应的信息
chengwenlong's avatar
chengwenlong committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
            getSuppliesTemplate(this.selectedOption)
                .then((response) => {
                    //如果为六矿汇总表,导出时隐藏前两列
                    if (
                        this.selectedOption === 7 ||
                        this.selectedOption === 10
                    ) {
                        trueORfalse = true;
                    } else {
                        trueORfalse = false;
                    }
                    modify = false;
                    tempId = this.selectedOption;
                    uuid1 = this.uuid = uuidv4().substring(0, 8);
                    const sysSupplies = response.rows;
                    this.luckysheetData = sysSupplies[0].templateContent;
                    //将接收到的json存到json_data中
                    //const json_data = response.data;
                    var json_data = JSON.parse(sysSupplies[0].templateContent);
                    roleList(value).then((response) => {
                        this.luckyrule = response.rows;
                    });
                    let suffixArr = sysSupplies[0].templateName.split(".");
                    fileName = suffixArr[0];
                    //luckysheet.destroy()
                    luckysheet.create({
                        container: "luckysheet", // Luckysheet 的容器元素 ID
                        title: fileName, // Excel 文件名
                        data: json_data, // Excel 数据
                        showinfobar: false,
                        allowEdit: false, //是否显示顶部名称栏
                        lang: "zh",
                    });
                    this.value = fileName;
                })
                .catch(() => {
                    // 处理错误逻辑,这里是一个空的错误处理函数
                    this.$message.error("查询失败,发生未知错误!");
hehongwei's avatar
hehongwei committed
300 301 302
                });
        },
        open4() {
chengwenlong's avatar
chengwenlong committed
303
            this.$message.error("请仔细检查所导入表");
hehongwei's avatar
hehongwei committed
304 305 306
        },
        /** 规则下拉选 调佣后端的方法*/
        handleRuleChange(value) {
chengwenlong's avatar
chengwenlong committed
307 308 309
            const selectedItem = this.luckyrule.find(
                (item) => item.id === value
            );
hehongwei's avatar
hehongwei committed
310
            if (selectedItem) {
chengwenlong's avatar
chengwenlong committed
311
                this.selectname = selectedItem.roleName;
hehongwei's avatar
hehongwei committed
312 313
            }

chengwenlong's avatar
chengwenlong committed
314 315
            if (this.selectedOption === "") {
                this.selectedRule = "";
hehongwei's avatar
hehongwei committed
316 317 318 319
                this.$message.warning("选择规则前请先选择模板!");
                return; // 如果按钮被禁用,提前返回,避免执行下一步操作
            }

chengwenlong's avatar
chengwenlong committed
320 321
            this.disableNextButton = this.selectedRule === "";
            roleListid(this.selectedRule).then((response) => {
hehongwei's avatar
hehongwei committed
322 323 324
                roleId = this.selectedRule;
                rule = response.rows;
                //清洗规则
chengwenlong's avatar
chengwenlong committed
325 326
                this.cleaning = JSON.parse(response.rows[0].detailContent);
                this.ImportTables.convenRole = response.rows[0].detailContent;
hehongwei's avatar
hehongwei committed
327 328
            });
            if (tempId === 7 || tempId === 10) {
chengwenlong's avatar
chengwenlong committed
329 330 331 332 333 334 335 336 337 338
                getSuppliesTemplate(tempId)
                    .then((response) => {
                        uuid1 = this.uuid = uuidv4().substring(0, 8);
                        // 通过遍历this.luckyrule找到对应的iem.roleName
                        for (let i = 0; i < this.luckyrule.length; i++) {
                            if (this.luckyrule[i].id === this.selectedRule) {
                                let name = this.luckyrule[i].roleName;
                                fileName = name.slice(0, -2);
                                break;
                            }
hehongwei's avatar
hehongwei committed
339
                        }
chengwenlong's avatar
chengwenlong committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
                        modify = false;
                        const sysSupplies = response.rows;
                        this.luckysheetData = sysSupplies[0].templateContent;
                        let json_data = JSON.parse(
                            sysSupplies[0].templateContent
                        );
                        luckysheet.create({
                            container: "luckysheet", // Luckysheet 的容器元素 ID
                            title: fileName, // Excel 文件名
                            data: json_data, // Excel 数据
                            showinfobar: false, //是否显示顶部名称栏
                            lang: "zh",
                        });
                    })
                    .catch(() => {
                        // 处理错误逻辑,这里是一个空的错误处理函数
                        this.$message.error("查询失败,发生未知错误!");
hehongwei's avatar
hehongwei committed
357 358 359 360 361 362 363
                    });
            }
        },
        /** 重置按钮操作 */
        resetQuery() {
            //刷新下拉选框内容
            fileName = "新建XLSX工作表";
chengwenlong's avatar
chengwenlong committed
364 365
            this.selectedOption = "";
            this.disableNextButton = "";
hehongwei's avatar
hehongwei committed
366 367
            this.luckyrule = [];

chengwenlong's avatar
chengwenlong committed
368
            this.selectedRule = "";
hehongwei's avatar
hehongwei committed
369 370
            trueORfalse = false;
            modify = false;
chengwenlong's avatar
chengwenlong committed
371
            uuid1 = "";
hehongwei's avatar
hehongwei committed
372 373 374 375 376 377
            //刷新luckysheet表格
            this.init();
        },
        /** Luckyexcel文档 */
        init() {
            let options = {
chengwenlong's avatar
chengwenlong committed
378 379 380
                container: "luckysheet", //luckysheet为容器id
                title: "",
                lang: "zh",
hehongwei's avatar
hehongwei committed
381 382 383
                showinfobar: false,
                data: [
                    {
chengwenlong's avatar
chengwenlong committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
                        name: "sheet1", //工作表名称
                        color: "", //工作表颜色
                        index: 0, //工作表索引
                        status: 1, //激活状态
                        order: 0, //工作表的下标
                        hide: 0, //是否隐藏
                        row: 50, //行数
                        column: 20, //列数
                        defaultRowHeight: 19, //自定义行高
                        defaultColWidth: 73, //自定义列宽
                        celldata: [], //初始化使用的单元格数据
                        config: {
                            merge: {}, //合并单元格
                            rowlen: {}, //表格行高
                            columnlen: {}, //表格列宽
                            rowhidden: {}, //隐藏行
                            colhidden: {}, //隐藏列
                            borderInfo: {}, //边框
                            authority: {}, //工作表保护
hehongwei's avatar
hehongwei committed
403 404
                        },
                    },
chengwenlong's avatar
chengwenlong committed
405 406
                ],
            };
hehongwei's avatar
hehongwei committed
407 408 409 410
            luckysheet.create(options);
        },
        async handleFileChange(evt) {
            if (modify) {
chengwenlong's avatar
chengwenlong committed
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
                this.$confirm(
                    "再次导入将会清空表内数据,是否继续操作?",
                    "注意!!!",
                    {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }
                )
                    .then(async () => {
                        // 确认继续后刷新页面返回模板
                        getSuppliesTemplate(this.selectedOption)
                            .then((response) => {
                                const sysSupplies = response.rows;
                                this.luckysheetData =
                                    sysSupplies[0].templateContent;
                                let json_data = JSON.parse(
                                    sysSupplies[0].templateContent
                                );
                                luckysheet.destroy();
                                luckysheet.create({
                                    container: "luckysheet", // Luckysheet 的容器元素 ID
                                    title: fileName, // Excel 文件名
                                    data: json_data, // Excel 数据
                                    allowEdit: false, //作用:是否允许前台编辑
                                    showinfobar: false, //是否显示顶部名称栏
                                    lang: "zh",
                                });
                                modify = false;
                                this.open(evt);
                            })
                            .then(async () => { })
                            .catch(() => { });
                    })
                    .catch(() => {
                        // 用户点击了取消按钮
                        this.$message({ type: "info", message: "操作已取消" });
hehongwei's avatar
hehongwei committed
448 449
                    });
            } else {
chengwenlong's avatar
chengwenlong committed
450
                this.open(evt);
hehongwei's avatar
hehongwei committed
451
                this.showMask = true;
chengwenlong's avatar
chengwenlong committed
452
                LuckyExcel(evt, (exportJson) => {
hehongwei's avatar
hehongwei committed
453 454 455 456 457 458
                    //获取导入表格所有数据exportJson
                    this.open(exportJson)
                        // this.summary(exportJson)
                        .then(async () => {
                            // this.submit(exportJson);
                        })
chengwenlong's avatar
chengwenlong committed
459
                        .catch((error) => {
hehongwei's avatar
hehongwei committed
460 461
                            this.$message({
                                message: error.message,
chengwenlong's avatar
chengwenlong committed
462
                                type: "error",
hehongwei's avatar
hehongwei committed
463 464 465 466 467 468 469 470 471
                            });
                        })
                        .finally(() => {
                            // 导入完成后关闭遮罩层
                            this.showMask = false;
                        });
                });
            }
        },
472
        //转换方法
chengwenlong's avatar
chengwenlong committed
473
        transformPromises() {
474

chengwenlong's avatar
chengwenlong committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
            // try {
            let result = this.result
            this.dialogTableVisible = false
            let cc = result;
            let resultJSON = JSON.stringify(result.sheets)
            this.ImportTables.historyName =
                result.info.name + "(导入表名)";
            let codess = this.codess;
            let CompositeTable = this.jsondata;
            let classify = {};
            this.classify.forEach((item) => {
                if (item.nameType) {
                    if (classify[item.nameType]) {
                        classify[item.nameType] += `, ${item.name}`;
                    } else {
                        classify[item.nameType] = item.name;
                    }
                }
            });


            let c = cc.sheets[0].celldata;
            let cjson = JSON.stringify(c);
            let config = cc.sheets[0].config;
            //表头所在行
            let headRow = this.cleaning[0].HeaderRow - 2;
501 502
            let headROWs = c.flat().filter(obj => obj.c && obj.r == headRow)
            //部门所在列及所有部门的数据
chengwenlong's avatar
chengwenlong committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
            let DepartmentColumns =
                this.cleaning[0].DepartmentColumn - 1;
            let Department = c
                .flat()
                .filter(
                    (obj) =>
                        obj.c &&
                        obj.c === DepartmentColumns &&
                        obj.r > headRow
                );
            //编码所在列
            let codecolumn = this.cleaning[0].CodeColumn - 1;
            let code = c
                .flat()
                .filter(
                    (obj) =>
                        obj.c === codecolumn && obj.r > headRow
                );
            //金额列
            let moneyColumn = this.cleaning[0].money - 1;
            let money = c
                .flat()
                .filter(
                    (obj) =>
                        obj.c &&
                        obj.c === moneyColumn &&
                        obj.r > headRow
                );
            //数量
            let quantitys = this.cleaning[0].NumberColumn - 1;
            let quantity = c
                .flat()
                .filter(
                    (obj) =>
                        obj.c && obj.c === quantitys && obj.r > headRow
                );
            //单价
            let Unitprices = this.cleaning[0].MoneyColumn - 1;
            let Unitprice = c
                .flat()
                .filter(
                    (obj) =>
                        obj.c && obj.c === Unitprices && obj.r > headRow
                );
            //型号
            let models = this.cleaning[0].model - 1;
            let model = c
                .flat()
                .filter(
                    (obj) => obj.c && obj.c == models && obj.r > headRow
                );
            //类别名称
            let names = this.cleaning[0].sourceColoumn
                ? this.cleaning[0].sourceColoumn - 1
                : null;
558

chengwenlong's avatar
chengwenlong committed
559 560 561 562 563 564 565 566 567 568
            let name = names
                ? c
                    .flat()
                    .filter(
                        (obj) =>
                            obj.c &&
                            obj.c === names &&
                            obj.r > headRow
                    )
                : null;
569

chengwenlong's avatar
chengwenlong committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
            //材料名称所在列
            let materias = this.cleaning[0].NameColumn - 1;
            let materianame = c
                .flat()
                .filter(
                    (obj) =>
                        obj.c && obj.c === materias && obj.r > headRow
                );
            //单位
            let unit = this.cleaning[0].unit - 1;
            let units = c
                .flat()
                .filter(
                    (obj) => obj.c && obj.c === unit && obj.r > headRow
                );

            // 唐山矿转换方法
            //没任何规则
            let duplicateData = [];
            if (this.mining == "010101") {
                const duplicateDatas = Tangshan(
                    money,
                    c,
                    name,
                    CompositeTable,
                    headRow
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //林西
            if (this.mining == "011704") {
                const duplicateDatas = Linxi(
                    names,
                    Department,
                    money,
                    code,
                    duplicateData,
                    CompositeTable,
                    codess,
                    classify,
                    DepartmentColumns,
                    codecolumn
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //东欢坨
            if (this.mining == "010102") {
                const duplicateDatas = DongMine(
                    money,
                    code,
                    codess,
                    CompositeTable,
                    Department,
                    classify,
                    duplicateData
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //单侯
            if (this.mining == "011204") {
                const duplicateDatas = danMine(
                    CompositeTable,
                    c,
                    Department,
                    money,
                    code,
                    classify,
                    codess,
                    name,
                    headRow
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //吕矿
            if (this.mining == "011702") {
                const duplicateDatas = lvMine(
                    CompositeTable,
                    cjson,
                    codess,
                    code
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //范矿
            if (this.mining == "011701") {
                const duplicateDatas = fanMine(
                    money,
                    codess,
                    code,
                    CompositeTable,
                    name
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //宏丰
            if (this.mining == "011502") {
                const duplicateDatas = hongMine(
                    money,
                    Department,
                    code,
                    name,
                    codess,
                    CompositeTable
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //钱矿
            if (this.mining == "010105") {
                const duplicateDatas = MoneyMine(
                    money,
                    DepartmentColumns,
                    name,
                    materianame,
                    c,
                    CompositeTable,
                    headRow
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //云飞
            if (this.mining == '011504') {
                const duplicateDatas = YunFei(
                    money,
                    Department,
                    code,
                    name,
                    codess,
                    CompositeTable
                );
                duplicateData = duplicateDatas.duplicateData;
                CompositeTable = duplicateDatas.CompositeTable;
            }
            //中润
            if (this.mining == "011706") {
                const duplicateDatas = ZhongRun(
                    Department,
                    money,
                    materianame,
                    name,
                    CompositeTable,
                    quantity,
                    model,
                    Unitprice,
                    code,
                    units
                );
                CompositeTable = duplicateDatas.CompositeTable;
            }
            CompositeTable[0].calcChain = [];
            let as = CompositeTable[0].celldata.filter(
                (item) => item.v.f
            );
            as.forEach((item) => {
                let sum = {
                    index: "1",
                    r: item.r,
                    c: item.c,
                };
                CompositeTable[0].calcChain.push(sum);
            });
            // celldata => data 生成表格所需二维数组
            CompositeTable[0].data = luckysheet.transToData(
                CompositeTable[0]["celldata"]
            );
            this.ImportTables.historyContent = resultJSON;
            //往后台传科目编码相关的东西
            let matchedItems = CompositeTable[0]["celldata"].filter(
                (item) =>
                    item.v &&
                    ((typeof item.v.v === "string" &&
                        item.v.v.includes("其他材料")) ||
749 750
                        (typeof item.v.v === "string" &&
                        item.v.v.includes("生产材料")))
chengwenlong's avatar
chengwenlong committed
751 752 753 754
            )[0].r;
            let material = CompositeTable[0]["celldata"]
                .flat()
                .filter((obj) => obj.r && obj.r === matchedItems);
755
            console.log(material)
chengwenlong's avatar
chengwenlong committed
756
            duplicateData.forEach((obj) => {
757
                obj.v.material=''
chengwenlong's avatar
chengwenlong committed
758 759 760 761 762 763
                material.forEach((cell) => {
                    if (obj.c === cell.c) {
                        obj.v.material = cell.v.v;
                    }
                });
            });
764
            console.log(duplicateData,'2222222222')
chengwenlong's avatar
chengwenlong committed
765 766 767 768
            var cellList = [];
            var newHistoryContent = JSON.parse(
                this.ImportTables.historyContent
            );
769
            let maxC = headROWs.length - 1
chengwenlong's avatar
chengwenlong committed
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
            duplicateData.forEach((item) => {
                //新加字段内容拼接
                var newName = item.v.name + "-" + item.v.material;
                item.index.forEach((i) => {
                    var cell26 = {
                        r: i,
                        c: maxC + 1,
                        v: {
                            ct: {
                                fa: "General",
                                t: "n",
                            },
                            fs: 9,
                            ff: "宋体",
                            ht: 2,
                            vt: 0,
                            tb: 2,
                            v: newName,
                            m: newName,
                        },
                    };
                    cellList.push(cell26);
                });
            });

            newHistoryContent[0].celldata.push(...cellList);
            newHistoryContent[0].data = luckysheet.transToData(
                newHistoryContent[0]["celldata"]
            );
799
            if (!this.value.includes("凭证") || this.mining == "011706") {
chengwenlong's avatar
chengwenlong committed
800 801 802 803 804 805 806
                luckysheet.create({
                    container: "luckysheet", // Luckysheet 的容器元素 ID
                    title: fileName, // Excel 文件名
                    data: CompositeTable, // Excel 数据
                    showinfobar: false, //是否显示顶部名称栏
                    lang: "zh",
                });
807
                luckysheet.refreshFormula(); //渲染公式
chengwenlong's avatar
chengwenlong committed
808 809 810
                modify = true;
                this.showMask = false;
            }
811 812 813
            if (this.mining == '011706') {
                duplicateData = workbookCreateAfter(CompositeTable, this.mining)
            }
chengwenlong's avatar
chengwenlong committed
814 815 816 817 818 819 820 821 822 823 824
            this.ImportTables.historyContent = JSON.stringify(newHistoryContent)
            this.generate.historyContent =
                JSON.stringify(CompositeTable);
            this.middle = CompositeTable;
            this.duplicateData.push(...duplicateData);
            this.Vouchers(this.duplicateData);
            // } catch (error) {
            //     this.open4();
            //     this.showMask = false;
            // }
        },
hehongwei's avatar
hehongwei committed
825 826 827 828 829 830 831 832
        zhuan(file) {
            let cc = '';
            const transformPromise = new Promise((resolve, reject) => {
                LuckyExcel.transformExcelToLucky(file, (lucksheetfile) => {
                    resolve(lucksheetfile);
                });
            });
            transformPromise.then((result) => {
chengwenlong's avatar
chengwenlong committed
833
                this.result = result
834 835 836 837 838 839 840
                cc = result;
                let c = cc.sheets[0].celldata
                //表头所在行
                let headRow = this.cleaning[0].HeaderRow - 2
                //类别名称
                let names = this.cleaning[0].sourceColoumn ? this.cleaning[0].sourceColoumn - 1 : null;
                let name = names ? c.flat().filter(obj => obj.c && obj.c === names && obj.r > headRow) : null;
841

chengwenlong's avatar
chengwenlong committed
842
                this.transformPromises()
hehongwei's avatar
hehongwei committed
843 844
            });
        },
845
        //成本表往凭证但转
hehongwei's avatar
hehongwei committed
846
        Vouchers(duplicateData) {
chengwenlong's avatar
chengwenlong committed
847 848 849 850 851 852 853 854 855 856 857 858
            let sum = [
                {
                    code: "2241005",
                    material: "其他材料",
                    v: 0,
                },
                {
                    code: "1403002",
                    material: "火工品",
                    v: 0,
                },
            ];
hehongwei's avatar
hehongwei committed
859 860 861 862 863 864 865 866 867

            for (let i = 0; i < duplicateData.length; i++) {
                if (duplicateData[i].v.material === "火工品") {
                    sum[1].v += Number(duplicateData[i].v.v);
                } else {
                    sum[0].v += Number(duplicateData[i].v.v);
                }
            }

chengwenlong's avatar
chengwenlong committed
868
            sum.forEach((item) => {
hehongwei's avatar
hehongwei committed
869 870
                item.v = Number(item.v).toFixed(2);
            });
chengwenlong's avatar
chengwenlong committed
871
            sum = sum.filter((item) => item.v !== "0.00");
hehongwei's avatar
hehongwei committed
872
            const VoucherForm = JSON.parse(this.VoucherForm);
chengwenlong's avatar
chengwenlong committed
873 874 875
            const filteredData = VoucherForm[0].celldata.filter(
                (obj) => obj.r === 5
            );
hehongwei's avatar
hehongwei committed
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
            const needKeys = [
                "*手工码",
                "*会计主体",
                "*核算账簿",
                "*单据日期",
                "*凭证类型",
                "*制单人",
                "*分录摘要",
                "*币种",
                "本币汇率类型",
                "*本币汇率",
                "*业务日期",
                "凭证单摘要",
            ];

            // 根据需要的关键词获取对应的单元格
chengwenlong's avatar
chengwenlong committed
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
            const need = needKeys.map(
                (key) => filteredData.find((obj) => obj.v.v === key).c
            );
            const loan = filteredData.filter(
                (obj) => obj.v.v === "原币贷方金额"
            )[0].c;
            const loan1 = filteredData.filter(
                (obj) => obj.v.v === "本币贷方金额"
            )[0].c;
            const money = filteredData.filter(
                (obj) => obj.v.v === "原币借方金额"
            )[0].c;
            const money1 = filteredData.filter(
                (obj) => obj.v.v === "本币借方金额"
            )[0].c;
hehongwei's avatar
hehongwei committed
907
            // 根据特定条件筛选单元格
chengwenlong's avatar
chengwenlong committed
908 909 910
            const foundObjects = filteredData.filter(
                (obj) => obj.v.v === "物料基本分类"
            );
hehongwei's avatar
hehongwei committed
911 912 913 914 915 916 917 918 919 920
            let Classification;
            let oldClassification;
            if (foundObjects.length >= 2) {
                oldClassification = foundObjects[0].c;
                Classification = foundObjects[1].c;
            } else {
                // 处理找不到两个满足条件的对象的情况
            }

            // 遍历duplicateData数组,为每个对象添加mining属性并赋值为this.select
chengwenlong's avatar
chengwenlong committed
921
            duplicateData.forEach((obj) => {
hehongwei's avatar
hehongwei committed
922 923 924 925 926
                obj.mining = this.select;
            });

            // 生成标准模板
            const Fusion = {
chengwenlong's avatar
chengwenlong committed
927 928 929 930 931 932
                r: "",
                c: "",
                v: {
                    ct: {
                        fa: "@",
                        t: "s",
hehongwei's avatar
hehongwei committed
933
                    },
chengwenlong's avatar
chengwenlong committed
934 935 936 937 938 939 940
                    fs: 8,
                    ff: "微软雅黑",
                    tb: 2,
                    v: "",
                    qp: 1,
                    m: "",
                },
hehongwei's avatar
hehongwei committed
941 942 943 944 945
            };

            // 获取当前日期并格式化为 YYYY-MM-DD 的字符串
            const currentDate = new Date();
            const year = currentDate.getFullYear(); // 获取当前年份
chengwenlong's avatar
chengwenlong committed
946 947 948
            const month = (currentDate.getMonth() + 1)
                .toString()
                .padStart(2, "0"); // 获取当前月份,记得要加 1
hehongwei's avatar
hehongwei committed
949 950 951 952
            const day = currentDate.getDate(); // 获取当前日期
            const formattedDate = `${year}-${month}-${day}`;
            // 生成唯一标识符uuid
            function generateUniqueShortUuid() {
chengwenlong's avatar
chengwenlong committed
953
                return uuidv4().replace(/-/g, "").substring(0, 12);
hehongwei's avatar
hehongwei committed
954 955 956 957 958
            }
            const uuid = generateUniqueShortUuid();

            // 创建data1数组
            const data1 = [
chengwenlong's avatar
chengwenlong committed
959 960 961 962 963 964 965 966 967 968 969 970
                uuid,
                this.select,
                this.select,
                this.date,
                "",
                this.phone,
                "转本月材料分配",
                "CNY",
                "E001",
                "1.00000000",
                formattedDate,
                uuid,
hehongwei's avatar
hehongwei committed
971
            ];
chengwenlong's avatar
chengwenlong committed
972
            const newData = duplicateData.map((obj) => {
hehongwei's avatar
hehongwei committed
973 974 975 976 977 978 979 980
                const [name, department] = obj.v.name.split("-");
                return {
                    r: obj.r,
                    c: obj.c,
                    //金额
                    money: obj.v.v,
                    name,
                    indexRow: obj.index,
chengwenlong's avatar
chengwenlong committed
981
                    indexcoloumn: obj.coloumn,
hehongwei's avatar
hehongwei committed
982 983 984 985 986 987 988 989
                    department,
                    material: obj.v.material,
                    mining: obj.mining,
                    //uuid
                    accountuuid: data1[0],
                    accountdate: this.date,
                };
            });
chengwenlong's avatar
chengwenlong committed
990 991
            this.ImportTables.exportUuid = data1[0];
            this.generate.exportUuid = data1[0];
hehongwei's avatar
hehongwei committed
992
            this.ImportTables.identifyingCode = 0;
chengwenlong's avatar
chengwenlong committed
993 994 995 996
            this.ImportTables.date = this.date;
            this.ImportTables.mining = this.select;
            this.ImportTables.tylkStatus = 3;
            this.generate.tylkStatus = 3;
hehongwei's avatar
hehongwei committed
997
            this.generate.identifyingCode = 1;
chengwenlong's avatar
chengwenlong committed
998 999 1000 1001
            this.generate.date = this.date;
            this.generate.mining = this.select;
            // , this.generate
            let list = [this.ImportTables];
hehongwei's avatar
hehongwei committed
1002
            let filteredArr;
chengwenlong's avatar
chengwenlong committed
1003 1004 1005
            accountingcode(newData).then((response) => {
                // 合并起来的每行的值转换成一行一个编码 知道哪行合并了起来
                filteredArr = response.rows.map((obj) =>
hehongwei's avatar
hehongwei committed
1006 1007
                    Object.entries(obj)
                        .filter(([key, value]) => value !== null)
chengwenlong's avatar
chengwenlong committed
1008 1009 1010 1011
                        .reduce(
                            (acc, [key, value]) => ({ ...acc, [key]: value }),
                            {}
                        )
hehongwei's avatar
hehongwei committed
1012
                );
1013
                if (sum.length == 1 ) {
chengwenlong's avatar
chengwenlong committed
1014
                    filteredArr.pop();
1015
                }
chengwenlong's avatar
chengwenlong committed
1016
                this.ImportTables.historyRole = filteredArr.map((item) => {
hehongwei's avatar
hehongwei committed
1017 1018 1019 1020
                    let extractedItem = {};
                    if (item.accountingCode) {
                        extractedItem.accountingCode = item.accountingCode;
                    }
chengwenlong's avatar
chengwenlong committed
1021 1022 1023
                    if (item.indexcoloumn) {
                        extractedItem.indexcoloumn = item.indexcoloumn;
                    }
hehongwei's avatar
hehongwei committed
1024
                    if (Array.isArray(item.indexRow)) {
chengwenlong's avatar
chengwenlong committed
1025
                        extractedItem.indexRow = item.indexRow.join(", ");
hehongwei's avatar
hehongwei committed
1026 1027 1028 1029 1030 1031 1032 1033
                    }
                    if (item.name) {
                        extractedItem.name = item.name;
                    }
                    return extractedItem;
                });
                let historyContent = [];
                for (let i = 0; i < this.ImportTables.historyRole.length; i++) {
chengwenlong's avatar
chengwenlong committed
1034 1035 1036 1037 1038 1039 1040 1041
                    // && this.ImportTables.historyRole[i].accountingCode
                    if (this.ImportTables.historyRole[i].indexRow) {
                        const indexRowArray =
                            this.ImportTables.historyRole[i].indexRow.split(
                                ", "
                            );
                        const indexcoloumn =
                            this.ImportTables.historyRole[i].indexcoloumn;
hehongwei's avatar
hehongwei committed
1042 1043 1044
                        for (let j = 0; j < indexRowArray.length; j++) {
                            let historyRole = {
                                value: `${this.ImportTables.historyRole[i].accountingCode},${this.ImportTables.historyRole[i].name}`,
chengwenlong's avatar
chengwenlong committed
1045 1046
                                key: String(indexRowArray[j]),
                                coloumn: String(indexcoloumn),
hehongwei's avatar
hehongwei committed
1047 1048 1049 1050 1051 1052 1053
                            };
                            historyContent.push(historyRole);
                        }
                    }
                }
                //     //范矿重复数据
                // 使用 filter 方法对 historyContent 数组进行过滤
chengwenlong's avatar
chengwenlong committed
1054 1055 1056 1057 1058 1059
                historyContent = historyContent.filter((itemA) => {
                    return !this.historyContent.some(
                        (itemB) =>
                            itemA.key === itemB.key &&
                            itemA.value === itemB.value
                    );
hehongwei's avatar
hehongwei committed
1060
                });
chengwenlong's avatar
chengwenlong committed
1061 1062
                this.historyContent.push(...historyContent);
                this.ImportTables.historyRole = JSON.stringify(historyContent);
hehongwei's avatar
hehongwei committed
1063 1064 1065 1066 1067 1068 1069 1070
                for (let i = 0; i < sum.length; i++) {
                    for (let j = 0; j < filteredArr.length; j++) {
                        if (sum[i].code === filteredArr[j].accountingCode) {
                            sum[i].index = j;
                            break;
                        }
                    }
                }
1071

chengwenlong's avatar
chengwenlong committed
1072
                let isArray = [];
hehongwei's avatar
hehongwei committed
1073 1074
                for (let i = 0; i < filteredArr.length; i++) {
                    let newRow1 = {
chengwenlong's avatar
chengwenlong committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
                        r: 8 + i,
                        c: money,
                        v: {
                            ct: Fusion.v.ct,
                            bg: Fusion.v.bg,
                            fs: Fusion.v.fs,
                            ff: Fusion.v.ff,
                            ht: Fusion.v.ht,
                            vt: Fusion.v.vt,
                            tb: Fusion.v.tb,
                            v: duplicateData[i]?.v.v,
                            qp: Fusion.v.qp,
                            m: duplicateData[i]?.v.m,
                        },
hehongwei's avatar
hehongwei committed
1089 1090
                    };
                    let newRow2 = {
chengwenlong's avatar
chengwenlong committed
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
                        r: 8 + i,
                        c: money1,
                        v: {
                            ct: Fusion.v.ct,
                            bg: Fusion.v.bg,
                            fs: Fusion.v.fs,
                            ff: Fusion.v.ff,
                            ht: Fusion.v.ht,
                            vt: Fusion.v.vt,
                            tb: Fusion.v.tb,
                            v: duplicateData[i]?.v.v,
                            qp: Fusion.v.qp,
                            m: duplicateData[i]?.v.m,
                        },
hehongwei's avatar
hehongwei committed
1105 1106 1107 1108 1109
                    };

                    for (let l = 0; l < need.length; l++) {
                        let needIndex = l % need.length;
                        let newRow3 = {
chengwenlong's avatar
chengwenlong committed
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
                            r: 8 + i,
                            c: need[l],
                            v: {
                                ct: Fusion.v.ct,
                                bg: Fusion.v.bg,
                                fs: Fusion.v.fs,
                                ff: Fusion.v.ff,
                                ht: Fusion.v.ht,
                                vt: Fusion.v.vt,
                                tb: Fusion.v.tb,
                                v: data1[l],
                                qp: Fusion.v.qp,
                                m: Fusion.v.m,
                            },
hehongwei's avatar
hehongwei committed
1124 1125 1126 1127
                        };

                        isArray.push(newRow3);
                    }
chengwenlong's avatar
chengwenlong committed
1128
                    isArray.push(newRow1, newRow2);
hehongwei's avatar
hehongwei committed
1129 1130 1131 1132 1133 1134
                }

                for (let i = 0; i < filteredArr.length; i++) {
                    const codeValue = filteredArr[i]?.accountingCode;
                    if (codeValue) {
                        const newRow = {
chengwenlong's avatar
chengwenlong committed
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
                            r: 8 + i,
                            c: 12,
                            v: {
                                ct: Fusion.v.ct,
                                bg: Fusion.v.bg,
                                fs: Fusion.v.fs,
                                ff: Fusion.v.ff,
                                ht: Fusion.v.ht,
                                vt: Fusion.v.vt,
                                tb: Fusion.v.tb,
                                v: codeValue,
                                qp: Fusion.v.qp,
                                m: Fusion.v.m,
                            },
hehongwei's avatar
hehongwei committed
1149 1150 1151 1152 1153 1154
                        };
                        isArray.push(newRow);
                    }
                }
                const result = [];
                filteredArr.forEach((obj, index) => {
chengwenlong's avatar
chengwenlong committed
1155 1156 1157 1158 1159 1160
                    Object.keys(obj).forEach((key) => {
                        if (
                            typeof obj[key] == "string" &&
                            obj[key] &&
                            obj[key].includes(",")
                        ) {
hehongwei's avatar
hehongwei committed
1161
                            const [prop, val] = obj[key].split(",");
chengwenlong's avatar
chengwenlong committed
1162
                            const propName = prop.trim().replace("*", ""); // 去除属性名中的星号(*)
hehongwei's avatar
hehongwei committed
1163 1164 1165 1166
                            result.push({ [propName]: val.trim(), row: index });
                        }
                    });
                });
chengwenlong's avatar
chengwenlong committed
1167 1168 1169 1170
                let cleanedData = result.filter((entry) => {
                    return Object.values(entry).every(
                        (value) => value !== "null" && value !== null
                    );
hehongwei's avatar
hehongwei committed
1171
                });
chengwenlong's avatar
chengwenlong committed
1172
                let name = [];
hehongwei's avatar
hehongwei committed
1173 1174
                for (let i = 0; i < cleanedData.length; i++) {
                    for (let key in cleanedData[i]) {
chengwenlong's avatar
chengwenlong committed
1175 1176 1177
                        let columns = filteredData.filter(
                            (obj) => obj.v.v === key
                        )[0]?.c;
hehongwei's avatar
hehongwei committed
1178
                        if (columns && columns !== oldClassification) {
chengwenlong's avatar
chengwenlong committed
1179
                            name.push(columns);
hehongwei's avatar
hehongwei committed
1180 1181
                        }
                        if (columns === oldClassification) {
chengwenlong's avatar
chengwenlong committed
1182
                            name.push(Classification);
hehongwei's avatar
hehongwei committed
1183 1184 1185
                        }
                    }
                }
chengwenlong's avatar
chengwenlong committed
1186 1187 1188
                cleanedData = cleanedData.filter(
                    (obj) => Object.keys(obj)[0] !== ""
                );
hehongwei's avatar
hehongwei committed
1189 1190
                for (let i = 0; i < name.length; i++) {
                    const newRow = {
chengwenlong's avatar
chengwenlong committed
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
                        r: 8 + cleanedData[i].row,
                        c: name[i],
                        v: {
                            ct: Fusion.v.ct,
                            bg: Fusion.v.bg,
                            fs: Fusion.v.fs,
                            ff: Fusion.v.ff,
                            ht: Fusion.v.ht,
                            vt: Fusion.v.vt,
                            tb: Fusion.v.tb,
                            v: Object.values(cleanedData[i])[0],
                            qp: Fusion.v.qp,
                            m: Object.values(cleanedData[i])[0],
                        },
hehongwei's avatar
hehongwei committed
1205 1206 1207 1208 1209
                    };
                    isArray.push(newRow);
                }
                for (let i = 0; i < sum.length; i++) {
                    const newRow = {
chengwenlong's avatar
chengwenlong committed
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
                        r: 8 + sum[i].index,
                        c: loan,
                        v: {
                            ct: Fusion.v.ct,
                            bg: Fusion.v.bg,
                            fs: Fusion.v.fs,
                            ff: Fusion.v.ff,
                            ht: Fusion.v.ht,
                            vt: Fusion.v.vt,
                            tb: Fusion.v.tb,
                            v: sum[i].v,
                            qp: Fusion.v.qp,
                            m: sum[i].v,
                        },
hehongwei's avatar
hehongwei committed
1224 1225
                    };
                    const newRow1 = {
chengwenlong's avatar
chengwenlong committed
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
                        r: 8 + sum[i].index,
                        c: loan1,
                        v: {
                            ct: Fusion.v.ct,
                            bg: Fusion.v.bg,
                            fs: Fusion.v.fs,
                            ff: Fusion.v.ff,
                            ht: Fusion.v.ht,
                            vt: Fusion.v.vt,
                            tb: Fusion.v.tb,
                            v: sum[i].v,
                            qp: Fusion.v.qp,
                            m: sum[i].v,
                        },
hehongwei's avatar
hehongwei committed
1240 1241 1242
                    };
                    isArray.push(newRow, newRow1);
                }
1243 1244


chengwenlong's avatar
chengwenlong committed
1245
                VoucherForm[0].celldata.push(...isArray);
1246

chengwenlong's avatar
chengwenlong committed
1247
                if (this.value.includes("凭证")) {
hehongwei's avatar
hehongwei committed
1248 1249 1250
                    luckysheet.create({
                        container: "luckysheet", // Luckysheet 的容器元素 ID
                        title: fileName, // Excel 文件名
chengwenlong's avatar
chengwenlong committed
1251
                        allowEdit: false, //作用:是否允许前台编辑
hehongwei's avatar
hehongwei committed
1252 1253
                        data: VoucherForm, // Excel 数据
                        showinfobar: false, //是否显示顶部名称栏
chengwenlong's avatar
chengwenlong committed
1254
                        lang: "zh",
hehongwei's avatar
hehongwei committed
1255 1256
                    });

chengwenlong's avatar
chengwenlong committed
1257
                    modify = true;
hehongwei's avatar
hehongwei committed
1258 1259
                    this.showMask = false;
                }
1260
                console.log(list,'11111111111')
chengwenlong's avatar
chengwenlong committed
1261
                addInsert(list).then((response) => {
hehongwei's avatar
hehongwei committed
1262 1263
                    if (response.code == 200) {
                        this.$message({
chengwenlong's avatar
chengwenlong committed
1264 1265 1266
                            message: "保存成功",
                            type: "success",
                        });
hehongwei's avatar
hehongwei committed
1267 1268
                    }
                });
chengwenlong's avatar
chengwenlong committed
1269
                if (this.mining !== "011701") {
1270

chengwenlong's avatar
chengwenlong committed
1271 1272
                    this.historyContent = [];
                    this.duplicateData = [];
hehongwei's avatar
hehongwei committed
1273
                }
chengwenlong's avatar
chengwenlong committed
1274
                VoucherForm[0].celldata = [];
hehongwei's avatar
hehongwei committed
1275
            });
1276 1277 1278 1279 1280 1281 1282 1283 1284
        },
        handleExport: debounce(function () {
            // handleExport
            let mineId = JSON.stringify(this.mining)

            datahistoryContentCopy({ mineId }).then(res => {
            })
            exportExcel(luckysheet.getAllSheets(), fileName);
        }, 500),
chengwenlong's avatar
chengwenlong committed
1285
    },
1286 1287
};
// 配置项111
hehongwei's avatar
hehongwei committed
1288

1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
function getss(data) {
    let setXColumnObj = setXColumn(data, 2, '', 0, 9)
    let arrkses = Object.keys(setXColumnObj)
    let arr = []
    for (let rowIndex = 3; rowIndex < 34; rowIndex++) {
        let obj = {}
        arrkses.forEach(item => {
            let cell = data[rowIndex][setXColumnObj[item]];
            if (!item.includes('分配金额') && ['安全费用'] && ['内投工程材料'] && ['研发支出']) {
                // 去除
                if (!['分配金额', '安全费用', '内投工程材料', '研发支出'].find((key) => item.includes(key))) {
                    obj[item] = cell && cell.v || ''
                }
            }
        })
chengwenlong's avatar
chengwenlong committed
1304

1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
        if (!/^\d/.test(obj['费用列支'])) {
            arr.push(obj)
        }
    }
    return arr
}
function workbookCreateAfter(operate, mining) {
    let gets = getss(operate[0].data)
    let neearray = []
    gets.forEach(item => {
        let value = Object.values(item)
        // 找到括号内的内容
        let start = value[0].indexOf('(');
        let end = value[0].indexOf(')');
        let obj = ''
        let contentBeforeParentheses = ''
        if (start !== -1 && end !== -1) {
            let contentWithinParentheses = value[0].substring(start + 1, end);
            obj = contentWithinParentheses.split(',');
            obj = obj.map(newitem => newitem.trim());
        }
        let parenthesesIndex = value[0].indexOf('(');
        if (parenthesesIndex !== -1) {
            contentBeforeParentheses = value[0].substring(0, parenthesesIndex).trim();
        }
        let key = Object.keys(item)
        value.forEach((items, index) => {
            if (items && index != 0) {
                let funs = {
                    v: {
                        v: items,
                        name: key[index] + '-',
                        material: contentBeforeParentheses,
                    },
                    mining: mining,
                    r: ''
                }
                funs.v.material = funs.v.material.includes('净化车间') ? '净化车间' : funs.v.material
                if (index == 1) {
                    funs.r = obj[0]
                } else {
                    funs.r = obj[1] ? obj[1] : obj[0]
                }
                neearray.push(funs)
            }
chengwenlong's avatar
chengwenlong committed
1350
        })
1351 1352 1353 1354
    })
    return neearray
}

hehongwei's avatar
hehongwei committed
1355
// debounce函数定义
1356

hehongwei's avatar
hehongwei committed
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
function debounce(func, delay) {
    let timer;
    return function () {
        const context = this;
        const args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            func.apply(context, args);
        }, delay);
    };
}
function getKeyByValue(map, value) {
    for (let [key, val] of map) {
        if (val === value) {
            return key;
        }
        if (Array.isArray(val) && val.includes(value)) {
            return key;
        }
    }
}
function generateUUID() {
    let array = new Uint32Array(4);
    window.crypto.getRandomValues(array);
    return array.join("-");
1382
}