index_vue.vue 93 KB
Newer Older
1 2 3 4 5 6
<template>
    <div class="app-container">

        <el-form ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="模板" prop="name">
                <el-select v-model="selectedOption" ref="mySelect" size="mini" @change="handleOptionChange" filterable
hehongwei's avatar
hehongwei committed
7
                           placeholder="请选择您要查看的模板">
8 9 10 11
                    <el-option v-for="item in depss" :key="item.id" :label="item.templateName" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
位宇华's avatar
位宇华 committed
12 13
            <el-form-item label="清洗规则" prop="roleid">
                <el-select v-model="selectedRule" ref="mySelect" size="mini" @change="handleRuleChange" filterable
hehongwei's avatar
hehongwei committed
14
                           placeholder="请选择您要查看的规则">
位宇华's avatar
位宇华 committed
15 16 17 18
                    <el-option v-for="iem in luckyrule" :key="iem.id" :label="iem.roleName" :value="iem.id">
                    </el-option>
                </el-select>
            </el-form-item>
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
            <el-form-item label="时间" prop="date">
                <el-date-picker @change="handledateChange" v-model="date" type="month" placeholder="选择月">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="所属矿区" prop="mining">
                <el-select v-model="mining" placeholder="请选择矿区" @change="handleminingChange">
                    <el-option v-for="item in miningValue" :key="item.id" :label="item.name" :value="item.id">

                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-upload2" size="mini" @click="handleExport">导出</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-upload type="file" name="file" ref="upload" :before-upload="handleFileChange" action='' accept='.xlsx'
hehongwei's avatar
hehongwei committed
40
                           :limit="1" :file-list="fileList" :disabled="disableNextButton" :show-file-list=false>
41
                    <el-button plain size="mini" icon="el-icon-download" type="primary" :disabled="disableNextButton"
hehongwei's avatar
hehongwei committed
42
                               @click="rulesdate">导入</el-button>
43 44 45 46
                </el-upload>
                <el-button :plain="true" style="display: none;" @click="open4">错误</el-button>

            </el-col>
位宇华's avatar
位宇华 committed
47
            <el-button plain size="mini" type="primary" @click="dialogTableVisible = true">查看</el-button>
48
        </el-row>
位宇华's avatar
位宇华 committed
49 50 51 52 53 54 55 56 57 58 59 60 61
        <el-dialog title="详细信息" :visible.sync="dialogTableVisible">
            <el-table :data="detail">
                <el-table-column property="v.name" label="行"></el-table-column>
                <el-table-column property="v.material" label="列"></el-table-column>
                <el-table-column property="v.v" label="金额"></el-table-column>
                <el-table-column label="合并的行">
                    <template slot-scope="scope">
                        {{ scope.row.index.map(index => index + 1).join(', ') }}
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>

62 63 64 65 66 67 68 69 70 71 72 73
        <!-- luckysheet容器 -->
        <div id="luckysheet" style="margin: 0px; padding: 0px; position: absolute; width: 100%; height:80vh; z-index: 0">
        </div>
        <div v-if="showMask" class="mask">
            <div class="loading-spinner"></div>
        </div>

    </div>
</template>


<script>
hehongwei's avatar
hehongwei committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    import { selectActSuppliesHistorydata, selectActSuppliesHistorydataAcc } from "@/api/Actsupplies/cleaning_rule";
    import { getSuppliesTemplate, listSuppliesTemplate, roleList, materialConvert, materialListPZ, accountingcode, department, roleListid, materialList } from "@/api/ruoyi-myLuckyexcel/myluckyexcel";
    import { addInsert, addInsert1, addInsert2, addInsertAccount1, addInsertAccount2 } from "@/api/system/historydata"
    /*import luckysheet from 'luckysheet'*/
    import LuckyExcel from 'luckyexcel'
    //导入库export.js 这个文件是es6的,不能在普通的HTML文件直接引入js文件(虽然都是js文件,但是有区别,具体请百度es6与es5)!需要把es6转es5才可以直接引入使用!
    /*import {materialList} from "@/api/ruoyi-myLuckyexcel/myluckyexcel";*/
    import { exportExcel } from '../../../../public/exportExcel';
    import { v4 as uuidv4 } from 'uuid';
    import { getInfo } from "@/api/login";
    import { listSuppliesexpense } from "../../../api/ActClassification/ActClassification";
    var fileName = "新建XLSX工作表"; //定义表名
    var rule = [];
    var tempId;
    var roleId;
    var uuid1;
    var trueORfalse = false;
    var modify = false;
    export default {
        name: "Mymodule",
        data() {
            return {
                //详细信息
                dialogTableVisible: false,
                //清洗规则名字
                selectname: '',
                //详情页
                detail: [],
                //kuang
                mine: '',
                num: 1,
                nums: 1,
                value: '',
                VoucherForm: '',
                miningValue: [
109

hehongwei's avatar
hehongwei committed
110 111 112 113
                    {
                        name: '林西矿',
                        id: '011704'
                    },
位宇华's avatar
位宇华 committed
114

hehongwei's avatar
hehongwei committed
115 116 117 118 119 120 121 122 123 124 125 126
                    {
                        name: '唐山矿',
                        id: '010101'
                    },
                    {
                        name: '东欢坨矿',
                        id: '010102'
                    },
                    {
                        name: '单侯矿',
                        id: '011204'
                    }
hehongwei's avatar
hehongwei committed
127

hehongwei's avatar
hehongwei committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
                ],
                Cleaningrole: '',
                phone: '',
                classify: '',
                userName: '',
                //选择的矿区
                select: '',
                //转换完成成本材料的所有数据
                middle: '',
                //未导入成本材料表模板所有数据
                jsondata: '',
                //编码数据
                codess: '',
                luckyrule: [],
                showMask: false,
                //选中的表的数据
                selected: '',
                uuid: '',
                //弹出页面的表名
                from_name: "",
                //单侯煤矿的成本表
                newArray: '',
                //往后台穿的导入表的东西
                ImportTables: {},
                //往后台传生成表的数据
                generate: {},
                cleaning: '',
                // 是否显示弹出层
                dialogVisible: false,
                selectedOption: '',
                selectedRule: '',
                luckysheetData: '',
                fileList: [],
                disableNextButton: true,
                depss: [],
                // 表单参数
                from: {},
                date: '',
                mining: '',
                froms: {
                    hId: "",
                    projectId: "",
                    projectName: "",
                    departmentName: "",
                    number: "",
                    nuitPrice: "",
                    money: "",
                    createBy: "",
                    hDate: null,
                    mining: ""
                },
                synthesis: '',
                historyRole: [],
                dfrom: {},
                imp: {},
                ssd: {},
                // 查询参数
                queryParams: {
                    status: 0
                },
hehongwei's avatar
hehongwei committed
188

hehongwei's avatar
hehongwei committed
189
            };
190
        },
hehongwei's avatar
hehongwei committed
191 192 193
        created() {
            //刷新页面时进行的操作
            this.getList();
194
        },
hehongwei's avatar
hehongwei committed
195 196 197 198 199
        mounted() {

            this.init();
            fileName = "新建XLSX工作表";
            this.list()
位宇华's avatar
位宇华 committed
200
        },
hehongwei's avatar
hehongwei committed
201 202 203 204 205 206
        methods: {
            //查询材料编码
            list() {
                materialListPZ().then(response => {
                    this.codess = response.rows
                })
207 208


hehongwei's avatar
hehongwei committed
209

hehongwei's avatar
hehongwei committed
210
                //查用户名称
hehongwei's avatar
hehongwei committed
211

hehongwei's avatar
hehongwei committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
                getInfo().then(response => {
                    this.userName = response.user.nickName
                })
                getSuppliesTemplate(1248).then(response => {
                    const sysSupplies = response.rows;
                    this.luckysheetData = sysSupplies[0].templateContent;
                    let VoucherForm = JSON.parse(sysSupplies[0].templateContent);
                    this.VoucherForm = JSON.stringify(VoucherForm)
                })
                getSuppliesTemplate(1257).then(response => {
                    this.generate.historyName = response.rows[0].templateName + '(生成文件)';
                    const sysSupplies = response.rows;
                    this.luckysheetData = sysSupplies[0].templateContent;
                    //将接收到的json存到json_data中
                    //const json_data = response.data;
                    this.jsondata = JSON.parse(sysSupplies[0].templateContent);
                })
                //单侯煤矿需要的东西
                getSuppliesTemplate(1264).then(response => {
                    const sysSupplies = response.rows;
                    this.newArray = JSON.parse(sysSupplies[0].templateContent);
                })
hehongwei's avatar
hehongwei committed
234 235


hehongwei's avatar
hehongwei committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 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
            },
            //手机号
            open(evt) {
                this.$prompt('请输入用友系统的用户名', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /^(?:\+?86)?1[3-9]\d{9}$/,
                    inputErrorMessage: '手机号格式不正确'
                }).then(({ value }) => {
                    this.$message({
                        type: 'success',
                        message: '你的用户名是: ' + value
                    });
                    this.phone = value
                    this.zhuan(evt)
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消输入'
                    });
                    this.showMask = false
                });
            },
            /** 判断是否选择时间*/
            rulesdate() {

                const minvalue = this.miningValue.find(obj => obj.id === this.mining)
                const Luckysheetlabel = this.luckyrule.find(obj => obj.id === this.selectedRule);

                if (this.date == '' || this.date == null) {
                    this.disableNextButton = true;
                    this.$message.error('请选择时间日期!');
                } else if (this.mining == '' || this.mining == null) {
                    this.disableNextButton = true;
                    this.$message.error('请选择所属矿区!');
                } else if (this.cleaning == '') {
                    this.disableNextButton = true;
                    this.$message.error('请选则清洗规则!');
                }
            },
            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;


                this.date = formattedDate
                if (this.date == '' || this.date == null || this.date == undefined) {
                    this.disableNextButton = true;
hehongwei's avatar
hehongwei committed
290
                } else {
hehongwei's avatar
hehongwei committed
291
                    this.disableNextButton = false;
hehongwei's avatar
hehongwei committed
292
                }
hehongwei's avatar
hehongwei committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
            },
            handleminingChange(value) {
                department(value).then(response => {
                    this.classify = response
                })
                const selectedItem = this.miningValue.find(item => item.id === value);
                if (selectedItem) {
                    this.mine = selectedItem.name
                }
                this.select = value
                if (this.date == '' || this.date == null || this.date == undefined) {
                    this.disableNextButton = true;
                } else {
                    this.disableNextButton = false;
                }
            },

            /** 页面刷新时展示的数据*/
            getList() {
                listSuppliesTemplate(this.queryParams).then(response => {
                    this.depss = response.rows;
314 315
                });

hehongwei's avatar
hehongwei committed
316 317 318 319 320 321
            },
            /** 下拉选和页面luckysheet绑定 */
            handleOptionChange(value) {
                this.date = ''
                this.mining = ''
                this.value = value
hehongwei's avatar
hehongwei committed
322
                this.selectedRule = '';
hehongwei's avatar
hehongwei committed
323 324 325 326 327 328 329 330
                this.disableNextButton = this.selectedRule === '';
                //根据选中的下拉选项值获取相应的信息
                getSuppliesTemplate(this.selectedOption).then(response => {
                    //如果为六矿汇总表,导出时隐藏前两列
                    if (this.selectedOption === 7 || this.selectedOption === 10) {
                        trueORfalse = true;
                    } else {
                        trueORfalse = false;
hehongwei's avatar
hehongwei committed
331 332
                    }
                    modify = false;
hehongwei's avatar
hehongwei committed
333 334 335
                    tempId = this.selectedOption;
                    uuid1 = this.uuid = uuidv4().substring(0, 8);

336 337
                    const sysSupplies = response.rows;
                    this.luckysheetData = sysSupplies[0].templateContent;
hehongwei's avatar
hehongwei committed
338 339 340 341 342 343 344 345 346
                    //将接收到的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()
347 348 349 350 351 352 353 354 355 356 357
                    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
358 359 360 361 362 363 364 365 366 367
            },
            open4() {
                this.$message.error('找不到部门名称或者结算金额和材料编码列,请改为正确名称');
            },
            /** 规则下拉选 调佣后端的方法*/
            handleRuleChange(value) {
                const selectedItem = this.luckyrule.find(item => item.id === value);
                if (selectedItem) {
                    this.selectname = selectedItem.roleName
                }
位宇华's avatar
位宇华 committed
368

hehongwei's avatar
hehongwei committed
369 370 371 372 373
                if (this.selectedOption === '') {
                    this.selectedRule = '';
                    this.$message.warning("选择规则前请先选择模板!");
                    return; // 如果按钮被禁用,提前返回,避免执行下一步操作
                }
位宇华's avatar
位宇华 committed
374

hehongwei's avatar
hehongwei committed
375 376 377 378 379 380 381
                this.disableNextButton = this.selectedRule === '';
                roleListid(this.selectedRule).then(response => {
                    roleId = this.selectedRule;
                    rule = response.rows;
                    //清洗规则
                    this.cleaning = JSON.parse(response.rows[0].detailContent)
                    this.ImportTables.convenRole = response.rows[0].detailContent
位宇华's avatar
位宇华 committed
382

hehongwei's avatar
hehongwei committed
383 384 385 386 387 388 389 390 391 392 393 394 395
                });
                if (tempId === 7 || tempId === 10) {
                    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;
                            }
                        }
                        modify = false;
396 397 398 399 400 401 402 403 404 405
                        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',
                        });
hehongwei's avatar
hehongwei committed
406 407 408 409 410 411 412 413
                    }).catch(() => {
                        // 处理错误逻辑,这里是一个空的错误处理函数
                        this.$message.error('查询失败,发生未知错误!');
                    });
                }


            },
hehongwei's avatar
hehongwei committed
414

hehongwei's avatar
hehongwei committed
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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
            /** 重置按钮操作 */
            resetQuery() {
                //刷新下拉选框内容
                fileName = "新建XLSX工作表";
                this.selectedOption = '';
                this.disableNextButton = '';
                this.luckyrule = [];

                this.selectedRule = '';
                trueORfalse = false;
                modify = false;
                uuid1 = '';
                //刷新luckysheet表格
                this.init();
            },




            /** Luckyexcel文档 */
            init() {
                let options = {
                    container: 'luckysheet', //luckysheet为容器id
                    title: '',
                    lang: 'zh',
                    showinfobar: false,
                    data: [
                        {
                            "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": {}, //工作表保护
                            },
                        },

                    ]

                }
                luckysheet.create(options);

            },
            async handleFileChange(evt) {
                if (modify) {
                    this.$confirm('再次导入将会清空表内数据,是否继续操作?', '注意!!!', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
483
                    }).then(async () => {
hehongwei's avatar
hehongwei committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
                        // 确认继续后刷新页面返回模板
                        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 () => {
502 503


hehongwei's avatar
hehongwei committed
504 505
                        }).catch(() => {
                        });
506
                    }).catch(() => {
hehongwei's avatar
hehongwei committed
507 508
                        // 用户点击了取消按钮
                        this.$message({ type: 'info', message: '操作已取消' });
509
                    });
hehongwei's avatar
hehongwei committed
510 511 512 513 514 515
                } else {
                    this.open(evt)
                    this.showMask = true;
                    LuckyExcel(evt, exportJson => {
                        //获取导入表格所有数据exportJson
                        this.open(exportJson)
516
                        // this.summary(exportJson)
hehongwei's avatar
hehongwei committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530
                            .then(async () => {

                                // this.submit(exportJson);
                            })
                            .catch(error => {
                                this.$message({
                                    message: error.message,
                                    type: "error"
                                });

                            })
                            .finally(() => {
                                // 导入完成后关闭遮罩层
                                this.showMask = false;
位宇华's avatar
位宇华 committed
531
                            });
hehongwei's avatar
hehongwei committed
532
                    });
533

hehongwei's avatar
hehongwei committed
534
                }
535

hehongwei's avatar
hehongwei committed
536 537 538 539 540 541 542 543 544
            },
            //转换方法 cc是导入表数据
            // 唐山矿转入方法
            zhuan(file) {
                let cc = '';
                const transformPromise = new Promise((resolve, reject) => {
                    LuckyExcel.transformExcelToLucky(file, (lucksheetfile) => {
                        resolve(lucksheetfile);
                    });
545
                });
hehongwei's avatar
hehongwei committed
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
                transformPromise.then((result) => {
                    let resultJSON = JSON.stringify(result.sheets)
                    cc = result;
                    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;
                            }
位宇华's avatar
位宇华 committed
561
                        }
hehongwei's avatar
hehongwei committed
562 563 564 565 566 567 568 569 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
                    });
                    let c = cc.sheets[0].celldata
                    //表头所在行
                    let headRow = this.cleaning[0].HeaderRow - 1
                    //部门名称列
                    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 && obj.c === codecolumn && obj.r > headRow)
                    //林西的类别名称
                    let names = c.flat().filter(obj => obj.v && (obj.v.v === "类别名称" || obj.v.v === "收发类别"))[0]?.c;
                    let name = c.flat().filter(obj => obj.c && obj.c === names && obj.r > headRow)
                    //数量所在列
                    let numbercolumn = this.cleaning[0].NumberColumn - 1
                    let number = c.flat().filter(obj => obj.c && obj.c === numbercolumn && obj.r > headRow)
                    //单价所在列
                    let MoneyColumn = this.cleaning[0].MoneyColumn - 1
                    let moneys = c.flat().filter(obj => obj.c && obj.c === MoneyColumn && obj.r > headRow)
                    //算总额
                    let money = []
                    number.forEach((n, index) => {
                        if (n.r === moneys[index].r) {
                            moneys[index].v.v = (moneys[index].v.v * n.v.v).toFixed(2)
                            money.push(moneys[index])
                        }
                    })
                    // 唐山矿转换方法
                    //没任何规则
                    if (this.mine.includes('唐山') && this.selectname.includes('唐山')) {
                        if (code && money && Department) {
                            let newobj = []
                            //把这三个数组push到newobj里
                            newobj.unshift(money);
                            newobj.unshift(code);
                            newobj.unshift(Department);
                            //跟材料表的数据对比  如果编码一样 则把导入表的列数换成模板的列数
                            codess.forEach(c => {
                                let codeLength = String(c.code).length;
                                let codeToCompare = String(c.code).substring(0, codeLength);
                                newobj[1].forEach(column => {
                                    let columnIdString = String(column.v.v);
                                    let idToMatch = columnIdString.substring(0, codeLength);
                                    if (idToMatch === codeToCompare) {
                                        column.ccc = c.oneLevel * 1;
                                    }
                                });
位宇华's avatar
位宇华 committed
609
                            });
610

hehongwei's avatar
hehongwei committed
611 612 613 614 615 616 617 618 619 620 621 622
                            //按照部门划分,去找到他所在科室分类
                            newobj = newobj.map(subArr => {
                                return subArr.map(obj => {
                                    let v = obj.v.v;
                                    for (let key in classify) {
                                        if (classify[key].includes(v)) {
                                            obj.v.m = key;
                                            obj.v.v = key;
                                            obj.v.name = key
                                            obj.whether = true
                                            return obj;
                                        }
hehongwei's avatar
hehongwei committed
623
                                    }
hehongwei's avatar
hehongwei committed
624 625 626 627 628 629 630
                                    obj.whether = false
                                    return obj;
                                });
                            });
                            newobj[2].forEach((item, i) => {
                                if ('name' in newobj[0][i].v) {
                                    item.v.name = newobj[0][i].v.name;
631
                                }
hehongwei's avatar
hehongwei committed
632
                            });
hehongwei's avatar
hehongwei committed
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
                            //直接luck表格初始化 替换数据

                            //找到所在的行数,按照  -的前后去找,前面是标题,后面是标题后的小分类,如选煤,洗煤等
                            CompositeTable[0].data = luckysheet.transToData(he[0]["celldata"])
                            newobj[0].forEach((item) => {
                                if (item.v.m !== undefined) {
                                    let index = item.v.m.indexOf("-");
                                    if (index !== -1) {
                                        let substrBeforeDash = item.v.m.slice(0, index);
                                        let DepartColumns = he[0]["celldata"].flat().find(obj =>
                                            obj.v && obj.v.v && typeof obj.v.v === 'string' && obj.v.v.includes(item.v.m.slice(0, index))
                                        );

                                        if (DepartColumns && DepartColumns.r) {
                                            let index = item.v.m.indexOf("-")
                                            if (index !== -1) {
                                                let substrAfterDash = item.v.m.slice(index + 1);
                                                switch (substrAfterDash) {
                                                    case '':
                                                        item.r = DepartColumns.r;
                                                        break;
                                                    case '原煤':
                                                        item.r = DepartColumns.r + 1;
                                                        break;
                                                    case '洗煤':
                                                        item.r = DepartColumns.r + 2;
                                                        break;
                                                    case '选煤':
                                                        item.r = DepartColumns.r + 3;
                                                        break;
                                                    case '厂区服务':
                                                        item.r = DepartColumns.r + 1;
                                                        break;
                                                    default:
                                                    // 默认情况
                                                }
hehongwei's avatar
hehongwei committed
669
                                            }
670 671 672
                                        }
                                    }
                                }
hehongwei's avatar
hehongwei committed
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
                            });
                            //把原来分类找不到的放到其他数据类型中,最后一列其他列中
                            newobj[1].forEach((item, i) => {
                                if (item.ccc && newobj[0][i].r < 8) {
                                    item.c = item.ccc;
                                    delete item.ccc;
                                } else {
                                    item.c = 10;
                                }
                            });
                            //金额列和行是原先导入表的行列 要替换掉模板表的行列
                            newobj[0].forEach((item, i) => {
                                if (item.whether) {
                                    newobj[2][i].r = item.r;
                                    newobj[2][i].c = newobj[1][i].c;
                                    newobj[2][i].v.v = Number(newobj[2][i].v.v);
                                } else {
                                    newobj[2][i].r = '';
                                    newobj[2][i].c = '';
                                }
                            });
                            //同一个单元格的数据 金额相加。
                            let i = -1
                            let duplicateData = [];
                            let seen = new Map();
                            // 根据行列信息合并重复数据并记录索引
                            for (let obj of newobj[2]) {
                                i += 1;
                                let key = obj.r + ',' + obj.c;
                                if (seen.has(key)) {
                                    let existingObj = seen.get(key);
                                    existingObj.v.v += obj.v.v;
                                    existingObj.v.m = (parseInt(existingObj.v.m) + parseInt(obj.v.m)).toString();
                                    existingObj.index.push(newobj[1][i].r);
                                } else {
                                    obj.index = [newobj[1][i].r];
                                    seen.set(key, obj);
                                }
711
                            }
hehongwei's avatar
hehongwei committed
712 713 714 715
                            // 将合并后的数据放入 duplicateData 数组
                            for (let obj of seen.values()) {
                                if (obj.v.v > 0 || parseInt(obj.v.m) > 0) {
                                    duplicateData.push(obj);
位宇华's avatar
位宇华 committed
716
                                }
hehongwei's avatar
hehongwei committed
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
                            }
                            duplicateData = duplicateData.map(item => {
                                return {
                                    ...item,
                                    v: {
                                        ...item.v,
                                        v: isNaN(item.v.v) ? item.v.v : Number(item.v.v).toFixed(2)
                                    }
                                };
                            });
                            // 替换金额所在列和行相同的模板表中的数据
                            //金额所在列和行,去模板表中查找,如果行列一致则替换
                            for (let i = 0; i < duplicateData.length; i++) {
                                //     // 对比 c 和 r 是否与 CompositeTable[0]["celldata"] 中相应对象相同
                                for (let ii = 0; ii < CompositeTable[0]["celldata"].length; ii++) {
                                    if (duplicateData[i].r === CompositeTable[0]["celldata"][ii].r && duplicateData[i].c === CompositeTable[0]["celldata"][ii].c) {
                                        // 如果相同,则进行替换
                                        CompositeTable[0]["celldata"][ii] = duplicateData[i];
                                    }
hehongwei's avatar
hehongwei committed
736
                                }
737
                            }
hehongwei's avatar
hehongwei committed
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
                            // celldata => data 生成表格所需二维数组
                            CompositeTable[0].data = luckysheet.transToData(CompositeTable[0]["celldata"])
                            if (this.value === 1257) {
                                luckysheet.create({
                                    container: "luckysheet", // Luckysheet 的容器元素 ID
                                    title: fileName, // Excel 文件名
                                    data: CompositeTable, // Excel 数据
                                    showinfobar: false, //是否显示顶部名称栏
                                    lang: 'zh',
                                });
                                modify = true
                                this.showMask = false;

                            }
                            //this.from 往后台村的数据
                            this.ImportTables.historyContent = resultJSON
                            this.generate.historyContent = JSON.stringify(CompositeTable)
                            //往后台传科目编码相关的东西
                            duplicateData.forEach(obj => {
                                CompositeTable[0].celldata.forEach(cell => {
                                    if (obj.c === cell.c && cell.r === 3) {
                                        obj.v.material = cell.v.v;
                                    }
                                });
hehongwei's avatar
hehongwei committed
762
                            });
hehongwei's avatar
hehongwei committed
763 764 765 766
                            this.middle = CompositeTable
                            this.Vouchers(duplicateData)
                        } else {
                            this.open4()
hehongwei's avatar
hehongwei committed
767
                            this.showMask = false;
768
                        }
hehongwei's avatar
hehongwei committed
769
                    }
hehongwei's avatar
hehongwei committed
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
                    //林西矿转换方法
                    //机电制造费用现在是筛选出来了,。没有放到里面,如果想放进去也可以放进去,但是具体划分就不明细了
                    if (this.mine.includes('林西') && this.selectname.includes('林西') && name) {
                        //类别名称,部门名称,不含税金额,存货编码
                        if (name && Department && money && code) {
                            let nameColums = name
                            nameColums = nameColums.flat().filter(obj => obj.v.hasOwnProperty('v'));
                            let name1 = Department
                            // code 编码 name1部门名称 money金额  name1 部门名称
                            // 清空属性
                            money.forEach(entry => {
                                entry.department = '';
                                entry.remark = '';
                                entry.classify = '';
                                entry.code = '';
                            });
786

hehongwei's avatar
hehongwei committed
787 788 789 790 791 792 793 794 795 796 797 798 799
                            // 合并数组
                            let newobj = [...name1, ...nameColums, ...code];

                            // 匹配赋值
                            money.forEach(m => {
                                newobj.forEach(a => {
                                    if (m.r === a.r) {
                                        if (a.c === DepartmentColumns) m.remark = a.v.v || a.v.m;
                                        if (a.c === names) m.classify = a.v.v || a.v.m;
                                        if (a.c === codecolumn) m.code = a.v.v || a.v.m;
                                        m.cc = '';
                                    }
                                });
位宇华's avatar
位宇华 committed
800
                            });
801

hehongwei's avatar
hehongwei committed
802 803 804
                            // 删除指定分类
                            const filteredClassifications = ["研发费用", "基金", "安全费用"];
                            money = money.filter(item => !filteredClassifications.includes(item.classify));
805

hehongwei's avatar
hehongwei committed
806 807 808 809 810
                            // 替换属性值
                            money.forEach(item => {
                                if (item.head === "坑木") item.head = "木材";
                                if (!item.remark) item.v.name = "基本生产-原煤";
                            });
811

hehongwei's avatar
hehongwei committed
812 813 814 815 816 817
                            // 提取特定属性值相同的数据
                            const Electromechanical = "机电制造分公司";
                            const filteredMoney = money.filter(item => {
                                if (item.remark === Electromechanical) {
                                    money.splice(money.indexOf(item), 1);
                                    return true;
hehongwei's avatar
hehongwei committed
818
                                }
hehongwei's avatar
hehongwei committed
819
                                return false;
位宇华's avatar
位宇华 committed
820
                            });
hehongwei's avatar
hehongwei committed
821

hehongwei's avatar
hehongwei committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
                            // 对比替换导入表和模板的列数
                            codess.forEach(code => {
                                let codeLength = String(code.code).length;
                                money.forEach(m => {
                                    let columnIdString = String(m.code);
                                    let idToMatch = columnIdString.substring(0, codeLength);
                                    if (idToMatch === String(code.code).substring(0, codeLength)) {
                                        m.cc = code.oneLevel * 1;
                                    }
                                });
                            });

                            // 设置属性值
                            money.forEach(item => {
                                item.c = item.cc ? item.cc * 1 : 10;
                            });
                            money = money.map(obj => {
                                let v = obj.remark;
                                for (let key in classify) {
                                    if (classify[key].includes(v)) {
                                        obj.v.name = key;
                                        obj.whether = true;
                                        return obj;
                                    }
hehongwei's avatar
hehongwei committed
846
                                }
hehongwei's avatar
hehongwei committed
847 848 849
                                obj.v.name = "基本生产-原煤";
                                return obj;
                            });
850

hehongwei's avatar
hehongwei committed
851 852 853 854 855 856 857 858
                            money.forEach(item => {
                                if (item.department && item.v.name) {
                                    let originalString = item.v.name;
                                    let parts = originalString.split("-");
                                    let replacedString = parts[0] + "-" + item.department;
                                    item.v.name = replacedString;
                                }
                            });
位宇华's avatar
位宇华 committed
859

hehongwei's avatar
hehongwei committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
                            money.forEach(item => {
                                if (item.v.name !== undefined) {
                                    let index = item.v.name.indexOf("-");
                                    if (index !== -1) {
                                        let substrBeforeDash = item.v.name.slice(0, index);
                                        let DepartColumns = CompositeTable[0]["celldata"].flat().filter(obj => {
                                            if (obj.v && obj.v.v && typeof obj.v.v === 'string') {
                                                return obj.v.v.includes(item.v.name.slice(0, index));
                                            }
                                            return false;
                                        })[0];

                                        if (DepartColumns && DepartColumns.r) {
                                            let index = item.v.name.indexOf("-");
                                            if (index !== -1) {
                                                let substrAfterDash = item.v.name.slice(index + 1);
                                                switch (substrAfterDash) {
                                                    case '':
                                                        item.r = DepartColumns.r;
                                                        break;
                                                    case '原煤':
                                                        item.r = DepartColumns.r + 1;
                                                        break;
                                                    case '洗煤':
                                                        item.r = DepartColumns.r + 2;
                                                        break;
                                                    case '选煤':
                                                        item.r = DepartColumns.r + 3;
                                                        break;
                                                    case '厂区服务':
                                                        item.r = DepartColumns.r + 1;
                                                        break;
                                                    case '加工修理':
                                                        item.r = DepartColumns.r + 4;
                                                        break;
                                                    default:
                                                    // 默认情况
                                                }
位宇华's avatar
位宇华 committed
898 899 900 901
                                            }
                                        }
                                    }
                                }
hehongwei's avatar
hehongwei committed
902
                            });
位宇华's avatar
位宇华 committed
903

hehongwei's avatar
hehongwei committed
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
                            money.forEach(item => {
                                if (item.r > 8 && item.c < 10) {
                                    item.c = 10;
                                }
                            });
                            // 同一个单元格,金额相加
                            let seen = new Map();
                            let duplicateData = [];

                            money.forEach((obj, i) => {
                                let key = obj.r + ',' + obj.c;
                                if (seen.has(key)) {
                                    let existingObj = seen.get(key);
                                    existingObj.v.v = Number(existingObj.v.v) + Number(obj.v.v);
                                    existingObj.v.m = existingObj.v.v.toString();
                                    existingObj.index.push(i);
                                } else {
                                    obj.index = [i];
                                    seen.set(key, obj);
                                }
                            });
位宇华's avatar
位宇华 committed
925

hehongwei's avatar
hehongwei committed
926 927 928
                            seen.forEach(obj => {
                                if (obj.v.v > 0 || parseInt(obj.v.m) > 0) {
                                    duplicateData.push(obj);
位宇华's avatar
位宇华 committed
929
                                }
hehongwei's avatar
hehongwei committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
                            });
                            duplicateData = duplicateData.map(item => {
                                return {
                                    ...item,
                                    v: {
                                        ...item.v,
                                        v: isNaN(item.v.v) ? item.v.v : Number(item.v.v).toFixed(2)
                                    }
                                };
                            });
                            //金额所在列和行,去模板表中查找,如果行列一致则替换
                            for (let i = 0; i < duplicateData.length; i++) {
                                //     // 对比 c 和 r 是否与 CompositeTable[0]["celldata"] 中相应对象相同
                                for (let ii = 0; ii < CompositeTable[0]["celldata"].length; ii++) {
                                    if (duplicateData[i].r === CompositeTable[0]["celldata"][ii].r && duplicateData[i].c === CompositeTable[0]["celldata"][ii].c) {
                                        // 如果相同,则进行替换
                                        CompositeTable[0]["celldata"][ii] = duplicateData[i];
                                    }
位宇华's avatar
位宇华 committed
948 949
                                }
                            }
hehongwei's avatar
hehongwei committed
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
                            CompositeTable[0].data = luckysheet.transToData(CompositeTable[0]["celldata"])
                            if (this.value === 1257) {
                                luckysheet.create({
                                    container: "luckysheet", // Luckysheet 的容器元素 ID
                                    title: fileName, // Excel 文件名
                                    data: CompositeTable, // Excel 数据
                                    showinfobar: false, //是否显示顶部名称栏
                                    allowEdit: false,//作用:是否允许前台编辑
                                    lang: 'zh',
                                });
                                modify = true
                                this.showMask = false;

                            }
                            //this.from 往后台村的数据
                            this.ImportTables.historyContent = resultJSON
                            this.generate.historyContent = JSON.stringify(CompositeTable)
                            //往后台传科目编码相关的东西
                            duplicateData.forEach(obj => {
                                CompositeTable[0].celldata.forEach(cell => {
                                    if (obj.c === cell.c && cell.r === 3) {
                                        obj.v.material = cell.v.v;
                                    }
                                });
位宇华's avatar
位宇华 committed
974
                            });
hehongwei's avatar
hehongwei committed
975 976 977 978
                            this.middle = CompositeTable
                            this.Vouchers(duplicateData)
                        } else {
                            this.open4()
位宇华's avatar
位宇华 committed
979 980
                            this.showMask = false;
                        }
hehongwei's avatar
hehongwei committed
981 982 983 984 985 986 987 988 989 990 991
                    }
                    //东欢坨矿转换方法
                    //如果部门为旧品和设备 并且他们的材料为支护用品和大型材料就把他们放到基本生产里
                    if (this.mine.includes('东欢坨') && this.selectname.includes('东欢坨')) {
                        //材料编码,金额,部门
                        if (code && money && Department) {
                            //code 编码 ,,money金额,remark 部门
                            let remark = Department
                            remark.forEach((item) => {
                                if (item.v.v.includes("单项卡")) {
                                    item.v.v = item.v.v.replace(/单项卡/g, '');
位宇华's avatar
位宇华 committed
992 993 994
                                }
                            });

hehongwei's avatar
hehongwei committed
995 996 997 998 999 1000
                            money.forEach((item) => {
                                item.remark = '';
                                item.code = '';
                                item.cc = '';
                                item.v.name = '';
                            });
位宇华's avatar
位宇华 committed
1001

hehongwei's avatar
hehongwei committed
1002 1003 1004 1005 1006 1007 1008
                            for (let i = 0; i < money.length; i++) {
                                if (money[i].r == code[i].r) {
                                    money[i].code = code[i].v.v;
                                }
                                if (money[i].r == remark[i].r) {
                                    money[i].remark = remark[i].v.v;
                                }
位宇华's avatar
位宇华 committed
1009 1010
                            }

hehongwei's avatar
hehongwei committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
                            codess.forEach((codeItem) => {
                                let codeLength = String(codeItem.code).length;
                                let codeToCompare = String(codeItem.code).substring(0, codeLength);
                                money.forEach((moneyItem) => {
                                    let columnIdString = String(moneyItem.code);
                                    let idToMatch = columnIdString.substring(0, codeLength);
                                    if (idToMatch === codeToCompare) {
                                        moneyItem.cc = codeItem.oneLevel * 1;
                                    }
                                });
位宇华's avatar
位宇华 committed
1021 1022
                            });

hehongwei's avatar
hehongwei committed
1023 1024 1025 1026 1027 1028 1029
                            money = money.map((item) => {
                                let v = item.remark;
                                for (let key in classify) {
                                    if (classify[key].includes(v)) {
                                        item.v.name = key;
                                        return item;
                                    }
位宇华's avatar
位宇华 committed
1030
                                }
hehongwei's avatar
hehongwei committed
1031 1032 1033 1034 1035 1036 1037 1038 1039
                                item.v.name = "基本生产-原煤";
                                return item;
                            });
                            //东欢坨矿的规则 如果部门为旧品和设备 并且他们的材料为支护用品和大型材料就把他们放到基本生产里
                            money.forEach((item) => {
                                if (item.remark == "旧品利用中心" || item.remark == "设备管理科") {
                                    if (item.cc == 3 || item.cc == 2) {
                                        item.v.name = "基本生产-原煤";
                                    }
位宇华's avatar
位宇华 committed
1040
                                }
hehongwei's avatar
hehongwei committed
1041
                            });
位宇华's avatar
位宇华 committed
1042

hehongwei's avatar
hehongwei committed
1043 1044 1045
                            money.forEach((item) => {
                                item.c = item.cc ? item.cc * 1 : 10;
                            });
位宇华's avatar
位宇华 committed
1046

hehongwei's avatar
hehongwei committed
1047 1048 1049 1050 1051 1052 1053 1054
                            money.forEach((item) => {
                                if (item.department && item.v.name) {
                                    let originalString = item.v.name;
                                    let parts = originalString.split("-");
                                    let replacedString = parts[0] + "-" + item.department;
                                    item.v.name = replacedString;
                                }
                            });
位宇华's avatar
位宇华 committed
1055

hehongwei's avatar
hehongwei committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
                            money.forEach((item) => {
                                if (item.v.name !== undefined) {
                                    let index = item.v.name.indexOf("-");
                                    if (index !== -1) {
                                        let substrBeforeDash = item.v.name.slice(0, index);
                                        let DepartColumns = CompositeTable[0]["celldata"].flat().find((obj) => {
                                            if (obj.v && obj.v.v && typeof obj.v.v === 'string') {
                                                return obj.v.v.includes(item.v.name.slice(0, index));
                                            }
                                            return false;
                                        });

                                        if (DepartColumns && DepartColumns.r) {
                                            let index = item.v.name.indexOf("-");
                                            if (index !== -1) {
                                                let substrAfterDash = item.v.name.slice(index + 1);
                                                switch (substrAfterDash) {
                                                    case '':
                                                        item.r = DepartColumns.r;
                                                        break;
                                                    case '原煤':
                                                        item.r = DepartColumns.r + 1;
                                                        break;
                                                    case '洗煤':
                                                        item.r = DepartColumns.r + 2;
                                                        break;
                                                    case '选煤':
                                                        item.r = DepartColumns.r + 3;
                                                        break;
                                                    case '厂区服务':
                                                        item.r = DepartColumns.r + 1;
                                                        break;
                                                    default:
                                                    // 默认情况
                                                }
位宇华's avatar
位宇华 committed
1091 1092 1093 1094
                                            }
                                        }
                                    }
                                }
hehongwei's avatar
hehongwei committed
1095
                            });
位宇华's avatar
位宇华 committed
1096

hehongwei's avatar
hehongwei committed
1097 1098 1099 1100 1101
                            // 更新金额列
                            for (let item of money) {
                                if (item.r > 8 && item.c < 10) {
                                    item.c = 10;
                                }
位宇华's avatar
位宇华 committed
1102 1103
                            }

hehongwei's avatar
hehongwei committed
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
                            // 合并重复单元格数据
                            let cellMap = new Map();
                            for (let i = 0; i < money.length; i++) {
                                let key = money[i].r + ',' + money[i].c;
                                if (cellMap.has(key)) {
                                    let existingItem = cellMap.get(key);
                                    existingItem.v.v = Number(existingItem.v.v) + Number(money[i].v.v);
                                    existingItem.v.m = existingItem.v.v.toString();
                                    existingItem.index.push(i);
                                } else {
                                    money[i].index = [i];
                                    cellMap.set(key, money[i]);
位宇华's avatar
位宇华 committed
1116 1117
                                }
                            }
hehongwei's avatar
hehongwei committed
1118 1119 1120 1121 1122 1123 1124 1125 1126
                            let duplicateData = Array.from(cellMap.values()).filter(item => item.v.v > 0 || parseInt(item.v.m) > 0);
                            duplicateData = duplicateData.map(item => {
                                return {
                                    ...item,
                                    v: {
                                        ...item.v,
                                        v: isNaN(item.v.v) ? item.v.v : Number(item.v.v).toFixed(2)
                                    }
                                };
位宇华's avatar
位宇华 committed
1127
                            });
hehongwei's avatar
hehongwei committed
1128 1129 1130 1131 1132 1133 1134 1135 1136
                            // 替换原始数据中的重复单元格数据
                            //金额所在列和行,去模板表中查找,如果行列一致则替换
                            for (let i = 0; i < duplicateData.length; i++) {
                                //     // 对比 c 和 r 是否与 CompositeTable[0]["celldata"] 中相应对象相同
                                for (let ii = 0; ii < CompositeTable[0]["celldata"].length; ii++) {
                                    if (duplicateData[i].r === CompositeTable[0]["celldata"][ii].r && duplicateData[i].c === CompositeTable[0]["celldata"][ii].c) {
                                        // 如果相同,则进行替换
                                        CompositeTable[0]["celldata"][ii] = duplicateData[i];
                                    }
位宇华's avatar
位宇华 committed
1137
                                }
hehongwei's avatar
hehongwei committed
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
                            }
                            CompositeTable[0].data = luckysheet.transToData(CompositeTable[0]["celldata"])
                            if (this.value !== 1248) {
                                luckysheet.create({
                                    container: "luckysheet", // Luckysheet 的容器元素 ID
                                    title: fileName, // Excel 文件名
                                    data: CompositeTable, // Excel 数据
                                    showinfobar: false, //是否显示顶部名称栏
                                    lang: 'zh',
                                });
                                modify = true
                                this.showMask = false;
                            }
                            //this.from 往后台村的数据
                            this.ImportTables.historyContent = resultJSON
                            this.generate.historyContent = JSON.stringify(CompositeTable)
                            //往后台传科目编码相关的东西
                            duplicateData.forEach(obj => {
                                CompositeTable[0].celldata.forEach(cell => {
                                    if (obj.c === cell.c && cell.r === 3) {
                                        obj.v.material = cell.v.v;
                                    }
                                });
位宇华's avatar
位宇华 committed
1161
                            });
hehongwei's avatar
hehongwei committed
1162 1163 1164 1165 1166 1167
                            this.middle = CompositeTable
                            this.Vouchers(duplicateData)
                        } else {
                            this.open4()
                            this.showMask = false
                        }
位宇华's avatar
位宇华 committed
1168
                    }
hehongwei's avatar
hehongwei committed
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
                    //单侯矿转换方法&& this.selectname.includes('单侯')
                    //特定规则 制造费用可能放也可能不放,制造费用后期可能会晒出来
                    if (this.mine.includes('单侯')) {
                        //部门名称所在列
                        let DepartmentColumn = c.flat().filter(obj => obj.v && obj.v.v === "创建部门")[0]?.c;
                        //结算金额所在列
                        let ExpenseColumn = c.flat().filter(obj => obj.v && obj.v.v === "实际金额")[0]?.c;
                        //材料编码
                        let codeColumn = c.flat().filter(obj => obj.v && obj.v.v === "材料编码")[0]?.c


                        let headRows = this.newArray[0].celldata.flat().filter(obj => obj.v && obj.v.v === "火工品")[0]?.r
                        //费用来源
                        let fylyColumn = c.flat().filter(obj => obj.v && obj.v.v === "费用来源")[0]?.c
                        if (DepartmentColumn && ExpenseColumn && codeColumn && fylyColumn) {
                            let code = c.flat().filter(obj => obj.c && obj.c === codeColumn && obj.r > 0)
                            let headRow = this.newArray[0].celldata.flat().filter(obj => obj.r && obj.r === headRows && obj.c > 0)
                            let money = c.flat().filter(obj => obj.c && obj.c === ExpenseColumn && obj.r > 0)
                            let remark = c.flat().filter(obj => obj.c && obj.c === DepartmentColumn && obj.r > 0)
                            let fyly = c.flat().filter(obj => obj.c && obj.c === fylyColumn && obj.r > 0)
                            // 清空money数组中的属性
                            money.forEach(item => {
                                item.remark = '';
                                item.code = '';
                                item.cc = '';
                                item.fyly = '';
                                item.rr = '';
                            });
                            // 更新money数组中的属性
                            money = money.filter(item => {
                                let matchingCode = code.find(c => c.r === item.r);
                                if (matchingCode) {
                                    item.code = matchingCode.v.v;
                                }
位宇华's avatar
位宇华 committed
1203

hehongwei's avatar
hehongwei committed
1204 1205 1206 1207
                                let matchingRemark = remark.find(r => r.r === item.r);
                                if (matchingRemark) {
                                    item.remark = matchingRemark.v.v;
                                }
位宇华's avatar
位宇华 committed
1208

hehongwei's avatar
hehongwei committed
1209 1210 1211 1212
                                let matchingFyly = fyly.find(f => f.r === item.r);
                                if (matchingFyly) {
                                    item.fyly = matchingFyly.v.v;
                                }
位宇华's avatar
位宇华 committed
1213

hehongwei's avatar
hehongwei committed
1214 1215
                                return (matchingCode && matchingRemark && matchingFyly);
                            });
位宇华's avatar
位宇华 committed
1216

hehongwei's avatar
hehongwei committed
1217 1218 1219
                            money.forEach((item) => {
                                if (item.remark.startsWith('物管科')) {
                                    item.remark = '物管科';
位宇华's avatar
位宇华 committed
1220
                                }
hehongwei's avatar
hehongwei committed
1221 1222
                                if (item.remark.endsWith('储运科')) {
                                    item.remark = '储运科';
位宇华's avatar
位宇华 committed
1223
                                }
hehongwei's avatar
hehongwei committed
1224 1225
                                if (item.remark.includes('生活')) {
                                    item.remark = '生活科'
位宇华's avatar
位宇华 committed
1226 1227
                                }
                            });
hehongwei's avatar
hehongwei committed
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
                            money = money.map(obj => {
                                let v = obj.remark;
                                for (let key in classify) {
                                    if (classify[key].includes(v)) {
                                        obj.v.name = key;
                                        obj.whether = true;
                                        return obj;
                                    }
                                }
                                return obj;
                            });
                            for (let i = 0; i < codess.length; i++) {
                                let codeLength = String(codess[i].code).length;
                                let codeToCompare = String(codess[i].code).substring(0, codeLength);
                                for (let ii = 0; ii < money.length; ii++) {
                                    let columnIdString = String(money[ii].code);
                                    let idToMatch = columnIdString.substring(0, codeLength);
                                    if (idToMatch === codeToCompare) {
                                        money[ii].cc = codess[i].oneLevel * 1
                                    }
                                }
位宇华's avatar
位宇华 committed
1249
                            }
hehongwei's avatar
hehongwei committed
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
                            let synthesis = this.newArray
                            let head = synthesis[0].celldata.flat().filter(obj => obj.c == 0 && obj.r > 4)
                            head.forEach(itemA => {
                                let targetRemark = itemA.v.v; // 需要匹配的目标值,这里是 a 属性中的 v.v
                                money.forEach(itemB => {
                                    if (itemB.remark.includes(targetRemark)) { // 使用 include 方法进行模糊匹配
                                        itemB.rr = itemA.r; // 如果匹配到,则将 a 属性中的 r 的值赋给 b 属性中的 rr
                                    }
                                });
                            });
                            for (let i = 0; i < money.length; i++) {
                                if (money[i].rr) {
                                    money[i].r = money[i].rr
                                }
                                if (money[i].cc) {
                                    money[i].c = money[i].cc * 1
                                }
                                if (!money[i].cc) {
                                    money[i].c = 10
位宇华's avatar
位宇华 committed
1269

hehongwei's avatar
hehongwei committed
1270
                                }
位宇华's avatar
位宇华 committed
1271
                            }
hehongwei's avatar
hehongwei committed
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
                            let seen = new Map();
                            let duplicateData = [];
                            let i = -1
                            for (let obj of money) {
                                let key = obj.r + ',' + obj.c;
                                i += 1
                                if (seen.has(key)) {
                                    let existingObj = seen.get(key);
                                    existingObj.v.v = Number(existingObj.v.v) + Number(obj.v.v);
                                    existingObj.v.m = existingObj.v.v.toString();
                                    existingObj.index.push(i)
                                } else {
                                    obj.index = [i]
                                    seen.set(key, obj);
                                }
位宇华's avatar
位宇华 committed
1287
                            }
hehongwei's avatar
hehongwei committed
1288 1289 1290 1291
                            for (let obj of seen.values()) {
                                if (obj.v.v > 0 || parseInt(obj.v.m) > 0) {
                                    duplicateData.push(obj);
                                }
位宇华's avatar
位宇华 committed
1292
                            }
hehongwei's avatar
hehongwei committed
1293 1294 1295 1296 1297 1298 1299
                            for (let i = 0; i < duplicateData.length; i++) {
                                //     // 对比 c 和 r 是否与 he[0]["celldata"] 中相应对象相同
                                for (let ii = 0; ii < synthesis[0]["celldata"].length; ii++) {
                                    if (duplicateData[i].r === synthesis[0]["celldata"][ii].r && duplicateData[i].c === synthesis[0]["celldata"][ii].c) {
                                        // 如果相同,则进行替换
                                        synthesis[0]["celldata"][ii] = duplicateData[i];
                                    }
位宇华's avatar
位宇华 committed
1300 1301
                                }
                            }
hehongwei's avatar
hehongwei committed
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312
                            synthesis[0].data = luckysheet.transToData(synthesis[0]["celldata"])
                            if (this.value !== 1248) {
                                luckysheet.create({
                                    container: "luckysheet", // Luckysheet 的容器元素 ID
                                    title: fileName, // Excel 文件名
                                    data: synthesis, // Excel 数据
                                    showinfobar: false, //是否显示顶部名称栏
                                    lang: 'zh',
                                });
                                modify = true
                                this.showMask = false;
位宇华's avatar
位宇华 committed
1313
                            }
hehongwei's avatar
hehongwei committed
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
                            duplicateData.forEach(item => {
                                const matchedHeadRow = headRow.find(headItem => headItem.c === item.c);
                                if (matchedHeadRow) {
                                    item.v.material = matchedHeadRow.v.v;
                                }
                            });
                            for (let i = 0; i < duplicateData.length; i++) {
                                if (duplicateData[i].r > 4 && duplicateData[i].r < 16) {
                                    //管理费用
                                    duplicateData[i].r = 6
                                    duplicateData[i].c = 12
位宇华's avatar
位宇华 committed
1325

hehongwei's avatar
hehongwei committed
1326 1327 1328 1329 1330
                                }
                                if (duplicateData[i].r > 16 && duplicateData[i].r < 27) {
                                    //制造费用
                                    duplicateData[i].r = 7
                                    duplicateData[i].c = 10
位宇华's avatar
位宇华 committed
1331 1332


hehongwei's avatar
hehongwei committed
1333 1334 1335 1336
                                }
                                if (duplicateData[i].r > 28 && duplicateData[i].r < 43) {
                                    //基本费用
                                    duplicateData[i].r = 8
位宇华's avatar
位宇华 committed
1337

hehongwei's avatar
hehongwei committed
1338 1339 1340 1341 1342
                                }
                                if (duplicateData[i].r > 43 && duplicateData[i].r < 46) {
                                    //销售费用
                                    duplicateData[i].r = 9
                                    duplicateData[i].c = 10
位宇华's avatar
位宇华 committed
1343 1344


hehongwei's avatar
hehongwei committed
1345 1346 1347 1348 1349 1350
                                }
                                if (duplicateData[i].r > 46 && duplicateData[i].r < 48) {
                                    //其他业务
                                    duplicateData[i].r = 10
                                    duplicateData[i].c = 10
                                }
位宇华's avatar
位宇华 committed
1351

hehongwei's avatar
hehongwei committed
1352 1353 1354 1355 1356
                                if (duplicateData[i].r > 49 && duplicateData[i].r < 51) {
                                    //安全费用
                                    duplicateData[i].r = 11
                                    duplicateData[i].c = 10
                                }
位宇华's avatar
位宇华 committed
1357
                            }
hehongwei's avatar
hehongwei committed
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
                            let seens = new Map();
                            let duplicateDatas = [];
                            for (let obj of duplicateData) {
                                let key = obj.r + ',' + obj.c;
                                if (seens.has(key)) {
                                    let existingObj = seens.get(key);
                                    existingObj.v.v = Number(existingObj.v.v) + Number(obj.v.v);
                                    existingObj.v.m = existingObj.v.v.toString();
                                } else {
                                    seens.set(key, obj);
                                }
位宇华's avatar
位宇华 committed
1369
                            }
hehongwei's avatar
hehongwei committed
1370 1371 1372 1373
                            for (let obj of seens.values()) {
                                if (obj.v.v > 0 || parseInt(obj.v.m) > 0) {
                                    duplicateDatas.push(obj);
                                }
位宇华's avatar
位宇华 committed
1374
                            }
hehongwei's avatar
hehongwei committed
1375 1376 1377 1378
                            this.Vouchers(duplicateDatas)
                        } else {
                            this.open4()
                            this.showMask = false;
位宇华's avatar
位宇华 committed
1379 1380 1381
                        }
                    }

hehongwei's avatar
hehongwei committed
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
                });
            },
            //成本表往凭证但转
            Vouchers(duplicateData) {
                this.detail = duplicateData.map(item => {
                    if (typeof item.v.v === 'number') {
                        item.v.v = Number(item.v.v.toFixed(2)); // 如果是数字,则进行处理
                    }
                    if (typeof item.v.m === 'number') {
                        item.v.m = parseFloat(item.v.m).toFixed(2); // 如果是数字,则进行处理
                    }
                    return item;
                });

                let sum = [{
                    code: '2241005',
                    material: '其他材料',
                    v: 0
                }, {
                    code: '1403002',
                    material: "火工品",
                    v: 0,
                }];

                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);
                    }
位宇华's avatar
位宇华 committed
1412 1413
                }

hehongwei's avatar
hehongwei committed
1414 1415 1416
                sum.forEach(item => {
                    item.v = Number(item.v).toFixed(2);
                });
位宇华's avatar
位宇华 committed
1417

hehongwei's avatar
hehongwei committed
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
                const VoucherForm = JSON.parse(this.VoucherForm);
                const filteredData = VoucherForm[0].celldata.filter(obj => obj.r === 5);
                const needKeys = [
                    "*手工码",
                    "*会计主体",
                    "*核算账簿",
                    "*单据日期",
                    "*凭证类型",
                    "*制单人",
                    "*分录摘要",
                    "*币种",
                    "本币汇率类型",
                    "*本币汇率",
                    "*业务日期",
                    "凭证单摘要",
                ];

                // 根据需要的关键词获取对应的单元格
                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;

                // 根据特定条件筛选单元格
                const foundObjects = filteredData.filter(obj => obj.v.v === "物料基本分类");
                let Classification;
                let oldClassification;
                if (foundObjects.length >= 2) {
                    oldClassification = foundObjects[0].c;
                    Classification = foundObjects[1].c;
                } else {
                    // 处理找不到两个满足条件的对象的情况
位宇华's avatar
位宇华 committed
1451 1452
                }

hehongwei's avatar
hehongwei committed
1453 1454 1455 1456
                // 遍历duplicateData数组,为每个对象添加mining属性并赋值为this.select
                duplicateData.forEach(obj => {
                    obj.mining = this.select;
                });
位宇华's avatar
位宇华 committed
1457

hehongwei's avatar
hehongwei committed
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
                // 生成标准模板
                const Fusion = {
                    "r": '',
                    "c": '',
                    "v": {
                        "ct": {
                            "fa": "@",
                            "t": "s"
                        },
                        "fs": 8,
                        "ff": "微软雅黑",
                        "tb": 2,
                        "v": "",
                        "qp": 1,
                        "m": ""
位宇华's avatar
位宇华 committed
1473
                    }
hehongwei's avatar
hehongwei committed
1474
                };
位宇华's avatar
位宇华 committed
1475

hehongwei's avatar
hehongwei committed
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
                // 获取当前日期并格式化为 YYYY-MM-DD 的字符串
                const currentDate = new Date();
                const year = currentDate.getFullYear(); // 获取当前年份
                const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 获取当前月份,记得要加 1
                const day = currentDate.getDate(); // 获取当前日期
                const formattedDate = `${year}-${month}-${day}`;
                // 生成唯一标识符uuid
                function generateUniqueShortUuid() {
                    return uuidv4().replace(/-/g, '').substring(0, 12);
                }
                const uuid = generateUniqueShortUuid();

                // 创建data1数组
                const data1 = [
                    uuid, this.select, this.select, this.date, '', this.phone, '转本月材料分配', 'CNY', 'E001', '1.00000000', formattedDate, uuid
                ];
                const newData = duplicateData.map(obj => {
                    const [name, department] = obj.v.name.split("-");
                    return {
                        r: obj.r,
                        c: obj.c,
                        //金额
                        money: obj.v.v,
                        name,
                        indexRow: obj.index,
                        department,
                        material: obj.v.material,
                        mining: obj.mining,
                        //uuid
                        accountuuid: data1[0],
                        accountdate: this.date,
                    };
位宇华's avatar
位宇华 committed
1508
                });
hehongwei's avatar
hehongwei committed
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
                this.ImportTables.exportUuid = data1[0]
                this.generate.exportUuid = data1[0]
                this.ImportTables.identifyingCode = 0;
                this.ImportTables.date = this.date
                // this.ImportTables.exportUuid = 1;
                this.ImportTables.mining = this.select
                this.ImportTables.tylkStatus = 3
                this.ImportTables.templateId = this.value
                this.generate.templateId = this.value
                this.generate.tylkStatus = 3
                // this.generate.exportUuid = 1;
                this.generate.identifyingCode = 1;
                this.generate.date = this.date
                this.generate.mining = this.select
                let list = [this.ImportTables, this.generate]
                let filteredArr;
                accountingcode(newData).then(response => {
                    //合并起来的每行的值转换成一行一个编码 知道哪行合并了起来
                    filteredArr = response.rows.map(obj =>
                        Object.entries(obj)
                            .filter(([key, value]) => value !== null)
                            .reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
                    );
                    this.ImportTables.historyRole = filteredArr.map(item => {
                        let extractedItem = {};
                        if (item.accountingCode) {
                            extractedItem.accountingCode = item.accountingCode;
                        }
位宇华's avatar
位宇华 committed
1537

hehongwei's avatar
hehongwei committed
1538 1539
                        if (Array.isArray(item.indexRow)) {
                            extractedItem.indexRow = item.indexRow.join(', ');
位宇华's avatar
位宇华 committed
1540
                        }
hehongwei's avatar
hehongwei committed
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556

                        return extractedItem;
                    });
                    let historyContent = [];

                    for (let i = 0; i < this.ImportTables.historyRole.length; i++) {
                        if (this.ImportTables.historyRole[i].indexRow && this.ImportTables.historyRole[i].accountingCode) {
                            const indexRowArray = this.ImportTables.historyRole[i].indexRow.split(', ');
                            for (let j = 0; j < indexRowArray.length; j++) {
                                let historyRole = {
                                    value: this.ImportTables.historyRole[i].accountingCode,
                                    key: String(indexRowArray[j])
                                };

                                historyContent.push(historyRole);
                            }
位宇华's avatar
位宇华 committed
1557 1558
                        }
                    }
hehongwei's avatar
hehongwei committed
1559 1560 1561 1562 1563 1564 1565
                    this.ImportTables.historyRole = JSON.stringify(historyContent)
                    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;
                            }
位宇华's avatar
位宇华 committed
1566
                        }
hehongwei's avatar
hehongwei committed
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584
                    }
                    let isArray = []
                    for (let i = 0; i < filteredArr.length; i++) {
                        let newRow1 = {
                            "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
                            }
位宇华's avatar
位宇华 committed
1585

hehongwei's avatar
hehongwei committed
1586 1587
                        };
                        let newRow2 = {
位宇华's avatar
位宇华 committed
1588
                            "r": 8 + i,
hehongwei's avatar
hehongwei committed
1589
                            "c": money1,
hehongwei's avatar
hehongwei committed
1590 1591 1592 1593 1594 1595 1596 1597
                            "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,
hehongwei's avatar
hehongwei committed
1598
                                "v": duplicateData[i]?.v.v,
hehongwei's avatar
hehongwei committed
1599
                                "qp": Fusion.v.qp,
hehongwei's avatar
hehongwei committed
1600
                                "m": duplicateData[i]?.v.m
hehongwei's avatar
hehongwei committed
1601
                            }
位宇华's avatar
位宇华 committed
1602

hehongwei's avatar
hehongwei committed
1603
                        };
位宇华's avatar
位宇华 committed
1604

hehongwei's avatar
hehongwei committed
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628
                        for (let l = 0; l < need.length; l++) {
                            let needIndex = l % need.length;
                            let newRow3 = {
                                "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
                                }

                            };

                            isArray.push(newRow3);
                        }
                        isArray.push(newRow1, newRow2)

位宇华's avatar
位宇华 committed
1629 1630
                    }

hehongwei's avatar
hehongwei committed
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
                    const newRows = [];
                    for (let i = 0; i < filteredArr.length; i++) {
                        const codeValue = filteredArr[i]?.accountingCode;
                        if (codeValue) {
                            const newRow = {
                                "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
                                }
                            };
                            isArray.push(newRow);
                        }
                    }
                    const result = [];

                    filteredArr.forEach((obj, index) => {
                        Object.keys(obj).forEach(key => {
                            if (obj[key] && obj[key].includes(",")) {
                                const [prop, val] = obj[key].split(",");
                                const propName = prop.trim().replace('*', ''); // 去除属性名中的星号(*)
                                result.push({ [propName]: val.trim(), row: index });
                            }
                        });
                    });
                    let cleanedData = result.filter(entry => {
                        return Object.values(entry).every(value => value !== "null" && value !== null);
                    });
                    let name = []
                    for (let i = 0; i < cleanedData.length; i++) {
                        for (let key in cleanedData[i]) {
                            let columns = filteredData.filter(obj => obj.v.v === key)[0]?.c
                            if (columns && columns !== oldClassification) {
                                name.push(columns)
                            }
                            if (columns === oldClassification) {
                                name.push(Classification)
位宇华's avatar
位宇华 committed
1677

hehongwei's avatar
hehongwei committed
1678 1679 1680 1681 1682
                            }
                        }
                    }
                    cleanedData = cleanedData.filter(obj => Object.keys(obj)[0] !== "");
                    for (let i = 0; i < name.length; i++) {
位宇华's avatar
位宇华 committed
1683
                        const newRow = {
hehongwei's avatar
hehongwei committed
1684 1685
                            "r": 8 + cleanedData[i].row,
                            "c": name[i],
hehongwei's avatar
hehongwei committed
1686 1687 1688 1689 1690 1691 1692 1693
                            "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,
hehongwei's avatar
hehongwei committed
1694
                                "v": Object.values(cleanedData[i])[0],
hehongwei's avatar
hehongwei committed
1695
                                "qp": Fusion.v.qp,
hehongwei's avatar
hehongwei committed
1696
                                "m": Object.values(cleanedData[i])[0]
hehongwei's avatar
hehongwei committed
1697 1698
                            }
                        };
位宇华's avatar
位宇华 committed
1699
                        isArray.push(newRow);
hehongwei's avatar
hehongwei committed
1700
                    }
hehongwei's avatar
hehongwei committed
1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
                    for (let i = 0; i < sum.length; i++) {
                        const newRow = {
                            "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,
                            }
                        };
                        const newRow1 = {
                            "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,
                            }
                        };
                        isArray.push(newRow, newRow1);
1735
                    }
hehongwei's avatar
hehongwei committed
1736 1737
                    VoucherForm[0].celldata.push(...isArray)
                    if (this.value === 1248) {
1738

hehongwei's avatar
hehongwei committed
1739 1740 1741 1742 1743 1744 1745 1746
                        luckysheet.create({
                            container: "luckysheet", // Luckysheet 的容器元素 ID
                            title: fileName, // Excel 文件名
                            allowEdit: false,//作用:是否允许前台编辑
                            data: VoucherForm, // Excel 数据
                            showinfobar: false, //是否显示顶部名称栏
                            lang: 'zh',
                        });
1747

hehongwei's avatar
hehongwei committed
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
                        modify = true
                        this.showMask = false;
                    }
                    // addInsert(list).then(response => {
                    //     if (response.code == 200) {
                    //         this.$message({
                    //             message: '保存成功', type: 'success'
                    //         })
                    //     }
                    // });
                    VoucherForm[0].celldata = []
1759

hehongwei's avatar
hehongwei committed
1760
                })
1761

hehongwei's avatar
hehongwei committed
1762 1763 1764 1765 1766
            },
            /** 保存导入文件和生成文件 */
            submit(contents) {
                const name = contents.info.name;
                const obj = contents.sheets;
hehongwei's avatar
hehongwei committed
1767
                let list = [];
hehongwei's avatar
hehongwei committed
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
                //导入文件内容转json
                let str = JSON.stringify(obj)// 对象转化为字符串
                let objsheet = luckysheet.getAllSheets() // 得到表的数据
                //生成文件转json
                let strsheet = JSON.stringify(objsheet)// 对象转化为字符串
                this.from.templateId = this.dfrom.templateId = tempId;
                this.from.importUuid = this.dfrom.importUuid = uuid1;
                this.from.roleId = this.dfrom.roleId = roleId;
                this.dfrom.historyName = name + '(导入文件)';
                this.dfrom.historyContent = str;
                this.dfrom.identifyingCode = 0;
                this.dfrom.tylkStatus = 1;
                this.dfrom.historyRole = this.historyRole;
                let date = new Date(this.date);
                let fullYear = date.getFullYear();
                let month = ("0" + (date.getMonth() + 1)).slice(-2);
                let datastr = fullYear + month;
                this.dfrom.date = datastr
                this.dfrom.mining = this.mining
                this.from.status = this.dfrom.status = 0;
                list.push(this.dfrom);
                this.from.historyName = fileName + '(生成文件)';
                this.from.historyContent = strsheet;
                this.from.identifyingCode = 1;
                this.from.date = datastr;
                this.from.tylkStatus = 1;
                this.from.mining = this.mining
                list.push(this.from);
                addInsert(list).then(response => {
                    if (response.code == 200) {
                        this.$message({
                            message: '保存成功', type: 'success'
                        })
hehongwei's avatar
hehongwei committed
1801
                    }
位宇华's avatar
位宇华 committed
1802
                });
1803

hehongwei's avatar
hehongwei committed
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847
            },
            /** 导出设置 */
            handleExport: debounce(function () {
                // 处理点击事件
                exportExcel(luckysheet.getAllSheets(), fileName, trueORfalse, this.value);

                // 清洗数据
                selectActSuppliesHistorydataAcc(3).then(response => {
                    var data = response.data;
                    let list = [];
                    let list1 = [];
                    for (let i = 0; i < data.length; i++) {

                        if (data[i].identifyingCode == 1) {
                            let imp = {}
                            imp.exportUuid = data[i].exportUuid
                            let parse = JSON.parse(data[i].historyContent);
                            let transToCellData = window.luckysheet.transToData(parse[0].celldata);
                            imp.hId = data[i].id;
                            imp.createBy = data[i].createBy;
                            imp.hDate = data[i].date;
                            imp.mining = data[i].mining;
                            imp.actOperation2 = transToCellData;
                            list.push(imp);
                        } else {
                            let ssd = {}
                            ssd.exportUuid = data[i].exportUuid
                            let parse = JSON.parse(data[i].historyContent);
                            let transToCellData = window.luckysheet.transToData(parse[0].celldata);
                            ssd.hId = data[i].id;
                            ssd.createBy = data[i].createBy;
                            ssd.hDate = data[i].date;
                            ssd.mining = data[i].mining;
                            ssd.actOperation2 = transToCellData;
                            ssd.convenRole = data[i].convenRole
                            ssd.historyRole = data[i].historyRole
                            list1.push(ssd);
                        }
                    }
                    addInsertAccount1(list).then(response => {

                    });

                    addInsertAccount2(list1).then(response => {
1848

hehongwei's avatar
hehongwei committed
1849
                    });
1850 1851
                });

hehongwei's avatar
hehongwei committed
1852 1853 1854 1855
            }, 500), // 设置延迟时间,单位为毫秒
        }
        // 配置项111
    };
1856 1857 1858



hehongwei's avatar
hehongwei committed
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
    // debounce函数定义
    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;
            }
1879 1880
        }
    }
hehongwei's avatar
hehongwei committed
1881 1882 1883 1884 1885
    function generateUUID() {
        let array = new Uint32Array(4);
        window.crypto.getRandomValues(array);
        return array.join("-");
    }
1886 1887
</script>
<style>
hehongwei's avatar
hehongwei committed
1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
    .mask {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .loading-spinner {
        /* 添加你的加载动画样式 */
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 4px solid #f3f3f3;
        border-top: 4px solid #3498db;
        animation: spin 1s linear infinite;
hehongwei's avatar
hehongwei committed
1908 1909
    }

hehongwei's avatar
hehongwei committed
1910 1911 1912 1913 1914 1915 1916 1917
    @keyframes spin {
        0% {
            transform: rotate(0deg);
        }

        100% {
            transform: rotate(360deg);
        }
1918 1919
    }
</style>