zhouwx
2 天以前 d5bd0e88c1eec6bb2947d2bfa57348d89edbc1c3
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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
<template>
  <div class="app-container">
    <div style="margin-bottom: 10px">
      <el-form style="display: flex;flex-wrap: wrap;">
        <el-form-item>
          <el-button
              type="primary"
              plain
              icon="Plus"
              @click="openDialog('add',{})"
          >新增</el-button>
        </el-form-item>
        <el-form-item label="企业名称:" v-if="data.isAdmin" style="margin-left: 20px">
          <el-select v-model="data.queryParams.companyId" filterable placeholder="请选择" clearable>
            <el-option
                v-for="item in data.companyList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="data.isAdmin">
          <el-button type="primary" style="margin-left: 30px" @click="searchClick">查询</el-button>
          <el-button plain @click="reset">重置</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 15px">
          <el-button
              type="primary"
              @click="exportData"
          >导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList" :border="true"  @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
      <el-table-column label="供货单位" prop="supplierName" align="center"  />
      <el-table-column label="地址" prop="supplierAddr" align="center"  />
      <el-table-column label="供应品名称" prop="merito" align="center"  />
      <el-table-column label="联系人" prop="user" align="center"  />
      <el-table-column label="联系电话" prop="phone" align="center"  />
      <el-table-column label="备注" prop="remark" align="center"  />
      <el-table-column label="业绩评定表" align="center" class-name="small-padding fixed-width" width="160" >
        <template #default="scope">
          <el-button link type="primary" @click="openPerformance('review',scope.row)">查看</el-button>
          <el-button link type="primary" @click="openPerformance('edit',scope.row)">编辑</el-button>
          <el-button link type="primary"  @click = 'exportPerformance(scope.row)'>导出</el-button>
        </template>
      </el-table-column>
      <el-table-column label="质量保证能力调查表" align="center" class-name="small-padding fixed-width"  width="160" >
        <template #default="scope">
          <el-button link type="primary" @click="openQuality('review',scope.row)">查看</el-button>
          <el-button link type="primary" @click="openQuality('edit',scope.row)">编辑</el-button>
          <el-button link type="primary"  @click = 'exportQuality(scope.row)'>导出</el-button>
        </template>
      </el-table-column>
      <el-table-column label="证书" align="center" class-name="small-padding fixed-width" >
        <template #default="scope">
          <el-button link type="primary"  @click="openCert('review',scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="160" >
        <template #default="scope">
          <el-button link type="primary"  @click="openDialog('review',scope.row)" >查看</el-button>
          <el-button link type="primary"  @click="openDialog('edit',scope.row)" >编辑</el-button>
          <el-button link type="danger"  @click="handleDelete(scope.row)" >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <div class="pag-container">
      <el-pagination
          v-model:current-page="data.queryParams.pageNum"
          v-model:page-size="data.queryParams.pageSize"
          :page-sizes="[10,15,20,25]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
    <supplierDialog ref="noticeRef" @getList = "getList"></supplierDialog>
    <performanceTable ref="performanceRef" @getList = "getList"></performanceTable>
    <qualityDialog ref="qualityRef" @getList = "getList"></qualityDialog>
    <certDialog ref="certRef" @getList = "getList"></certDialog>
  </div>
</template>
 
<script setup>
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from "vue";
import supplierDialog from "./components/supplierDialog.vue"
import performanceTable from './components/performanceTableDialog.vue'
import qualityDialog from './components/qualityDialog.vue'
import certDialog from './components/certDialog.vue'
import {ElMessage, ElMessageBox} from "element-plus";
import {getCompany} from "@/api/onlineEducation/company";
import Cookies from "js-cookie";
import {generateWordDocument} from "@/utils/exportWord";
import {delBasic, getBasic} from "@/api/companyInfo/basicInfo";
import {delSupplierById, getPerformance, getQuality, getSupplierPage} from "@/api/supplier/supplierList";
const { proxy } = getCurrentInstance();
const loading = ref(false);
const noticeRef = ref();
const performanceRef = ref();
const qualityRef = ref();
const certRef = ref();
 
const loadingCompany = ref(false)
const choosedData = ref([])
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    companyId: null,
  },
  companyList: [],
  isAdmin: false,
  verifyList:[{id: 1,label: '现场验证'},{id: 2,label: '入库验证'},{id: 3,label: '供方货源处验证'},],
  opinionList:[{id: 1,label: '保留(≥80)'},{id: 2,label: '暂停,整改后再评价(≥65)'},{id: 3,label: '剔除(<65)'},],
  traitList:[
    {
      id: 1,
      name: '成批生产'
    },
    {
      id: 2,
      name: '流水线生产'
    },
    {
      id: 3,
      name: '单台生产'
    },
    {
      id: 4,
      name: '其他'
    },
  ],
  facilityList:[
    {
      id: 1,
      name: '齐全、良好'
    },
    {
      id: 2,
      name: '基本齐全、尚可'
    },
    {
      id: 3,
      name: '不全'
    },
    {
      id: 4,
      name: '代理商'
    },
  ],
  craftList:[
    {
      id: 1,
      name: '齐备'
    },
    {
      id: 2,
      name: '有一部分'
    },
    {
      id: 3,
      name: '没有'
    },
    {
      id: 4,
      name: '代理商'
    },
  ],
  developList:[
    {
      id: 1,
      name: '能自行设计开发新品'
    },
    {
      id: 2,
      name: '只能开发简单产品'
    },
    {
      id: 3,
      name: '没有自行开发能力,代理商'
    },
  ],
  teamWorkList:[
    {
      id: 1,
      name: '是外资企业'
    },
    {
      id: 2,
      name: '是合资企业'
    },
    {
      id: 3,
      name: '给企业提供产品'
    },
    {
      id: 4,
      name: '无对外合作经验'
    },
    {
      id: 5,
      name: '有对外合作经验,但不经常发生'
    },
  ],
  qualificationList:[
    {
      id: 1,
      name: '营业执照'
    },
    {
      id: 2,
      name: '有效期内'
    },
    {
      id: 3,
      name: '有效期外'
    },
    {
      id: 4,
      name: '高新技术企业'
    },
    {
      id: 5,
      name: '有效期内'
    },
    {
      id: 6,
      name: '有效期外'
    },
    {
      id: 7,
      name: '资质代理商'
    },
    {
      id: 8,
      name: '其他资质情况:'
    },
  ],
  productList:[
    {
      id: 1,
      name: '通过产品认证'
    },
    {
      id: 2,
      name: '没有产品认证'
    },
    {
      id: 3,
      name: '通过质量体系认证'
    },
    {
      id: 4,
      name: '没有体系认证'
    },
    {
      id: 5,
      name: '其他认证(请指出具体内容):'
    },
  ]
});
const dataList = ref([]);
const total = ref(0);
 
const { queryParams } = toRefs(data);
 
onMounted(() => {
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  console.log("userInfo",userInfo)
  data.isAdmin = userInfo.userType === 0;
  if(data.isAdmin){
    data.queryParams.companyId = null
  }else {
    data.queryParams.companyId = userInfo.companyId
  }
  getList();
  if(data.isAdmin){
    getCompanyList()
  }
 
 
});
const getList = async () => {
  loading.value = true;
  const res = await getSupplierPage(data.queryParams);
  if(res.code === 200){
    dataList.value = res.data.list
    total.value = res.data.total
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false
}
 
const searchClick = () => {
  getList();
}
const openDialog = (type, value) => {
  noticeRef.value.openDialog(type, value,data.companyList);
}
const openPerformance = (type, value) => {
  performanceRef.value.openDialog(type, value);
}
const openQuality = (type,value) => {
  qualityRef.value.openDialog(type, value);
}
const openCert = (type,value) => {
  certRef.value.openDialog(type, value);
}
const selectValue = (val) => {
  data.companyList.forEach(item => {
    if(item.name === val){
      data.queryParams.companyId = item.id
    }
  })
}
 
const getCompanyList = async ()=>{
  const queryParams = {
    pageNum: 1,
    pageSize: 999
  }
  const res = await getCompany(queryParams)
  if (res.code == 200) {
    data.companyList = res.data.list?res.data.list:[]
    // data.queryParams.companyId = data.companyList[0].id
  } else {
    ElMessage.warning(res.message)
  }
}
 
const handleSizeChange = (val) => {
  data.queryParams.pageSize = val
  getList()
}
const handleCurrentChange = (val) => {
  data.queryParams.pageNum = val
  getList()
}
 
/** 重置新增的表单以及其他数据  */
function reset() {
  data.queryParams = {
    companyId: '',
    pageNum: 1,
    pageSize: 10,
  }
  choosedData.value = []
  data.companyList = [];
  getList();
  getCompanyList()
}
 
 
const handleSelectionChange = (val) => {
  choosedData.value = val
}
const handleDelete = (val) => {
  ElMessageBox.confirm(
      '确定删除此条数据?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await delSupplierById(val.id);
        if(res.code === 200){
          ElMessage({
            type: 'success',
            message: '删除成功'
          });
          getList();
        }else{
          ElMessage.warning(res.message)
        }
      })
}
const qualityPath = ref('/qualityExample.docx')
const exportQuality = async (val) => {
  let state = {}
  const param = {
    supplierSureId: val.id
  }
  const res = await getQuality(param)
  if(res.code == 200){
    state = res.data
    state.productName = val.merito
    if(state.otherQualifi){
      data.qualificationList.forEach((item) => {
        if(item.id == 8){
          item.name = item.name+ state.otherQualifi
        }
      })
    }
    if(state.otherProduct){
      data.productList.forEach((item) => {
        if(item.id == 5){
          item.name = item.name+ state.otherProduct
        }
      })
    }
    await handleCheckData(res.data)
    state.traitList = data.traitList
    state.facilityList = data.facilityList
    state.craftList = data.craftList
    const teamWorkData = formatCheckboxData(data.teamWorkList)
    state.teamWorkList = teamWorkData
    const developData = formatCheckboxData(data.developList)
    state.developList = developData
    const qualificationData = formatCheckboxData(data.qualificationList,'quality')
    state.qualificationList = qualificationData
    const productData = formatCheckboxData(data.productList)
    state.productList = productData
    state.chargeTime = state.chargeTime?state.chargeTime.substring(0,10):''
    try {
      generateWordDocument(qualityPath.value, state, val.supplierName+'_供方质量保证能力调查表.docx');
      await setTableData()
    } catch (error){
      ElMessage({
        type: 'warning',
        message: '导出失败'
      });
    }
 
  }else{
    ElMessage.warning(res.message)
  }
}
function formatCheckboxData(items,type) {
  return items.reduce((rows, item, index) => {
    if(type == 'quality'){
      if (index % 3 === 0) {
        // 创建新行,添加第一个复选框
        rows.push({ check1: item });
      } else if (index % 3 === 1 && rows.length > 0) {
        // 向当前行添加第二个复选框
        const currentRow = rows[rows.length - 1];
        currentRow.check2 = item;
      } else if (index % 3 === 2 && rows.length > 0) {
        // 向当前行添加第三个复选框
        const currentRow = rows[rows.length - 1];
        currentRow.check3 = item;
      }
    }else{
      if (index % 2 === 0) {
        // 创建新行,添加第一个复选框
        rows.push({ check1: item });
      } else {
        // 向最后一行添加第二个复选框
        const lastRow = rows[rows.length - 1];
        lastRow.check2 = item;
      }
    }
    return rows;
  }, []);
}
const handleCheckData = (val) =>{
  const idSetTrait = new Set(val.trait.split(',').map((i => Number(i))))
  data.traitList.forEach(item => {
    if (idSetTrait.has(item.id)) {
      item.checked = true;
    }
  });
  const idSetFacility = new Set(val.facility.split(',').map((i => Number(i))))
  data.facilityList.forEach(item => {
    if (idSetFacility.has(item.id)) {
      item.checked = true;
    }
  });
  const idSetCraft = new Set(val.craft.split(',').map((i => Number(i))))
  data.craftList.forEach(item => {
    if (idSetCraft.has(item.id)) {
      item.checked = true;
    }
  });
  const idSetDevelop = new Set(val.develop.split(',').map((i => Number(i))))
  data.developList.forEach(item => {
    if (idSetDevelop.has(item.id)) {
      item.checked = true;
    }
  });
  const idSetTeamWork = new Set(val.teamWork.split(',').map((i => Number(i))))
  data.teamWorkList.forEach(item => {
    if (idSetTeamWork.has(item.id)) {
      item.checked = true;
    }
  });
  const idSetQualification = new Set(val.qualification.split(',').map((i => Number(i))))
  data.qualificationList.forEach(item => {
    if (idSetQualification.has(item.id)) {
      item.checked = true;
    }
  });
  const idSetProduct = new Set(val.product.split(',').map((i => Number(i))))
  data.productList.forEach(item => {
    if (idSetProduct.has(item.id)) {
      item.checked = true;
    }
  });
}
 
 
 
 
 
const performancePath = ref('/performanceExample.docx')
const exportPerformance = async (val) => {
  let state = {}
  const param = {
    supplierSureId: val.id
  }
  const res = await getPerformance(param)
  if(res.code == 200){
    // if(!res.data.p1){
    //   ElMessage.warning('暂无数据!')
    //   return
    // }
    state = res.data
    state.tableData = [{name: '产品质量 p1', good: '', fine: '', middle: '', bad: ''},
      {name: '交货期 p2', good: '', fine: '', middle: '', bad: ''},
      {name: '履约能力 p3', good: '', fine: '', middle: '', bad: ''},
      {name: '价格 p4', good: '', fine: '', middle: '', bad: ''},
      {name: '售后服务 p5', good: '', fine: '', middle: '', bad: ''},
      {name: '资历 p6', good: '', fine: '', middle: '', bad: ''},
    ]
    //更新表格字段名
    const p1Field = getMatchedField(res.data.p1)
    if(p1Field){
      state.tableData[0][p1Field] = res.data.p1
    }
    const p2Field = getMatchedField(res.data.p2)
    if(p2Field){
      state.tableData[1][p2Field] = res.data.p2
    }
    const p3Field = getMatchedField(res.data.p3)
    if(p3Field){
      state.tableData[2][p3Field] = res.data.p3
    }
    const p4Field = getMatchedField(res.data.p4)
    if(p4Field){
      state.tableData[3][p4Field] = res.data.p4
    }
    const p5Field = getMatchedField(res.data.p5)
    if(p5Field){
      state.tableData[4][p5Field] = res.data.p5
    }
    const p6Field = getMatchedField(res.data.p6)
    if(p6Field){
      state.tableData[5][p6Field] = res.data.p6
    }
    const sum = res.data.p1+res.data.p2+res.data.p3+res.data.p4+res.data.p5+res.data.p6
    state.tableData = state.tableData.map((i,index) => {
      return {
        ...i,
        list: [{
          first: index == 0,
          conclusion:'Σ(Pi)/6 ='+(sum/6).toFixed(2)
        }]
      }
    })
    data.verifyList.forEach(i => {
      i.checked = i.id != state.verify
    })
    state.verifyList = data.verifyList
    data.opinionList.forEach(i => {
      i.checked = i.id != state.opinion
    })
    state.opinionList = data.opinionList
    state.reviewTime = state.reviewTime?state.reviewTime.substring(0,10):''
    state.checkTime = state.checkTime?state.checkTime.substring(0,10):''
  }else{
    ElMessage.warning(res.message)
  }
  try {
    generateWordDocument(performancePath.value, state, val.supplierName+'_业绩评定表.docx');
  } catch (error){
    ElMessage({
      type: 'warning',
      message: '导出失败'
    });
  }
 
}
const demo = ref([
  {
    rage: '86-100',
    field: 'good'
  },
  {
    rage: '71-85',
    field: 'fine'
  },
  {
    rage: '60-70',
    field: 'middle'
  },
  {
    rage: '0-59',
    field: 'bad'
  },
])
const getMatchedField = (num) => {
  for (const item of demo.value) {
    const [min, max] = item.rage.split('-').map(Number);
    if (num >= min && num <= max) {
      return item.field; // 返回匹配的字段名(如 "good")
    }
  }
  return null; // 无匹配时返回 null
}
const exportData = () => {
    startGeneration()
}
const templatePath = ref('/supplierExample.docx')
const startGeneration = async () => {
  const supplierList = {}
  supplierList.tableData = dataList.value.map((item,index) => {
    return{
      ...item,
      num: index+1
    }
  })
    try {
      generateWordDocument(templatePath.value, supplierList, '合格供方名录.docx');
    } catch (error){
      ElMessage({
        type: 'warning',
        message: '导出失败'
      });
    }
}
const setTableData = () => {
  data.traitList=[{id: 1, name: '成批生产'}, {id: 2, name: '流水线生产'}, {id: 3, name: '单台生产'}, {id: 4, name: '其他'},]
  data.facilityList=[{id: 1, name: '齐全、良好'}, {id: 2, name: '基本齐全、尚可'}, {id: 3, name: '不全'}, {id: 4, name: '代理商'},]
  data.craftList=[{id: 1, name: '齐备'}, {id: 2, name: '有一部分'}, {id: 3, name: '没有'}, {id: 4, name: '代理商'},]
  data.developList=[{id: 1, name: '能自行设计开发新品'}, {id: 2, name: '只能开发简单产品'}, {id: 3, name: '没有自行开发能力,代理商'},]
  data.teamWorkList=[{id: 1, name: '是外资企业'}, {id: 2, name: '是合资企业'}, {id: 3, name: '给企业提供产品'}, {id: 4, name: '无对外合作经验'}, {id: 5, name: '有对外合作经验,但不经常发生'},]
  data.qualificationList=[{id: 1, name: '营业执照'}, {id: 2, name: '有效期内'}, {id: 3, name: '有效期外'}, {id: 4, name: '高新技术企业'}, {id: 5, name: '有效期内'}, {id: 6, name: '有效期外'}, {id: 7, name: '资质代理商'}, {id: 8, name: '其他资质情况:'},]
  data.productList=[{id: 1, name: '通过产品认证'}, {id: 2, name: '没有产品认证'}, {id: 3, name: '通过质量体系认证'}, {id: 4, name: '没有体系认证'}, {id: 5, name: '其他认证(请指出具体内容):'},]
}
</script>
<style lang="scss">
.pag-container{
  float: right;
  margin-top: 10px;
}
</style>