CD配唱片
2025-05-08 e3e17a37d85f50bace525ed019ee0cd8d39143eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['apsPartRouteStat:export']"
          >{{ $t(`common.common.export`) }}</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Refresh"
          @click="handleRefresh"
          :disabled="loading"
          v-hasPermi="['apsPartRouteStat:edit']"
          >{{ $t(`common.common.update`) }}</el-button
        >
      </el-col>
      <right-toolbar @queryTable="getList" :search="false"></right-toolbar>
    </el-row>
    <vxe-grid ref="gridRef" v-bind="gridOptions" :loading="loading"></vxe-grid>
  </div>
</template>
 
<script setup name="apsPartRouteStat">
import { query, updateStat } from "@/api/mainPlan/partRouteStat.js";
import { ref } from "vue";
import * as XLSX from "xlsx";
 
const { proxy } = getCurrentInstance();
import { useI18n } from "vue-i18n"; //要在js中使用国际化
const { t, locale } = useI18n();
const loading = ref(false);
const gridRef = ref();
const height = ref(document.documentElement.clientHeight - 130 + "px;");
const headers = ref([]);
const exportData = ref([]);
 
const gridOptions = reactive({
  border: true,
  stripe: true,
  loading: false,
  showOverflow: true,
  showHeaderOverflow: true,
  showFooterOverflow: true,
  virtualXConfig: {
    enabled: true,
    gt: 0,
  },
  height: height,
  columnConfig: {
    resizable: true,
  },
  scrollX: {
    enabled: true,
    gt: 0,
    threshold: 50,
  },
  scrollY: {
    enabled: true,
    gt: 0,
    threshold: 50,
  },
});
 
let tableColumn = [];
let tableData = [];
let merges = [];
watch(
  locale,
  (newLocale) => {
    getList();
  },
  { immediate: true, deep: true }
);
/** 查询零件统计表列表 */
function getList() {
  let rowKey = 0;
  let colKey = 0;
  headers.value = [];
  exportData.value = [];
  tableColumn = [];
  tableData = [];
  loading.value = true;
  query().then((response) => {
    const colList = [];
    let headersOne = [];
    let headersTwo = [];
    if (response.code == "200") {
      if (!response.planTitle) {
        loading.value = false;
        return;
      }
      headersOne.push(t("plan.table.dateYearMonth"));
      headersTwo.push(t("plan.table.resourceName"));
      colList.push({
        field: "dateCol",
        title: t("plan.table.dateYearMonth"),
        fixed: "left",
        children: [
          {
            field: `resourceName`,
            title: t("plan.table.resourceName"),
            width: 250,
            type: "html",
          },
        ],
        width: 160,
      });
      response.planTitle.forEach((item) => {
        headersOne.push(item);
        headersOne.push("");
        headersOne.push("");
        headersTwo.push(t("plan.table.designWorkingHours"));
        headersTwo.push(t("plan.table.requiredWorkingHours"));
        headersTwo.push(t("plan.table.capacityLoad"));
        colKey++;
        colList.push({
          field: `dateColTime${colKey}`,
          title: item,
          children: [
            {
              field: `designTimes${colKey}`,
              title: t("plan.table.designWorkingHours"),
              width: 80,
            },
            {
              field: `requireTimes${colKey}`,
              title: t("plan.table.requiredWorkingHours"),
              width: 80,
            },
            {
              field: `capacityLoad${colKey}`,
              title: t("plan.table.capacityLoad"),
              width: 80,
              type: "html",
            },
          ],
          width: 160,
        });
      });
 
      headers.value.push(headersOne);
      headers.value.push(headersTwo);
 
      const columnList = [...tableColumn, ...colList];
      const dataList = [];
      let startCol = 1;
 
      //获取map
      response.planTable.forEach((mapItem) => {
        rowKey++;
        let lastCol = startCol + 2;
        merges.push({ s: { r: 0, c: startCol }, e: { r: 0, c: lastCol } });
        startCol = lastCol + 1;
        let data = [];
        const item = {
          id: `${rowKey}`,
        };
        for (const [key, listValue] of Object.entries(mapItem)) {
          data.push(key);
 
          let tableKey = 0;
          let flag = false;
          listValue.forEach((listItem) => {
            tableKey++;
            item[`designTimes${tableKey}`] = listItem.designTimes;
            item[`requireTimes${tableKey}`] = listItem.requireTimes;
            item[`capacityLoad${tableKey}`] =
              listItem.capacityLoad > 100
                ? `<font color="red">${listItem.capacityLoad}%</font>`
                : listItem.capacityLoad + "%";
            data.push(listItem.designTimes);
            data.push(listItem.requireTimes);
            data.push(listItem.capacityLoad + "%");
            if (listItem.capacityLoad > 100) {
              flag = true;
            }
          });
 
          item[`resourceName`] = flag
            ? `<div class='el-badge'><sup class="el-badge__content is-fixed is-dot"></sup>${key}</div>`
            : key;
        }
        exportData.value.push(data);
        dataList.push(item);
      });
 
      const $grid = gridRef.value;
      if ($grid) {
        tableColumn = columnList;
        tableData = [...tableData, ...dataList];
        $grid.loadColumn(tableColumn);
        $grid.loadData(tableData);
        gridOptions.loading = false;
      }
 
      loading.value = false;
    }
  });
}
 
/** 导出按钮操作 */
function handleExport() {
  // 合并表头和数据
  const finalData = [...headers.value, ...exportData.value];
 
  // 将数据转换为 worksheet
  const ws = XLSX.utils.aoa_to_sheet(finalData);
 
  // 合并单元格(如果需要)
  /* ws['!merges'] = [
    { s: { r: 0, c: 1 }, e: { r: 0, c: 3 } },
    { s: { r: 0, c: 0 }, e: { r: 0, c: 0 } }
  ]; */
 
  ws["!merges"] = merges;
 
  // 创建 workbook
  const wb = XLSX.utils.book_new();
  // 将 worksheet 添加到 workbook 中
  XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
  // 导出文件
  XLSX.writeFile(wb, `apsPartRouteStat_${new Date().getTime()}.xlsx`);
}
 
/** 刷新按钮操作 */
function handleRefresh() {
  loading.value = true;
  updateStat().then((response) => {
    if (response.code == "200") {
      ElMessage({
        message: t("plan.message.update"),
        type: "success",
      });
      getList();
      loading.value = false;
    }
  });
}
 
// getList();
</script>