fillingData.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // 在 store/modules/fillingData.js 中更新字段映射
  2. import { defineStore } from "pinia";
  3. export const useFillingDataStore = defineStore("fillingData", {
  4. state: () => ({
  5. // 存储所有设备的填写数据
  6. deviceFillings: new Map(), // key: deviceId, value: {设备数据}
  7. // 存储累计值(根据 data.txt 中的生产日报字段调整)
  8. totals: {
  9. "当日运转时间H": 0, // 对应空压机、空气处理撬、液驱机、中压增压撬等
  10. "当日注气量-方": 0, // 对应提纯撬
  11. "当日注水量-方": 0, // 对应注水泵(虽然数据中没有,但保留逻辑)
  12. "当日用电量kWh": 0, // 对应箱式变电站
  13. },
  14. }),
  15. actions: {
  16. // 更新设备数据并重新计算累计值
  17. updateDeviceFilling(deviceId, deviceData) {
  18. this.deviceFillings.set(deviceId, deviceData);
  19. this.calculateTotals();
  20. },
  21. // 更新单个填写项
  22. updateFillingItem(deviceId, deviceName, itemName, value) {
  23. const deviceData = this.deviceFillings.get(deviceId) || {
  24. deviceId,
  25. deviceName,
  26. };
  27. if (!deviceData.nonSumList) deviceData.nonSumList = [];
  28. // 查找或创建对应项
  29. const itemIndex = deviceData.nonSumList.findIndex(
  30. (item) => item.name === itemName
  31. );
  32. if (itemIndex >= 0) {
  33. deviceData.nonSumList[itemIndex].fillContent = value;
  34. } else {
  35. deviceData.nonSumList.push({
  36. name: itemName,
  37. fillContent: value,
  38. type: "double",
  39. });
  40. }
  41. this.updateDeviceFilling(deviceId, deviceData);
  42. },
  43. // 计算所有累计值(根据 data.txt 数据调整逻辑)
  44. calculateTotals() {
  45. // 重置累计值
  46. const newTotals = {
  47. "当日运转时间H": 0,
  48. "当日注气量-方": 0,
  49. "当日注水量-方": 0,
  50. "当日用电量kWh": 0,
  51. };
  52. // 遍历所有设备数据
  53. this.deviceFillings.forEach((deviceData) => {
  54. if (
  55. deviceData.nonSumList &&
  56. deviceData.deviceName &&
  57. !deviceData.isProductionReport
  58. ) {
  59. const { deviceName, nonSumList } = deviceData;
  60. // 根据设备名称和字段名判断是否需要累加
  61. nonSumList.forEach((item) => {
  62. // 确保 fillContent 是数字类型再进行计算
  63. const value = parseFloat(item.fillContent) || 0;
  64. // 需要累加的设备类型和字段(根据 data.txt 数据调整)
  65. if (
  66. (deviceName.includes("空压机") ||
  67. deviceName.includes("空气处理撬") ||
  68. deviceName.includes("液驱机") ||
  69. deviceName.includes("中压增压撬") ||
  70. deviceName.includes("增压机")) && // 包含所有运转时间的设备
  71. item.name === "当日运转时间H"
  72. ) {
  73. newTotals["当日运转时间H"] += value;
  74. } else if (
  75. deviceName.includes("提纯撬") &&
  76. item.name === "当日注气量-方"
  77. ) {
  78. newTotals["当日注气量-方"] += value;
  79. } else if (
  80. deviceName.includes("注水泵") &&
  81. item.name === "当日注水量-方"
  82. ) {
  83. newTotals["当日注水量-方"] += value;
  84. } else if (
  85. deviceName.includes("箱式变电站") &&
  86. item.name === "当日用电量kWh"
  87. ) {
  88. newTotals["当日用电量kWh"] += value;
  89. }
  90. });
  91. }
  92. });
  93. this.totals = newTotals;
  94. return newTotals;
  95. },
  96. // 获取指定字段的累计值
  97. getTotal(fieldName) {
  98. return this.totals[fieldName] || 0;
  99. },
  100. // 获取所有累计值
  101. getAllTotals() {
  102. return { ...this.totals };
  103. },
  104. // 检查是否是需要累加的字段
  105. isAccumulatedField(deviceName, fieldName) {
  106. return (
  107. // 空压机等设备 -> 当日运转时间H
  108. ((deviceName.includes("空压机") ||
  109. deviceName.includes("空气处理撬") ||
  110. deviceName.includes("液驱机") ||
  111. deviceName.includes("中压增压撬") ||
  112. deviceName.includes("增压机")) &&
  113. fieldName === "当日运转时间H") ||
  114. // 提纯撬 -> 当日注气量-方
  115. (deviceName.includes("提纯撬") && fieldName === "当日注气量-方") ||
  116. // 注水泵 -> 当日注水量-方
  117. (deviceName.includes("注水泵") && fieldName === "当日注水量-方") ||
  118. // 箱式变电站 -> 当日用电量kWh
  119. (deviceName.includes("箱式变电站") && fieldName === "当日用电量kWh")
  120. );
  121. },
  122. // 清理指定工单的数据
  123. clearData(orderId) {
  124. // 这里可以根据 orderId 清理特定工单的数据
  125. // 简单实现:清理所有数据
  126. this.deviceFillings.clear();
  127. this.totals = {
  128. "当日运转时间H": 0,
  129. "当日注气量-方": 0,
  130. "当日注水量-方": 0,
  131. "当日用电量kWh": 0,
  132. };
  133. },
  134. // 获取需要同步到生产日报的字段映射(根据 data.txt 中的生产日报字段)
  135. getProductionReportMapping() {
  136. return {
  137. // 设备字段名: 生产日报字段名
  138. "当日运转时间H": "当日运转时间H",
  139. "当日注气量-方": "当日注气量-方",
  140. "当日注水量-方": "当日注水量-方",
  141. "当日用电量kWh": "当日用电量kWh",
  142. };
  143. },
  144. // 获取生产日报字段到设备字段的反向映射
  145. getReverseMapping() {
  146. const mapping = this.getProductionReportMapping();
  147. const reverseMapping = {};
  148. for (const [deviceField, reportField] of Object.entries(mapping)) {
  149. reverseMapping[reportField] = deviceField;
  150. }
  151. return reverseMapping;
  152. },
  153. // 更新生产日报字段
  154. updateProductionReportFields(reportData) {
  155. // 获取反向映射,从生产日报字段到设备字段
  156. const reverseMapping = this.getReverseMapping();
  157. const newReportData = { ...reportData };
  158. if (newReportData.nonSumList && Array.isArray(newReportData.nonSumList)) {
  159. newReportData.nonSumList = newReportData.nonSumList.map(item => {
  160. // 检查这个字段是否是生产日报字段
  161. const deviceField = reverseMapping[item.name];
  162. if (deviceField && this.totals.hasOwnProperty(deviceField)) {
  163. // 如果是累计字段,使用 store 中的累计值
  164. return {
  165. ...item,
  166. fillContent: this.totals[deviceField].toString()
  167. };
  168. }
  169. return item;
  170. });
  171. }
  172. return newReportData;
  173. }
  174. },
  175. });