Mr.Zhang
2023-08-21 a1c49eabb69bae2aa33647b0327d867ea4a40b2b
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<template>
  <!-- <TableLayout> -->
  <keep-alive><TableLayout v-permissions="['ext:plansext:query']">
    <!-- 搜索表单 -->
    <el-form slot="search-form" ref="searchForm" :model="searchForm" label-suffix=":" label-width="110px" inline>
      <el-form-item label="物料信息" prop="mixParam">
        <el-input v-model="searchForm.mixParam" placeholder="请输入物料名称/编码" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="成品计划" prop="workPlanCode">
        <el-input v-model="searchForm.workPlanCode" placeholder="请输入成品计划编码" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="计划状态" prop="status">
        <el-select v-model="searchForm.status" placeholder="全部">
          <el-option
            v-for="item in status"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="计划类型" prop="type">
        <el-select v-model="searchForm.type" placeholder="全部">
          <el-option
            v-for="item in type"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工厂" prop="factoryId">
        <el-select v-model="searchForm.factoryId" placeholder="请选择" clearable filterable @change="selectFactroy">
          <el-option
            v-for="item in factories"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工序" prop="procedureIdList">
        <el-select v-model="searchForm.procedureIdList" multiple :disabled="!searchForm.factoryId" clearable filterable placeholder="请选择">
          <el-option
            v-for="item in productes"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="批次号" prop="batch">
        <el-input v-model="searchForm.batch" placeholder="请输入" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="计划结束日期" prop="planDate">
        <el-date-picker
          value-format="yyyy-MM-dd"
          v-model="time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="selectDate"
        ></el-date-picker>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar">
        <li v-permissions="['ext:plansext:distribute']"><el-button type="primary" @click="plansDistribute">批量分配</el-button></li>
        <li v-permissions="['ext:plansext:importExcel']">
          <ImportButton
            text="导入"
            template-name="plans_import_template.xlsx"
            template-path="/template/plans_import_template.xlsx"
            action="/ext/plansExt/importBatch"
            @success="search"
          />
        </li>
        <!-- <li v-permissions="['ext:plansext:create']"><el-button type="primary" @click="$refs.operaPlansExtWindow.open('新建生产计划')" >新建</el-button></li> -->
        <!-- <li v-permissions="['ext:plansext:publish']"><el-button type="primary" @click="planRelease" >发布</el-button></li> -->
        <!-- <li v-permissions="['ext:plansext:exportExcel']"><el-button type="primary" :loading="isWorking.export" @click="exportExcel">导出</el-button></li> -->
        <!-- <li v-permissions="['ext:plansext:planpink']"><el-button type="primary" @click="$refs.operaWTransferExtWindow.open('计划领料')">计划领料</el-button></li> -->
        <!-- <li v-permissions="['ext:plansext:stockpink']"><el-button type="primary" @click="$refs.operaPlanStaock.open('库存领料')">库存领料</el-button></li> -->
        <!-- <li v-permissions="['ext:plansext:delete']"><el-button type="danger" plain @click="deleteByIdInBatch">批量删除</el-button></li> -->
        <span></span>
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        :summary-method="getSummaries"
        show-summary
        @selection-change="handleSelectionChange"
        @row-style="rowStyle"
      >
        <el-table-column type="selection" fixed="left" width="55"></el-table-column>
        <el-table-column prop="id" label="计划序号" fixed="left" min-width="100px">
          <template slot-scope="{row}">
            <span>{{ row.id }}</span><el-tag type="danger" size="mini" v-if="row.hasExpire">延期</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="mmodel.name" fixed="left" label="物料名称" show-overflow-tooltip min-width="140px">
          <template slot-scope="{row}">
            <el-button type="text" class="materail" @click="showPlan(row.id)">
              <div class="long-title-style">{{ row.mmodel.name }}</div>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column prop="mmodel.code" label="物料编码" min-width="160px">
        </el-table-column>
        
        <el-table-column prop="fmodel.name" label="工厂" min-width="100px"></el-table-column>
        <el-table-column prop="pmodel.name" label="工序" show-overflow-tooltip min-width="100px">
          <template slot-scope="{row}">
            <span class="long-title-style">{{ row.pmodel ? row.pmodel.name : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="batch" label="生产批次号" show-overflow-tooltip min-width="140px"></el-table-column>
        <el-table-column prop="num" label="计划数量" min-width="100px">
          <template slot-scope="{row}">
            <span>{{ row.num + (row.umodel ? row.umodel.name : '') }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="workPlanStartDate" label="计划开始日期" min-width="100px">
          <!-- <template slot-scope="{row}">
            {{ row.workPlanStartDate ? row.workPlanStartDate.substring(0, row.workPlanStartDate.length-9) : '-' }}
          </template> -->
        </el-table-column>
        <el-table-column prop="workPlanEndDate" label="计划结束日期" min-width="100px">
          <!-- <template slot-scope="{row}">
            {{ row.workPlanEndDate ? row.workPlanEndDate.substring(0, row.workPlanEndDate.length-9) : '-' }}
          </template> -->
        </el-table-column>
        
        <el-table-column label="计划状态" min-width="80px">
          <template slot-scope="{row}">
            {{ statusToStr(row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="distributNoDoneNum" label="已分配未报工数量" min-width="140px">
          <template slot-scope="{row}">
            <span>{{row.distributNoDoneNum ? (row.distributNoDoneNum + (row.umodel ? row.umodel.name : '')) : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="qulifiedNum" label="合格数量" min-width="100px">
          <template slot-scope="{row}">
            <span class="valid-style">{{row.qulifiedNum ? (row.qulifiedNum + (row.umodel ? row.umodel.name : '')) : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="unqulifiedNum" label="不良数量" min-width="100px">
          <template slot-scope="{row}">
            <span class="unvalid-style">{{row.unqulifiedNum ? (row.unqulifiedNum + (row.umodel ? row.umodel.name : '')) : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="urgent" label="优先级" min-width="60px"></el-table-column>
        <el-table-column label="暂停" min-width="60px">
          <template slot-scope="{row}">
            {{ row.paused == 0 ? '否' : '是' }}
          </template>
        </el-table-column>
        <el-table-column prop="workPlanCode" label="主计划编码" min-width="140px"></el-table-column>
        <el-table-column label="类型" min-width="80px">
          <template slot-scope="{row}">
            <span :style="typeColor(row.type)">{{ typeToStr(row.type) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="publishDate" label="发布日期" min-width="100px">
          <template slot-scope="{row}">
            <span>{{ row.publishDate || '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="usermodel.realname" label="计划员" min-width="160px">
          <template slot-scope="{row}">
           <span class="long-title-style"> {{ row.usermodel.realname + " " + row.usermodel.mobile }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="100px"
          fixed="right">
          <template slot-scope="{row}">
            <!-- 0已生成、1已发布、2已撤回、3已取消、4已分配、5已暂停、6已完工、7已入库、8已关闭 -->
            <el-button v-if="row.status==0&&tempPremission('ext:plansext:publish')" type="text" @click="publishById(row.id)">发布</el-button>
            <!-- <el-button v-if="(row.status==1||row.status==4)" type="text" @click="distrubution(row)">分配</el-button> -->
            <!--  -->
            <el-button v-if="(row.status==1||row.status==4)&&(row.num-row.distributNum>0)&&tempPremission('ext:plansext:distribute')" type="text" @click="distrubution(row)">分配</el-button>
            <el-button v-if="row.status==4&&row.paused==0&&tempPremission('ext:plansext:control')" type="text" @click="planPauseById(row.id)">暂停</el-button>
            <el-button v-if="row.status==4&&row.paused==1&&tempPremission('ext:plansext:control')" type="text" @click="planRegainById(row.id)">恢复</el-button>
            <!-- <el-button v-if="row.status==4||row.status==5&&tempPremission('ext:plansext:control')" type="text" @click="planCloseById(row.id)">关闭</el-button> -->
            <el-button v-if="row.status==0&&tempPremission('ext:plansext:update')" type="text" @click="$refs.operaPlansExtWindow.open('编辑生产计划', row)">编辑</el-button>
            <span v-if="row.status==0||row.status==1&&tempPremission('ext:plansext:delete')" style="margin-left:8px">
              <!-- <el-button type="text" @click="deleteById(row)">删除</el-button> -->
            </span>
            <!-- <span v-if="row.status==4&&tempPremission('ext:plansext:control')" style="margin-left:8px">
              <el-button type="text" @click="cancelPlan(row)">取消</el-button>
            </span> -->
            <el-button v-if="row.status==3||row.status==6||row.status==8" type="text">-</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      ></pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaPlansExtWindow ref="operaPlansExtWindow" @success="handlePageChange"/>
    <OperaPlansDetailExtWindow ref="operaPlansDetailExtWindow" @success="handlePageChange"/>
    <OperaPlansExtFromWindow ref="operaPlansExtFromWindow" @success="distrubuted"/>
    <OperaWTransferExtWindow ref="operaWTransferExtWindow" @success="handlePageChange"/>
    <OrderDistrubution ref="orderDistrubution" @success="distrubuted"/>
    <OperaPlanStaock ref="operaPlanStaock" @success="handlePageChange"/>
    <el-dialog
      title="发布"
      :visible.sync="dialogRelease"
      width="30%"
      left
    >
      确定发布选中计划吗?
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogRelease = false">取 消</el-button>
        <el-button type="primary" :disabled="isLoading" :icon="isLoading ? 'el-icon-loading' : ''" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </TableLayout></keep-alive>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import ImportButton from '@/components/common/ImportButton'
import OperaPlansExtWindow from '@/components/ext/OperaPlansExtWindow'
import OperaPlansDetailExtWindow from '@/components/ext/OperaPlansDetailExtWindow'
import OperaPlansExtFromWindow from '@/components/ext/OperaPlansExtFromWindow'
import OperaWTransferExtWindow from '@/components/ext/OperaWTransferExtWindow'
import OrderDistrubution from '@/components/ext/OrderDistrubution'
import OperaPlanStaock from '@/components/ext/OperaPlanStaock'
import { publish, cancelById, pauseById, regainById, closeById, planDetailById } from '@/api/ext/plansExt'
import { getDepartmentListByConditon } from '@/api/ext/departmentExt'
import { productesGroup } from '@/api/ext/proceduresExt'
import { addPrecision } from '@/utils/util'
export default {
  name: 'PlansExt',
  extends: BaseTable,
  components: {
    TableLayout,
    OrderDistrubution,
    Pagination,
    ImportButton,
    OperaPlansExtWindow,
    OperaPlansDetailExtWindow,
    OperaPlansExtFromWindow,
    OperaWTransferExtWindow,
    OperaPlanStaock
  },
  data () {
    return {
      time: [],
      status: [
        // 0已生成、1已发布、2已撤回、3已取消、4已分配、5已暂停、6已完工、8已关闭
        { name: '已生成', id: 0 },
        { name: '已发布', id: 1 },
        { name: '已撤回', id: 2 },
        { name: '已取消', id: 3 },
        { name: '已分配', id: 4 },
        { name: '已暂停', id: 5 },
        { name: '已完工', id: 6 },
        { name: '已关闭', id: 8 }
      ],
      type: [
        { name: '正常', id: 0 },
        { name: '返工返修', id: 2 },
      ],
      dialogRelease: false,
      dialogwithdraw: false,
      dialogimport: false,
      ruleForms: {
        time: ''
      },
      isLoading: false,
      factories: [],
      productes: [],
      // 搜索
      searchForm: {
        procedureIdList: [],
        procedureId: null,
        factoryId: null,
        status: null,
        mixParam: null,
        planDateStartDate: null,
        planDateEndDate: null,
        batch: null,
        type: null,
        workPlanCode: null
      }
    }
  },
  provide() {
    return {
      factories: () => this.factories
    }
  },
  created () {
    this.config({
      module: '生产计划',
      api: '/ext/plansExt',
      'field.id': 'id',
      'field.main': 'name',
      sorts: [{ direction: 'DESC', property: 'CREATE_TIME' }]
    })
    this.search()
  },
  activated() {
    getDepartmentListByConditon({
      type: 1
    }).then(res => {
      this.factories = res
    }).catch(err => {
      console.log(err)
    })
  },
  methods: {
    selectDate (v) {
      this.searchForm.planDateStartDate = v[0]
      this.searchForm.planDateEndDate = v[1]
      this.search()
    },
    selectFactroy (v) {
      this.searchForm.procedureIdList = []
      productesGroup({ orgId: v })
        .then(res => {
          this.productes = res
        })
        .catch(err => {
          console.log(err)
        })
    },
    reset () {
      this.$refs.searchForm.resetFields()
      this.searchForm.planDateStartDate = null
      this.searchForm.planDateEndDate = null
      this.time = []
      this.search()
    },
    planRelease () {
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请至少选择一条数据')
        return
      }
      for (const item of this.tableData.selectedRows) {
        if (item.status !== 0) {
          this.$tip.warning('只有已创建状态可以发布')
          return
        }
      }
      this.dialogRelease = true
    },
    distrubution (row) {
      this.$refs.orderDistrubution.open('分配工单', row)
    },
    submit () {
      this.dialogRelease = false
      const query = '?ids=' + this.tableData.selectedRows.map(row => row.id).join(',')
      this.publishAction(query)
    },
    cancelPlan (row) {
      this.$confirm('确认取消当前的计划?', '确认取消', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消'
      })
        .then(() => {
          this.isWorking.delete = true
          cancelById({ id: row.id })
            .then(() => {
              this.handlePageChange()
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking.delete = false
            })
        })
        .catch(() => {})
    },
    publishById (id) {
      this.$confirm('确认发布当前的计划?', '确认发布', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '放弃'
      })
        .then(() => {
          this.publishAction('?ids=' + id)
        })
        .catch(() => {})
    },
    publishAction (query) {
      this.isWorking.delete = true
      publish(query)
        .then(() => {
          this.handlePageChange()
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking.delete = false
        })
    },
    planPauseById (id) {
      this.$confirm('确认暂停当前的计划?', '确认暂停', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '放弃'
      })
        .then(() => {
          this.isWorking.delete = true
          pauseById({ id })
            .then(() => {
              this.$tip.success('暂停成功')
              this.search()
            })
            .catch(err => {
              this.$tip.error(err)
            })
        })
        .catch(() => {})
    },
    planRegainById (id) {
      this.$confirm('确认恢复当前的计划?', '确认恢复', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '放弃'
      })
        .then(() => {
          this.isWorking.delete = true
          regainById({ id })
            .then(() => {
              this.$tip.success('恢复成功')
              this.search()
            })
            .catch(err => {
              this.$tip.error(err)
            })
        })
        .catch(() => {})
    },
    rowStyle({row, rowIndex}) {
      console.log('1');
      return { height: 20}
    },
    planCloseById (id) {
      this.$confirm('确认关闭当前的计划?', '确认关闭', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '放弃'
      })
        .then(() => {
          this.isWorking.delete = true
          closeById({ id })
            .then(() => {
              this.$tip.success('关闭成功')
              this.search()
            })
            .catch(err => {
              this.$tip.error(err)
            })
        })
        .catch(() => {})
    },
    plansDistribute () {
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请至少选择一条数据')
        return
      }
      let procedureId = this.tableData.selectedRows[0].procedureId
      for (const item of this.tableData.selectedRows) {
        if (item.status !== 4 && item.status !== 1) {
          this.$tip.warning('只有已发布或已分配状态可以分配')
          return
        }
        // if (procedureId !== item.procedureId) {
        //   this.$tip.warning('只能对同工序计划批量分配')
        //   return
        // }
      }
      this.$refs.operaPlansExtFromWindow.open('批量分配', this.tableData.selectedRows)
    },
    statusToStr (satus) {
      for (const item of this.status) {
        if (item.id === satus) {
          return item.name
        }
      }
    },
    deleteById (row) {
      this.$confirm('是否删除该条生产计划?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.isWorking.delete = true
        this.api.deleteById(row[this.configData['field.id']])
          .then(() => {
            this.__afterDelete()
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking.delete = false
          })
      }).catch(() => {})
    },
    showPlan (id) {
      planDetailById(id)
        .then(res => {
          this.$refs.operaPlansDetailExtWindow.open('详情', res)
        })
        .catch(err => {
          this.$tip.error(err)
        })
    },
    typeToStr (type) {
      for (const item of this.type) {
        if (item.id === type) {
          return item.name
        }
      }
      return '-'
    },
    typeColor (type) {
      // { name: '正常', id: 0 },
        // { name: '返工返修', id: 2 },
        // $nav-stateColor1: #305ED5;
        //     $nav-stateColor2: #03AF76;
        //     $nav-stateColor4: #DE5243;
        //     $nav-stateColor5: #F5A400;
      switch (type) {
        case 0 : return 'color: #03AF76'
        case 2 : return 'color: #F5A400'
        default: return 'color: #111111'
      }
    },
    // 权限判断
    tempPremission (permissions) {
      let allPremission = this.$store.state.userInfo.permissions
      
      for (const item of allPremission) {
        if (item === permissions) {
          return true
        }
      }
      return false
    },
    distrubuted() {
      setTimeout(()=>{
        this.handlePageChange()
      },500)
    },
    getSummaries (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        } else if (index === 1 || index === 6 || index === 8 || index === 9 || index === 14 || index === 16 || index === 17) {
          sums[index] = '-';
          return;
        } else if (index === 8 ) {
          sums[index] = '-';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = 0
          values.forEach(item => {
            sums[index] = addPrecision(item, sums[index])
          })
        } else {
          sums[index] = '-';
        }
      });
      return sums
    }
  }
}
 
</script>
<style lang="scss" scoped>
.materail {
  max-width: 120px;
}
.import{
  float: right;
}
span{
  clear: both;
}
.btn{
  a{
    margin-left: 20px;
  }
}
</style>