CD配唱片
2025-04-28 3a83082e618461f12d77d2455d11911b2061abb6
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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<template>
  <div class="app-container">
    <el-form
      class="responsive-form"
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-row type="flex" justify="left">
        <el-form-item label="统计方式">
          <el-select
            v-model="queryParams.searchType"
            style="width: 200px"
            placeholder="Select"
            @change="handleChangeSelectType"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="选择区间">
          <div v-if="!dayCom">
            <el-date-picker
              v-model="queryParams.monthRange"
              type="monthrange"
              range-separator="至"
              start-placeholder="选择开始月份"
              end-placeholder="选择结束月份"
            />
          </div>
          <div v-else>
            <el-date-picker
              v-model="queryParams.monthDays"
              type="month"
              placeholder="选择月份"
            />
          </div>
        </el-form-item>
 
        <el-form-item class="column-with-margin">
          <el-button type="primary" icon="Search" @click="handleQuery"
            >查询</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['aps:apsGasPipingRouteStat:exportExcel']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="Refresh"
          @click="handleRefresh"
          v-hasPermi="['aps:apsGasPipingRouteStat:computeCapacity']"
          :disabled="loading"
          >更新</el-button
        >
      </el-col>
      <right-toolbar @queryTable="handleQuery" :search="false"></right-toolbar>
    </el-row>
    <!-- <div class="box_container"> -->
      <!-- <div class="title_text">管路规划产能负载统计</div> -->
      <!-- <div class="tabel_container"> -->
        <vxe-grid
          ref="gridRef"
          v-bind="gridOptions"
          :loading="loading"
        ></vxe-grid>
      <!-- </div> -->
    <!-- </div> -->
  </div>
</template>
 
<script setup name="gasProduceStatics">
import {
  listUpdateGasProduceStatics,
  listGasProduceStatics,
} from "@/api/mainPlan/gasProduceStatics.js";
import { ref } from "vue";
import * as XLSX from "xlsx";
import { ElMessage } from "element-plus";
const { proxy } = getCurrentInstance();
 
const loading = ref(false);
const gridRef = ref();
const height = ref(document.documentElement.clientHeight - 180 + "px;");
const headers = ref([]);
const exportData = ref([]);
const showSearch = ref(true);
const data = reactive({
  queryParams: {
    monthRange: "",
    monthDays: "",
    searchType: "按月统计",
  },
});
let searchTypeValue = ref("month");
const options = [
  {
    value: "month",
    label: "按月统计",
  },
  {
    value: "day",
    label: "按日统计",
  },
];
const { queryParams } = toRefs(data);
const gridOptions = reactive({
  border: true,
  stripe: true,
  loading: false,
  showOverflow: true,
  eaderOverflow: true,
  showFooterOverflow: true,
  height: height,
  columnConfig: {
    resizable: true,
  },
  scrollX: {
    enabled: true,
    gt: 0,
    threshold: 50,
  },
  scrollY: {
    enabled: true,
    gt: 0,
    threshold: 50,
  },
});
const dayCom = ref(false);
let tableColumn = [];
let tableData = [];
let merges = [];
function handleChangeSelectType(e) {
  searchTypeValue.value = e;
  if (e === "day") {
    dayCom.value = true;
  } else {
    dayCom.value = false;
  }
}
function dateStr(dateTimeString) {
  const dateTime = new Date(dateTimeString);
  // 提取年份和月份
  const year = dateTime.getFullYear();
  const month = String(dateTime.getMonth() + 1).padStart(2, "0"); // 月份从0开始,所以需要加1,并用padStart补零
  // 格式化年份和月份为 "yyyy-mm" 格式的字符串
  return `${year}-${month}`;
}
function dateRangeStr(monthRange) {
  // 创建一个Date对象
  let sDate = new Date(monthRange[0]);
  let eDate = new Date(monthRange[1]);
  // 获取年份和月份
  let sYear = sDate.getFullYear();
  let sMonth = sDate.getMonth() + 1; // 月份是从0开始的,所以要加1
  let eYear = eDate.getFullYear();
  let eMonth = eDate.getMonth() + 1; // 月份是从0开始的,所以要加1
  // 格式化为"YYYY-MM"的形式
  return {
    sYearMonth: `${sYear}-${sMonth.toString().padStart(2, "0")}`,
    eYearMonth: `${eYear}-${eMonth.toString().padStart(2, "0")}`,
  };
}
/** 查询零件统计表列表 */
function getPipeList() {
  let rowKey = 0;
  let colKey = 0;
  headers.value = [];
  exportData.value = [];
  tableColumn = [];
  tableData = [];
  loading.value = true;
  listGasProduceStatics({
    searchStartDate: !dayCom.value
      ? dateRangeStr(queryParams.value.monthRange).sYearMonth
      : dateStr(queryParams.value.monthDays),
    searchEndDate: !dayCom.value
      ? dateRangeStr(queryParams.value.monthRange).eYearMonth
      : dateStr(queryParams.value.monthDays),
    searchType: searchTypeValue.value,
    major: "piping",
  }).then((response) => {
    console.log(response.data.planTable, "responseresponseresponse");
    const colList = [];
    let headersOne = [];
    let headersTwo = [];
    if (response.code == "200") {
      if (!response.data.planTitle) {
        loading.value = false;
        return;
      }
      headersOne.push("日期");
      headersTwo.push("工序名称");
      colList.push({
        field: "dateCol",
        title: "日期",
        fixed: "left",
        children: [
          {
            field: `resourceName`,
            title: "工序名称",
            width: 250,
            type: "html",
          },
        ],
        width: 160,
      });
      response.data.planTitle.forEach((item) => {
        headersOne.push(item);
        headersOne.push("");
        headersOne.push("");
        headersTwo.push("设计产能");
        headersTwo.push("需求产能");
        headersTwo.push("产能负载");
        colKey++;
        colList.push({
          field: `dateColTime${colKey}`,
          title: item,
          children: [
            { field: `designTimes${colKey}`, title: "设计产能", width: 80 },
            { field: `requireTimes${colKey}`, title: "需求产能", width: 80 },
            {
              field: `capacityLoad${colKey}`,
              title: "产能负载",
              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.data.planTable.map((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}`] = formatCapacityLoad(listItem.designTimes,listItem.requireTimes,listItem.capacityLoad)
            // 0-100 绿色,101-120黄色,大于120红色
              // 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;
          item[`resourceName`] =  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 formatCapacityLoad(designTimes,requireTimes,capacityLoad){
  /**
   * // 0-100 绿色,101-120黄色,大于120红色
    listItem.capacityLoad <= 100
      ? `<font color="red">${listItem.capacityLoad}%</font>`
      : listItem.capacityLoad + "%";
   */
  if(capacityLoad>0&&capacityLoad<=100){
    return `<font color="#85cf60">${capacityLoad}%</font>`
  }else if(designTimes>0&&capacityLoad>101&&capacityLoad<=120){
    return `<font color="#ecb869">${capacityLoad}%</font>`
  }else if(designTimes>0&&capacityLoad>120){
    return `<font color="#f89c9c">${capacityLoad}%</font>`
  }else if(designTimes==0&&requireTimes>0){
    return `<font color="#f56c6c">error</font>`
  }
}
/** 导出按钮操作 */
function handleExport() {
  if (
    (!queryParams.value.monthRange && dayCom.value == false) ||
    (!queryParams.value.monthDays && dayCom.value == true)
  ) {
    ElMessage({
      message: "请选择年月",
      type: "error",
    });
    return;
  }
  proxy.download(
    "/aps/apsGasPipingRouteStat/exportExcel",
    {
      searchStartDate: !dayCom.value
        ? dateRangeStr(queryParams.value.monthRange).sYearMonth
        : dateStr(queryParams.value.monthDays),
      searchEndDate: !dayCom.value
        ? dateRangeStr(queryParams.value.monthRange).eYearMonth
        : dateStr(queryParams.value.monthDays),
      searchType: searchTypeValue.value,
      major: "piping",
    },
    `aps_pipe_produce_statics_${new Date().getTime()}.xlsx`
  );
}
/** 搜索按钮操作 */
function handleQuery() {
  if (
    (!queryParams.value.monthRange && dayCom.value == false) ||
    (!queryParams.value.monthDays && dayCom.value == true)
  ) {
    ElMessage({
      message: "请选择年月",
      type: "error",
    });
    return;
  }
  // queryParams.value.pageNum = 1;
  getPipeList();
}
 
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value.monthRange = "";
  queryParams.value.monthDays = "";
  dayCom.value = false;
  (queryParams.value.searchType = "按月统计"),
    (searchTypeValue.value = "month");
  tableData = [];
  const $grid = gridRef.value;
  if ($grid) {
    $grid.loadColumn([]);
    $grid.loadData([]);
    gridOptions.loading = false;
  }
}
/** 刷新按钮操作 */
function handleRefresh() {
  if (
    (!queryParams.value.monthRange && dayCom.value == false) ||
    (!queryParams.value.monthDays && dayCom.value == true)
  ) {
    ElMessage({
      message: "请选择年月",
      type: "error",
    });
    return;
  }
  loading.value = true;
  listUpdateGasProduceStatics({
    major: "piping",
  }).then((response) => {
    ElMessage({
      message: "数据更新成功",
      type: "success",
    });
    loading.value = false;
    getPipeList();
  });
}
 
// getList();
</script>
<style lang="scss" scoped>
.box_container {
  width: 100%;
  margin: 20px auto;
  background: #fff;
  border-radius: 5px;
  box-shadow: 1px 1px 1px 4px#f1f1f1;
  .title_text {
    padding-top: 20px;
    margin-left: 20px;
  }
  .tabel_container {
    width: 98%;
    margin: 20px auto;
  }
}
</style>