廖井涛
2024-03-07 f60327c377097f67ed42c349bda2a54c3147b7be
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<script setup>
 
import request from "@/utils/request"
import deepClone from "@/utils/deepClone"
import {ElDatePicker, ElMessage} from "element-plus"
import useProductGlassTypeStore from "@/stores/sd/product/productGlassType"
import {nextTick, onMounted, onUnmounted, reactive, ref, watch} from "vue"
import {Search} from "@element-plus/icons-vue"
import GlassType from "@/components/sd/product/GlassType.vue"
import {useRouter} from 'vue-router'
import Sortable from 'sortablejs'
import BasicTable from '@/components/basic/BasicTable.vue'
import {VXETable} from "vxe-table";
import useUserInfoStore from "@/stores/userInfo";
 
let router = useRouter()
const userStore = useUserInfoStore()
const username = userStore.user.userName
const getTableRow = (row, type) => {
  switch (type) {
    case 'edit' : {
      //alert('我接收到子组件传送的编辑信息')
      router.push({path: '/main/processCard/PrintFlowCard', query: {id: row.id}})
      break
    }
 
    case  'setType': {
      alert('我接收到子组件传送的排版状态')
      break
    }
  }
}
 
//工序
const value = ref('')
const options = [
  {
    value: '切割',
    label: '切割',
  },
  {
    value: '磨边',
    label: '磨边',
  },
  {
    value: '钢化',
    label: '钢化',
  },
]
 
//排产状态
const stateValue = ref('1')
const stateOptions = [
  {
    value: '2',
    label: '已排产',
  },
  {
    value: '1',
    label: '未排产',
  },
]
 
function padLeftZero(str) {
  return ('00' + str).substr(str.length)
}
 
//定义表单值
const form = reactive({
  date1: '',
  orderId: ''
})
 
 
//表尾求和
const sumNum = (list, field) => {
  let count = 0
  list.forEach(item => {
    count += Number(item[field])
  })
  return count.toFixed(2)
}
 
//定义滚动条高度
let scrollTop = ref(null)
let scrollHeight = ref(null)
let clientHeight = ref(null)
const scrollEvnt = (row) => {
  // 内容高度
  scrollTop.value = row.$event.target.scrollTop
  scrollHeight.value = row.$event.target.scrollHeight
  clientHeight.value = row.$event.target.clientHeight
}
//筛选条件,有外键需要先定义明细里面的数据
let filterData = ref({
  order: {
    project: ''
  },
  orderDetail: {
    productId: '',
    productName: '',
    computeGrossArea: '',
    processingNote: '',
  }
 
})
//定义页面总页数
let pageTotal = ref('')
//定义数据返回结果
let produceList = ref([])
//定义当前页数
let pageNum = $ref(1)
let pageState = null
 
 
//获取七天前到当前时间
function getNowTime() {
  const start = new Date(new Date().getTime() - 3600 * 1000 * 24 * 7)
      .toISOString()
      .replace('T', ' ')
      .slice(0, 10) //默认开始时间7天前
  const end = new Date(new Date().getTime() + 3600 * 1000 * 24)
      .toISOString()
      .replace('T', ' ')
      .slice(0, 10)//默认结束时间当前时间
  return [start, end]
}
 
//第一次加载获取近七天时间和默认状态
form.date1 = getNowTime()
let startTime = form.date1[0]
let endTime = form.date1[1]
//第一次加载数据
 
request.post(`/productionScheduling/selectLastScheduling/${startTime}/${endTime}`, filterData.value).then((res) => {
 
  if (res.code == 200) {
    pageTotal.value = res.data.total
    produceList = produceList.value.concat(deepClone(res.data.data))
    xGrid.value.reloadData(produceList)
    gridOptions.loading = false
    //禁用删除、保存按钮
    gridOptions.toolbarConfig.buttons[0].disabled = true
    gridOptions.toolbarConfig.buttons[1].disabled = true
  } else {
    ElMessage.warning(res.msg)
  }
})
 
//点击时查询
const getWorkOrder = () => {
  let startTime = form.date1[0]
  let endTime = form.date1[1]
  let selectProcesses = value.value
  let selectState = stateValue.value
  let inputVal = form.orderId
  if (inputVal == '') {
    inputVal = null
  }
  if (selectProcesses == '') {
    selectProcesses = null
  }
  if (inputVal == null && selectState == 1) {
    //根据时间查询未排产数据
    request.post(`/productionScheduling/selectLastScheduling/${startTime}/${endTime}`, filterData.value).then((res) => {
 
      if (res.code == 200) {
        pageTotal.value = res.data.total
        xGrid.value.loadData(res.data.data)
        gridOptions.loading = false
        //禁用删除、保存按钮
        gridOptions.toolbarConfig.buttons[0].disabled = true
        gridOptions.toolbarConfig.buttons[1].disabled = true
        //启用保存
        gridOptions.toolbarConfig.buttons[2].disabled = false
      } else {
        ElMessage.warning(res.msg)
      }
    })
  } else if (inputVal != null && selectState == 1) {
 
    //根据工序查询未排产数据
    request.post(`/productionScheduling/selectScheduling/${startTime}/${endTime}/${inputVal}/${selectProcesses}/${selectState}`, filterData.value).then((res) => {
      if (res.code == 200) {
        pageTotal.value = res.data.total
        xGrid.value.loadData(res.data.data)
        gridOptions.loading = false
        //禁用删除、保存按钮
        gridOptions.toolbarConfig.buttons[0].disabled = true
        gridOptions.toolbarConfig.buttons[1].disabled = true
        //启用保存
        gridOptions.toolbarConfig.buttons[2].disabled = false
      } else {
        ElMessage.warning(res.msg)
      }
    })
  } else if (inputVal == null && selectState == 2) {
    //根据时间查询已排产数据
    console.log(startTime, endTime, selectProcesses, selectState)
    request.post(`/productionScheduling/selectScheduling/${startTime}/${endTime}/${inputVal}/${selectProcesses}/${selectState}`, filterData.value).then((res) => {
      if (res.code == 200) {
        pageTotal.value = res.data.total
        xGrid.value.loadData(res.data.data)
        gridOptions.loading = false
        //启用删除、保存按钮
        gridOptions.toolbarConfig.buttons[0].disabled = false
        gridOptions.toolbarConfig.buttons[1].disabled = false
        //禁用保存
        gridOptions.toolbarConfig.buttons[2].disabled = true
      } else {
        ElMessage.warning(res.msg)
      }
    })
  } else if (inputVal != null && selectState == 2) {
    //根据订单号查询已排产数据
    request.post(`/productionScheduling/selectSchedulingNot/${startTime}/${endTime}/${inputVal}/${selectProcesses}/${selectState}`, filterData.value).then((res) => {
      if (res.code == 200) {
        pageTotal.value = res.data.total
        xGrid.value.loadData(res.data.data)
        gridOptions.loading = false
        //启用删除、保存按钮
        gridOptions.toolbarConfig.buttons[0].disabled = false
        gridOptions.toolbarConfig.buttons[1].disabled = false
        //禁用保存
        gridOptions.toolbarConfig.buttons[2].disabled = true
      } else {
        ElMessage.warning(res.msg)
      }
    })
  }
 
 
}
 
 
//子组件接收参数
const xGrid = ref()
const gridOptions = reactive({
  border: "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe: true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true, height: 50},//鼠标移动或选择高亮
  id: 'CustomerList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY: {enabled: true},//开启虚拟滚动
  showOverflow: true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
    remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },//表头参数
  columns: [
    {type: 'expand', fixed: "left", slots: {content: 'content'}, width: 50},
    {type: 'checkbox', fixed: "left", title: '选择', width: 80},
    {type: 'seq', fixed: "left", title: '自序', width: 50},
    {
      field: 'scheduled_start_time',
      width: 120,
      editRender: {name: 'input', attrs: {placeholder: '', type: 'date'}},
      title: '计划开始时间'
    },
    {
      field: 'plan_end_time',
      width: 120,
      editRender: {name: 'input', attrs: {placeholder: '', type: 'date'}},
      title: '计划结束时间'
    },
    // {field: '排产编号', title: '排产编号',  width: 120 },
    {field: 'order_id', title: '销售单号', filters: [{data: ''}], slots: {filter: 'num1_filter'}, width: 100},
    {field: 'customer_name', title: '客户名称', width: 110, filters: [{data: ''}], slots: {filter: 'num1_filter'}},
    {field: 'project', title: '项目名称', width: 100, filters: [{data: ''}], slots: {filter: 'num1_filter'}},
    {field: 'order_number', title: '序号', filters: [{data: ''}], slots: {filter: 'num1_filter'}, width: 70},
 
    {field: 'width', title: '宽', width: 60},
    {field: 'height', title: '高', width: 60},
    {field: 'quantity', title: '订单数量', width: 70},
    {field: 'area', title: '订单面积', width: 90},
    {
      field: 'scheduling_quantity',
      width: 120,
      editRender: {name: 'input', attrs: {placeholder: ''}},
      title: '排产数量',
      sortable: true
    },
    {field: 'pendingProductionQuantity', title: '待排产数量', width: 120},
    {field: 'pendingProductionArea', title: '待排产面积', width: 120},
    {field: 'productionScheduledQuantity', title: '已排产数量', width: 120},
    {field: 'productionScheduledArea', title: '已排产面积', width: 120},
    {field: 'review_status', title: '审核状态', width: 140},
    {field: 'reviewer', title: '审核人', width: 140},
    {field: 'product_name', title: '产品名称', width: 140},
    {field: 'shape', title: '形状', width: 80},
    {field: 'notes', title: '备注', editRender: {name: 'input', attrs: {placeholder: ''}}, width: 120},
    {field: 'scheduling_id', title: '排产编号',width: 120},
  ],//表头按钮
 
  toolbarConfig: {
    buttons: [
      {code: 'delete', name: '删除', status: 'primary'},
      {code: 'review', name: '审核', status: 'primary'},
      {code: 'save', name: '排产', status: 'primary', icon: 'vxe-icon-save'},
    ],
    import: false,
    // export: true,
    // print: true,
    zoom: true,
    custom: true
  },
  data: [],//table body实际数据
  //脚部求和
  // footerMethod({columns, data}) {//页脚函数
  //   let footList = ['数量', '面积', '排产数量', '已排产数量', '已排产面积', '未排产数量', '未排产面积']
  //   return [
  //     columns.map((column, columnIndex) => {
  //       if (columnIndex === 0) {
  //         return '合计:'
  //       }
  //       if (footList.includes(column.field)) {
  //         return sumNum(data, column.field)
  //       }
  //       return ''
  //     })
  //   ]
  // }
 
})
 
//删除
 
 
const gridEvents = {
  async toolbarButtonClick({code}) {
    const $grid = xGrid.value
    if ($grid) {
      switch (code) {
        case 'save': {
          const $table = xGrid.value
          if ($table) {
            const selectRecords = $table.getCheckboxRecords()
            if (selectRecords.length == 0) {
              ElMessage.warning("请勾选排产数据")
              return;
            }
            for (let i = 0; i < selectRecords.length; i++) {
              let start = selectRecords[i].scheduled_start_time
              let end = selectRecords[i].plan_end_time
              let number = selectRecords[i].scheduling_quantity
              //计划开始、结束时间,排产数量不能为空
              if (start == null || end == null || number == null) {
                ElMessage.warning("请填入对应的值再进行保存")
                return;
              }
            }
            let selectProcesses = value.value
            if (selectProcesses == null || selectProcesses == "") {
              ElMessage.warning("请选择排产工序")
              return;
            }
 
            let schedulingData = ref({
              scheduling: selectRecords,
              processes: selectProcesses,//工序
              userName: username//审核人
            })
            //保存排产数据
            request.post("/productionScheduling/addScheduling", schedulingData.value).then((res) => {
              if (res.code == 200) {
                ElMessage.success("保存成功")
                location.reload();
              } else {
                ElMessage.warning(res.msg)
 
              }
            })
 
          }
          return;
 
        }
 
        case 'delete': {
          const $table = xGrid.value
          const selectRecords = $table.getCheckboxRecords()
          if ($table) {
            if (selectRecords.length == 0) {
              ElMessage.warning("请勾选排产数据")
              return;
            }
            const type = await VXETable.modal.confirm('您确定要删除该数据?')
            if (type === 'confirm') {
              let schedulingData = ref({
                scheduling: selectRecords,
              })
 
              request.post("/productionScheduling/deleteScheduling",schedulingData.value).then((res) => {
                if (res.code == 200) {
                  ElMessage.success("删除成功")
                  location.reload();
                } else {
                  ElMessage.warning(res.msg)
 
                }
              })
            }
          }
          return;
        }
        case 'review': {
          const $table = xGrid.value
          const selectRecords = $table.getCheckboxRecords()
          if ($table) {
            if (selectRecords.length == 0) {
              ElMessage.warning("请勾选排产数据")
              return;
            }
            let schedulingData = ref({
              scheduling: selectRecords,
              userName: username//审核人
            })
            request.post("/productionScheduling/examineScheduling",schedulingData.value).then((res) => {
              if (res.code == 200) {
                ElMessage.success("审核成功")
                location.reload();
              } else {
                ElMessage.warning(res.msg)
 
              }
            })
 
          }
          return;
        }
      }
    }
  },
 
}
 
const determineNum = () => {
  const $grid = xGrid.value
  const table = $grid.getTableData().fullData
  const selectRecords = $grid.getCheckboxRecords()
  table.forEach((selectRecords) => {
    if (selectRecords.scheduling_quantity > selectRecords.pendingProductionQuantity) {
      ElMessage.warning("排产数量不能大于待排产数量")
      //禁用保存按钮
      //gridOptions.toolbarConfig.buttons[2].disabled = true
    }
 
 
  })
}
 
 
 
 
</script>
 
<template>
  <div class="main-div-customer">
    <div id="selectForm">
      <el-row :gutter="0">
        <el-date-picker
            v-model="form.date1"
            :default-time="defaultTime"
            end-placeholder="结束时间"
            format="YYYY/MM/DD"
            start-placeholder="开始时间"
            type="daterange"
            value-format="YYYY-MM-DD"
 
        />
        &nbsp;&nbsp;
        <el-input v-model="form.orderId" placeholder="销售单号" clearable style="width: 110px"></el-input>
        &nbsp;
        <el-select v-model="value" class="m-2" placeholder="工序" clearable style="width: 90px;">
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
        &nbsp;
        <el-select v-model="stateValue" class="m-2" placeholder="是否排产" style="width: 120px">
          <el-option
              v-for="item in stateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
        &nbsp;&nbsp;
        <el-button
            id="select"
            :icon="Search"
            type="primary" @click="getWorkOrder">查询
        </el-button>
      </el-row>
 
    </div>
    <vxe-grid
        ref="xGrid"
        class="mytable-scrollbar"
        max-height="100%"
        height="100%"
        v-bind="gridOptions"
        v-on="gridEvents"
        @filter-change="filterChanged"
        @checkbox-change="determineNum"
    >
      <!--      @toolbar-button-click="toolbarButtonClickEvent"-->
      <!--      下拉显示所有信息插槽-->
      <template #content="{ row }">
        <ul class="expand-wrapper">
          <li v-for="(item,index) in gridOptions.columns" v-show="item.field!=undefined ">
            <span style="font-weight: bold">{{ item.title + ':  ' }}</span>
            <span v-if="hasDecimal(item.field)">{{ row[item.field.split('.')[0]][item.field.split('.')[1]] }}</span>
            <span v-else>{{ row[item.field] }}</span>
 
          </li>
        </ul>
      </template>
      <template #num1_filter="{ column, $panel }">
        <div>
          <div v-for="(option, index) in column.filters" :key="index">
            <input v-model="option.data" type="type" @input="changeFilterEvent($event, option, $panel)"/>
          </div>
        </div>
      </template>
 
 
    </vxe-grid>
  </div>
</template>
 
<style scoped>
.main-div-customer {
  width: 99%;
  height: 100%;
}
 
#selectForm {
  width: 70%;
  height: 6%;
  text-align: center;
}
</style>