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
<template>
  <div class="intelligent-scheduling">
    <!-- 搜索表单 -->
    <el-card class="search-form-card" shadow="never">
      <el-form :inline="true" :model="searchParams" class="search-form">
        <el-form-item label="时间范围">
          <el-date-picker
            v-model="searchParams.dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :shortcuts="dateShortcuts"
          />
        </el-form-item>
        <el-form-item label="煤种">
          <el-input v-model="searchParams.coalType" placeholder="请输入煤种" clearable />
        </el-form-item>
        <el-form-item label="排产状态">
          <el-select v-model="searchParams.status" placeholder="请选择排产状态" clearable style="width: 200px">
            <el-option label="全部" value="" />
            <el-option label="待排产" value="pending" />
            <el-option label="排产中" value="processing" />
            <el-option label="已完成" value="completed" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch" :loading="loading">查询</el-button>
          <el-button @click="handleReset">重置</el-button>
          <el-button type="success" @click="handleRandomScheduling">随机排产</el-button>
        </el-form-item>
      </el-form>
    </el-card>
 
    <!-- 统计卡片 -->
    <div class="stats-cards">
      <div class="stat-card">
        <div class="card-icon">
          <i class="el-icon-s-order" />
        </div>
        <div class="card-content">
          <div class="card-title">总排产量</div>
          <div class="card-value">{{ totalScheduledQuantity.toFixed(2) }} 吨</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="card-icon">
          <i class="el-icon-check" />
        </div>
        <div class="card-content">
          <div class="card-title">已完成排产</div>
          <div class="card-value">{{ completedScheduledQuantity.toFixed(2) }} 吨</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="card-icon">
          <i class="el-icon-time" />
        </div>
        <div class="card-content">
          <div class="card-title">待排产</div>
          <div class="card-value">{{ pendingScheduledQuantity.toFixed(2) }} 吨</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="card-icon">
          <i class="el-icon-warning" />
        </div>
        <div class="card-content">
          <div class="card-title">库存预警</div>
          <div class="card-value">{{ stockWarningCount }} 项</div>
        </div>
      </div>
    </div>
 
    <!-- 库存原料列表 -->
    <el-card class="stock-materials-card" shadow="never">
      <template #header>
        <div class="card-header">
          <span>库存原料</span>
        </div>
      </template>
      <el-table v-loading="loading" :data="stockMaterials" style="width: 100%">
        <el-table-column prop="id" label="序号" width="80" type="index" />
        <el-table-column prop="coalType" label="煤种" width="120" />
        <el-table-column prop="origin" label="产地" width="120" />
        <el-table-column prop="calorificValue" label="热值" width="120" />
        <el-table-column prop="currentStock" label="当前库存(吨)" width="150" align="right">
          <template #default="scope">
            <span :class="{ 'stock-warning': scope.row.currentStock < scope.row.minStock }">
              {{ scope.row.currentStock.toFixed(2) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="minStock" label="最低库存(吨)" width="150" align="right">
          <template #default="scope">{{ scope.row.minStock.toFixed(2) }}</template>
        </el-table-column>
        <el-table-column prop="unit" label="单位" width="80" />
        <el-table-column prop="updateTime" label="更新时间" width="180" />
      </el-table>
    </el-card>
 
    <!-- 排产结果列表 -->
    <el-card class="scheduling-results-card" shadow="never">
      <template #header>
        <div class="card-header">
          <span>排产结果</span>
        </div>
      </template>
      <el-table v-loading="loading" :data="schedulingResults" style="width: 100%">
        <el-table-column prop="code" label="排产编码" width="180" />
        <el-table-column prop="productionLine" label="生产线" width="120" />
        <el-table-column prop="coalType" label="煤种" width="120" />
        <el-table-column prop="quantity" label="排产数量(吨)" width="150" align="right">
          <template #default="scope">{{ scope.row.quantity.toFixed(2) }}</template>
        </el-table-column>
        <el-table-column prop="scheduleTime" label="排产时间" width="180" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag
              :type="scope.row.status === 'completed' ? 'success' : scope.row.status === 'processing' ? 'warning' : 'info'"
              size="small"
            >
              {{ scope.row.status === 'completed' ? '已完成' : scope.row.status === 'processing' ? '排产中' : '待排产' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="200" />
      </el-table>
    </el-card>
  </div>
</template>
 
<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
 
// 搜索参数
const searchParams = ref({
  dateRange: [],
  coalType: '',
  status: ''
})
 
// 日期快捷选项
const dateShortcuts = [
  {
    text: '今天',
    value: () => {
      const end = new Date()
      const start = new Date()
      return [start, end]
    }
  },
  {
    text: '昨天',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24)
      return [start, end]
    }
  },
  {
    text: '近7天',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    }
  },
  {
    text: '近30天',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    }
  },
  {
    text: '本月',
    value: () => {
      const end = new Date()
      const start = new Date(end.getFullYear(), end.getMonth(), 1)
      return [start, end]
    }
  }
]
 
// 统计数据
const totalScheduledQuantity = ref(0)
const completedScheduledQuantity = ref(0)
const pendingScheduledQuantity = ref(0)
const stockWarningCount = ref(0)
 
// 库存原料数据
const stockMaterials = ref([
  { id: 1, coalType: '烟煤', origin: '山西', calorificValue: '5300大卡', currentStock: 1200.5, minStock: 500, unit: '吨', updateTime: '2023-05-07 09:30:15' },
  { id: 2, coalType: '无烟煤', origin: '内蒙古', calorificValue: '5800大卡', currentStock: 800.2, minStock: 400, unit: '吨', updateTime: '2023-05-07 10:15:30' },
  { id: 3, coalType: '褐煤', origin: '新疆', calorificValue: '4200大卡', currentStock: 350.8, minStock: 400, unit: '吨', updateTime: '2023-05-07 11:05:45' },
  { id: 4, coalType: '贫煤', origin: '陕西', calorificValue: '5100大卡', currentStock: 900.0, minStock: 300, unit: '吨', updateTime: '2023-05-07 13:20:00' },
  { id: 5, coalType: '瘦煤', origin: '贵州', calorificValue: '5400大卡', currentStock: 650.5, minStock: 350, unit: '吨', updateTime: '2023-05-07 14:45:15' }
])
 
// 排产结果数据
const schedulingResults = ref([
  { code: 'PS20230507001', productionLine: '生产线1', coalType: '烟煤', quantity: 200.5, scheduleTime: '2023-05-07 09:30:15', status: 'completed', remark: '按计划完成' },
  { code: 'PS20230507002', productionLine: '生产线2', coalType: '无烟煤', quantity: 150.2, scheduleTime: '2023-05-07 10:15:30', status: 'processing', remark: '正在进行中' },
  { code: 'PS20230507003', productionLine: '生产线3', coalType: '贫煤', quantity: 180.0, scheduleTime: '2023-05-07 11:05:45', status: 'pending', remark: '等待排产' }
])
 
// 加载状态
const loading = ref(false)
 
// 计算统计数据
const calculateStats = () => {
  // 计算总排产量
  totalScheduledQuantity.value = schedulingResults.value.reduce((sum, item) => sum + item.quantity, 0)
  
  // 计算已完成排产
  completedScheduledQuantity.value = schedulingResults.value
    .filter(item => item.status === 'completed')
    .reduce((sum, item) => sum + item.quantity, 0)
  
  // 计算待排产
  pendingScheduledQuantity.value = schedulingResults.value
    .filter(item => item.status === 'pending')
    .reduce((sum, item) => sum + item.quantity, 0)
  
  // 计算库存预警数量
  stockWarningCount.value = stockMaterials.value.filter(item => item.currentStock < item.minStock).length
}
 
// 生成排产编码
const generateSchedulingCode = () => {
  const date = new Date()
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const random = Math.floor(Math.random() * 1000).toString().padStart(3, '0')
  return `PS${year}${month}${day}${random}`
}
 
// 随机排产
const handleRandomScheduling = async () => {
  try {
    loading.value = true
    
    // 模拟API请求延迟
    await new Promise(resolve => setTimeout(resolve, 1000))
    
    // 获取有库存的原料
    const availableMaterials = stockMaterials.value.filter(item => item.currentStock > 0)
    
    if (availableMaterials.length === 0) {
      ElMessage.warning('没有可用的库存原料')
      return
    }
    
    // 随机选择原料
    const randomMaterial = availableMaterials[Math.floor(Math.random() * availableMaterials.length)]
    
    // 随机生成排产数量(不超过库存的50%)
    const maxQuantity = randomMaterial.currentStock * 0.5
    const quantity = Math.max(50, Math.random() * maxQuantity) // 至少排产50吨
    
    // 随机选择生产线
    const productionLines = ['生产线1', '生产线2', '生产线3']
    const randomLine = productionLines[Math.floor(Math.random() * productionLines.length)]
    
    // 生成新的排产计划
    const newScheduling = {
      code: generateSchedulingCode(),
      productionLine: randomLine,
      coalType: randomMaterial.coalType,
      quantity: quantity,
      scheduleTime: new Date().toLocaleString('zh-CN'),
      status: 'pending',
      remark: '随机排产生成'
    }
    
    // 添加到排产结果列表
    schedulingResults.value.unshift(newScheduling)
    
    // 更新库存数量
    randomMaterial.currentStock -= quantity
    
    // 更新统计数据
    calculateStats()
    
    ElMessage.success('随机排产成功')
  } catch (error) {
    console.error('随机排产失败:', error)
    ElMessage.error('随机排产失败,请稍后重试')
  } finally {
    loading.value = false
  }
}
 
// 查询数据
const handleSearch = async () => {
  try {
    loading.value = true
    
    // 模拟API请求延迟
    await new Promise(resolve => setTimeout(resolve, 800))
    
    // 这里可以根据搜索条件过滤数据
    // 实际应用中应该调用API获取数据
    
    ElMessage.success('查询成功')
  } catch (error) {
    console.error('查询失败:', error)
    ElMessage.error('查询失败,请稍后重试')
  } finally {
    loading.value = false
  }
}
 
// 重置搜索参数
const handleReset = () => {
  searchParams.value = {
    dateRange: [],
    coalType: '',
    status: ''
  }
  
  // 重置后重新查询
  handleSearch()
}
 
// 初始化页面
onMounted(() => {
  // 默认查询近7天数据
  const end = new Date()
  const start = new Date()
  start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  searchParams.value.dateRange = [start, end]
  
  // 计算统计数据
  calculateStats()
  
  // 初始加载数据
  handleSearch()
})
</script>
 
<style scoped>
.intelligent-scheduling {
  padding: 20px;
}
 
.page-header {
  margin-bottom: 20px;
}
 
.page-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
}
 
.search-form-card {
  margin-bottom: 20px;
}
 
.search-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
 
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
 
.stat-card {
  display: flex;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}
 
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
 
.card-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 24px;
  margin-right: 16px;
}
 
.stat-card:nth-child(1) .card-icon {
  background: #ECF5FF;
  color: #409EFF;
}
 
.stat-card:nth-child(2) .card-icon {
  background: #F6FFED;
  color: #52C41A;
}
 
.stat-card:nth-child(3) .card-icon {
  background: #FFF7E6;
  color: #FAAD14;
}
 
.stat-card:nth-child(4) .card-icon {
  background: #FFF1F0;
  color: #F5222D;
}
 
.card-content {
  flex: 1;
}
 
.card-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 8px;
}
 
.card-value {
  font-size: 24px;
  font-weight: 600;
  color: #303133;
}
 
.stock-materials-card,
.scheduling-results-card {
  margin-bottom: 24px;
}
 
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #EBEEF5;
}
 
.card-header span {
  font-weight: 600;
  color: #303133;
}
 
.stock-warning {
  color: #F5222D;
  font-weight: 500;
}
 
/* 响应式布局 */
@media (max-width: 768px) {
  .intelligent-scheduling {
    padding: 10px;
  }
  
  .stats-cards {
    grid-template-columns: 1fr;
  }
  
  .search-form {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-form .el-form-item {
    margin-right: 0;
    margin-bottom: 10px;
  }
}
</style>