| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- // 在 store/modules/fillingData.js 中更新字段映射
- import { defineStore } from "pinia";
- export const useFillingDataStore = defineStore("fillingData", {
- state: () => ({
- // 存储所有设备的填写数据
- deviceFillings: new Map(), // key: deviceId, value: {设备数据}
- // 存储累计值(根据 data.txt 中的生产日报字段调整)
- totals: {
- "当日运转时间H": 0, // 对应空压机、空气处理撬、液驱机、中压增压撬等
- "当日注气量-方": 0, // 对应提纯撬
- "当日注水量-方": 0, // 对应注水泵(虽然数据中没有,但保留逻辑)
- "当日用电量kWh": 0, // 对应箱式变电站
- },
- }),
- actions: {
- // 更新设备数据并重新计算累计值
- updateDeviceFilling(deviceId, deviceData) {
- this.deviceFillings.set(deviceId, deviceData);
- this.calculateTotals();
- },
- // 更新单个填写项
- updateFillingItem(deviceId, deviceName, itemName, value) {
- const deviceData = this.deviceFillings.get(deviceId) || {
- deviceId,
- deviceName,
- };
- if (!deviceData.nonSumList) deviceData.nonSumList = [];
- // 查找或创建对应项
- const itemIndex = deviceData.nonSumList.findIndex(
- (item) => item.name === itemName
- );
- if (itemIndex >= 0) {
- deviceData.nonSumList[itemIndex].fillContent = value;
- } else {
- deviceData.nonSumList.push({
- name: itemName,
- fillContent: value,
- type: "double",
- });
- }
- this.updateDeviceFilling(deviceId, deviceData);
- },
- // 计算所有累计值(根据 data.txt 数据调整逻辑)
- calculateTotals() {
- // 重置累计值
- const newTotals = {
- "当日运转时间H": 0,
- "当日注气量-方": 0,
- "当日注水量-方": 0,
- "当日用电量kWh": 0,
- };
- // 遍历所有设备数据
- this.deviceFillings.forEach((deviceData) => {
- if (
- deviceData.nonSumList &&
- deviceData.deviceName &&
- !deviceData.isProductionReport
- ) {
- const { deviceName, nonSumList } = deviceData;
- // 根据设备名称和字段名判断是否需要累加
- nonSumList.forEach((item) => {
- // 确保 fillContent 是数字类型再进行计算
- const value = parseFloat(item.fillContent) || 0;
- // 需要累加的设备类型和字段(根据 data.txt 数据调整)
- if (
- (deviceName.includes("空压机") ||
- deviceName.includes("空气处理撬") ||
- deviceName.includes("液驱机") ||
- deviceName.includes("中压增压撬") ||
- deviceName.includes("增压机")) && // 包含所有运转时间的设备
- item.name === "当日运转时间H"
- ) {
- newTotals["当日运转时间H"] += value;
- } else if (
- deviceName.includes("提纯撬") &&
- item.name === "当日注气量-方"
- ) {
- newTotals["当日注气量-方"] += value;
- } else if (
- deviceName.includes("注水泵") &&
- item.name === "当日注水量-方"
- ) {
- newTotals["当日注水量-方"] += value;
- } else if (
- deviceName.includes("箱式变电站") &&
- item.name === "当日用电量kWh"
- ) {
- newTotals["当日用电量kWh"] += value;
- }
- });
- }
- });
- this.totals = newTotals;
- return newTotals;
- },
- // 获取指定字段的累计值
- getTotal(fieldName) {
- return this.totals[fieldName] || 0;
- },
- // 获取所有累计值
- getAllTotals() {
- return { ...this.totals };
- },
- // 检查是否是需要累加的字段
- isAccumulatedField(deviceName, fieldName) {
- return (
- // 空压机等设备 -> 当日运转时间H
- ((deviceName.includes("空压机") ||
- deviceName.includes("空气处理撬") ||
- deviceName.includes("液驱机") ||
- deviceName.includes("中压增压撬") ||
- deviceName.includes("增压机")) &&
- fieldName === "当日运转时间H") ||
- // 提纯撬 -> 当日注气量-方
- (deviceName.includes("提纯撬") && fieldName === "当日注气量-方") ||
- // 注水泵 -> 当日注水量-方
- (deviceName.includes("注水泵") && fieldName === "当日注水量-方") ||
- // 箱式变电站 -> 当日用电量kWh
- (deviceName.includes("箱式变电站") && fieldName === "当日用电量kWh")
- );
- },
- // 清理指定工单的数据
- clearData(orderId) {
- // 这里可以根据 orderId 清理特定工单的数据
- // 简单实现:清理所有数据
- this.deviceFillings.clear();
- this.totals = {
- "当日运转时间H": 0,
- "当日注气量-方": 0,
- "当日注水量-方": 0,
- "当日用电量kWh": 0,
- };
- },
- // 获取需要同步到生产日报的字段映射(根据 data.txt 中的生产日报字段)
- getProductionReportMapping() {
- return {
- // 设备字段名: 生产日报字段名
- "当日运转时间H": "当日运转时间H",
- "当日注气量-方": "当日注气量-方",
- "当日注水量-方": "当日注水量-方",
- "当日用电量kWh": "当日用电量kWh",
- };
- },
- // 获取生产日报字段到设备字段的反向映射
- getReverseMapping() {
- const mapping = this.getProductionReportMapping();
- const reverseMapping = {};
- for (const [deviceField, reportField] of Object.entries(mapping)) {
- reverseMapping[reportField] = deviceField;
- }
- return reverseMapping;
- },
- // 更新生产日报字段
- updateProductionReportFields(reportData) {
- // 获取反向映射,从生产日报字段到设备字段
- const reverseMapping = this.getReverseMapping();
- const newReportData = { ...reportData };
- if (newReportData.nonSumList && Array.isArray(newReportData.nonSumList)) {
- newReportData.nonSumList = newReportData.nonSumList.map(item => {
- // 检查这个字段是否是生产日报字段
- const deviceField = reverseMapping[item.name];
- if (deviceField && this.totals.hasOwnProperty(deviceField)) {
- // 如果是累计字段,使用 store 中的累计值
- return {
- ...item,
- fillContent: this.totals[deviceField].toString()
- };
- }
- return item;
- });
- }
- return newReportData;
- }
- },
- });
|