huangjiayang
2025-04-21 3dc60eec20715fcf8336f9efe138d4f1bb012f22
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
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="事件描述" prop="description">
        <el-input
          v-model="queryParams.description"
          placeholder="请输入事件描述"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="持续时长" prop="duration">-->
<!--        <el-input-->
<!--          v-model="queryParams.duration"-->
<!--          placeholder="请输入持续时长"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="事件开始日期" prop="startDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.startDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择事件开始日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="事件结束日期" prop="endDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.endDate"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择事件结束日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="事件开始时间" prop="startTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.startTime"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择事件开始时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="事件结束时间" prop="endTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.endTime"-->
<!--          type="date"-->
<!--          value-format="YYYY-MM-DD"-->
<!--          placeholder="请选择事件结束时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['core:event:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['core:event:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['core:event:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['core:event:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
 
    <HxlhTable
        style="width: 100%"
        :columns="columns"
        :data="eventList"
        :loading="loading"
        :height="height"
        :page="page"
        @changePageNo="changePageNo"
        @changePageSize="changePageSize"
        @on-checkbox="handleCheckboxChange"
    >
 
      <template #buttons="{row}">
        <vxe-button mode="text" @click="handleUpdate(row)" v-hasPermi="['plant:edit']" >修改</vxe-button>
      </template>
    </HxlhTable>
 
    <!-- 添加或修改事件管理对话框 -->
    <el-dialog :title="title" v-model="open" width="700px" append-to-body>
      <el-form ref="eventRef" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="事件描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入事件描述" />
        </el-form-item>
        <el-form-item label="事件开始日期" prop="startDate">
          <el-date-picker clearable
                          v-model="form.startDateTime"
                          type="datetime"
                          format="YYYY-MM-DD HH:mm"
                          date-format="YYYY-MM-DD"
                          time-format="hh:mm"
                          value-format="YYYY-MM-DD HH:mm"
                          placeholder="请选择事件开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="事件结束日期" prop="endDate">
          <el-date-picker clearable
                          v-model="form.endDateTime"
                          type="datetime"
                          format="YYYY-MM-DD HH:mm"
                          date-format="YYYY-MM-DD"
                          time-format="hh:mm"
                          value-format="YYYY-MM-DD HH:mm"
                          placeholder="请选择事件结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="持续时长" prop="duration">
          <el-input type="number" v-model="form.duration" placeholder="请输入持续时长" style="width: 150px" min="0"/>&nbsp;小时
        </el-form-item>
        <el-form-item label="适用工厂" prop="applicableFactory">
          <el-select v-model="form.applicableFactory" placeholder="请选择适用工厂" @change="changePlant($event)">
            <el-option
                v-for="plant in plantList"
                :key="plant.id"
                :label="plant.plantName"
                :value="plant.plantCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="适用车间" prop="applicableWorkshop">
          <el-select v-model="form.applicableWorkshop" placeholder="请选择适用车间" filterable>
            <el-option
                v-for="shop in shopList"
                :key="shop.id"
                :label="shop.shopName"
                :value="shop.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="适用工序" prop="applicableProcess">
          <el-select v-model="form.applicableProcess" placeholder="请选择适用工序" filterable>
            <el-option
                v-for="process in processList"
                :key="process.id"
                :label="process.processName"
                :value="process.processName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="适用日历" prop="applicableCalendar">
          <el-select v-model="form.applicableCalendar" placeholder="请选择适用日历">
            <el-option label="Zone one" value="shanghai" />
            <el-option label="Zone two" value="beijing" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup name="Event">
import { listEvent, getEvent, delEvent, addEvent, updateEvent } from "@/api/basicData/event";
import { listAll_plant } from "@/api/basicData/plant";
import { listAll_shop, listAps_shop } from "@/api/basicData/shop";
import { selectProcessNameList } from "@/api/basicData/processRoute.js";
import HxlhTable from '@/components/HxlhTable'
import axios from "axios";
 
const { proxy } = getCurrentInstance();
 
const eventList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const plantList = ref([]);
const shopList = ref([]);
const allShopList = ref([]);
const processList = ref([]);
 
const height = ref(document.documentElement.clientHeight - 230 + "px;")
 
// 多选框选中数据
const handleCheckboxChange = (data) => {
  ids.value = data.records.map(item => item.id);
  single.value = data.records.length !== 1;
  multiple.value = !data.records.length;
};
 
// 分页属性
const page = ref({
  total: 0,
  current: 1,
  size: 10
});
// 表格配置
const columns = ref([
  { type: 'checkbox', width: 60, align:"center"},
  { type: 'seq', title: '序号', width: 60, align: 'center' },
  {
    title: '事件描述',
    field: 'description',
    width: 150,
    align: 'center'
  },
  {
    title: '持续时长',
    field: 'duration',
    width: 150,
    align: 'center'
  },
  {
    title: '事件开始日期',
    field: 'startDate',
    width: 150,
    align: 'center'
  },
  {
    title: '事件结束日期',
    field: 'endDate',
    width: 150,
    align: 'center'
  },
  {
    title: '事件开始时间',
    field: 'startTime',
    width: 150,
    align: 'center'
  },
  {
    title: '事件结束时间',
    field: 'endTime',
    width: 150,
    align: 'center'
  },
  {
    title: '适用工厂',
    field: 'applicableFactory',
    width: 150,
    align: 'center',
    formatter: (({ cellValue, row, column }) => {
      if (cellValue) {
        for(let i=0;i<plantList.value.length;i++){
          if(cellValue===plantList.value[i].plantCode){
            return plantList.value[i].plantName
          }
        }
      }
      return '';
    })
  },
  {
    title: '适用车间',
    field: 'applicableWorkshop',
    width: 150,
    align: 'center',
    formatter: (({ cellValue, row, column }) => {
      if (cellValue) {
        for(let i=0;i<allShopList.value.length;i++){
          if(cellValue===allShopList.value[i].id){
            return allShopList.value[i].shopName
          }
        }
      }
      return '';
    })
  },
  {
    title: '适用工序',
    field: 'applicableProcess',
    width: 150,
    align: 'center'
  },
  {
    title: '适用日历',
    field: 'applicableCalendar',
    width: 150,
    align: 'center'
  },
  { title: '操作', width: 100, fixed:"right", slots: { default: 'buttons' }, align: 'center' }
]);
 
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    description: null,
    duration: null,
    startDate: null,
    endDate: null,
    startTime: null,
    endTime: null,
    applicableFactory: null,
    applicableWorkshop: null,
    applicableProcess: null,
    applicableCalendar: null,
    startDateTime: null,
    endDateTime: null
  },
  rules: {
    description: [
      { required: true, message: "事件描述不能为空", trigger: "blur" }
    ],
    duration: [
      { required: true, message: "持续时长不能为空", trigger: "blur" }
    ],
    startDate: [
      { required: true, message: "事件开始日期不能为空", trigger: "blur" }
    ],
    endDate: [
      { required: true, message: "事件结束日期不能为空", trigger: "blur" }
    ],
    startTime: [
      { required: true, message: "事件开始时间不能为空", trigger: "blur" }
    ],
    endTime: [
      { required: true, message: "事件结束时间不能为空", trigger: "blur" }
    ],
    applicableFactory: [
      { required: true, message: "适用工厂不能为空", trigger: "change" }
    ],
    applicableWorkshop: [
      { required: true, message: "适用车间不能为空", trigger: "change" }
    ],
    applicableProcess: [
      { required: true, message: "适用工序不能为空", trigger: "change" }
    ],
    applicableCalendar: [
      { required: true, message: "适用日历不能为空", trigger: "change" }
    ],
  }
});
 
const { queryParams, form, rules } = toRefs(data);
 
/** 查询事件管理列表 */
function getList() {
  axios.all([
    /** 查询事件列表 **/
    listEvent(queryParams.value),
    /** 查询工厂列表 */
    listAll_plant({}),
    /** 查询车间列表 */
    listAll_shop({})
  ])
  .then(axios.spread((response1, response2, response3) => {
    eventList.value = response1.rows;
    plantList.value = response2.data;
    allShopList.value = response3.data;
    total.value = response1.total;
    loading.value = false;
  }))
  .catch(error => {
    console.error('请求出错:', error);
  });
 
 
  loading.value = true;
  listEvent(queryParams.value).then(response => {
 
    loading.value = false;
  });
}
 
// 取消按钮
function cancel() {
  open.value = false;
  reset();
}
 
// 表单重置
function reset() {
  form.value = {
    id: null,
    description: null,
    duration: null,
    startDate: null,
    endDate: null,
    startTime: null,
    endTime: null,
    applicableFactory: null,
    applicableWorkshop: null,
    applicableProcess: null,
    applicableCalendar: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    startDateTime: null,
    endDateTime: null
  };
  proxy.resetForm("eventRef");
}
 
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
 
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
 
// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
 
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "新增事件";
}
 
/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getEvent(_id).then(response => {
    form.value = response.data;
    form.value.startDateTime = form.value.startDate + " " + form.value.startTime;
    form.value.endDateTime = form.value.endDate + " " + form.value.endTime;
    changePlant(form.value.applicableFactory);
    open.value = true;
    title.value = "修改事件管理";
  });
}
 
/** 提交按钮 */
function submitForm() {
  proxy.$refs["eventRef"].validate(valid => {
    if (valid) {
      form.value.startDate = form.value.startDateTime.split(" ")[0];
      form.value.endDate = form.value.endDateTime.split(" ")[0];
      form.value.startTime = form.value.startDateTime.split(" ")[1];
      form.value.endTime = form.value.endDateTime.split(" ")[1];
      if (form.value.id != null) {
        updateEvent(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addEvent(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
 
/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除事件管理编号为"' + _ids + '"的数据项?').then(function() {
    return delEvent(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}
 
/** 导出按钮操作 */
function handleExport() {
  proxy.download('/aps/event/export', {
    ...queryParams.value
  }, `event_${new Date().getTime()}.xlsx`)
}
 
/** 选择工厂后事件 加载车间 和 工序 **/
function changePlant(plant){
  listAps_shop({"plantCode": plant}).then(response => {
    shopList.value = response.rows;
  })
  selectProcessNameList({"orgCode": plant}).then(response => {
    processList.value = response.rows;
  })
}
 
function changePageNo(currentPage) {
  queryParams.value.pageNum = currentPage;
  page.value.current = currentPage;
  getList();
}
 
function changePageSize(pageSize) {
  page.value.current = 1;
  queryParams.value.pageNum = 1;
  queryParams.value.pageSize = pageSize;
  getList();
}
 
/** 初始化数据 **/
onMounted(()=>{})
 
getList();
</script>