Fixiaobai
2023-09-09 34a7e21b3508ac0f5f011d958210fdb7176d726b
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
<template>
    <div class="content-main">
        <div class="top-bar">
            <el-form ref="form" :inline="true" :model="searchData" label-position="left" style="margin-top: 10px;">
                <el-form-item label="样品编号:">
                    <el-input size="small" v-model="searchData.sample_code" class="input-form" placeholder="请输入样品编号"
                        @keyup.enter.native="getData" />
                </el-form-item>
                <el-form-item label="报告单号:">
                    <el-input size="small" v-model="searchData.reportCode" class="input-form" placeholder="请输入报告单号" />
                </el-form-item>
                <el-form-item label="申请单号:">
                    <el-input size="small" v-model="searchData.application_code" class="input-form" placeholder="请输入申请单号" />
                </el-form-item>
                <el-form-item>
                    <el-button size="small" type="primary" @click="getData()">查询</el-button>
                    <el-button size="small" type="primary" plain @click="resetData()">重置</el-button>
                </el-form-item>
            </el-form>
            <el-form style="margin-top: 10px;">
                <el-button size="small" @click="exportToPDF" class="rightBtn" type="primary" icon="el-icon-document">导出报告</el-button>
            </el-form>
        </div>
        <div class="library-table">
            <div class="table-header">
                <div class="search-bar">
                    <el-radio-group v-model="checkStatus" @change="handleRadioChange">
                        <el-radio-button>全部</el-radio-button>
                        <el-radio-button label="0">待审核</el-radio-button>
                        <el-radio-button label="1">待签字</el-radio-button>
                        <el-radio-button label="2">已完成</el-radio-button>
                    </el-radio-group>
                    <el-checkbox v-model="checked" style="margin-left: 20px">仅看我的</el-checkbox>
                </div>
            </div>
            <el-dialog top="10vh" title="报告预览" :visible.sync="dialogVisible" width="60%">
                <span slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="printFun()">打印</el-button>
                </span>
                <div class="printStyle" v-if="dialogVisible">
                    <Preview id="printRaw" :reportData="reportData" v-if="reportType===0"></Preview>
                    <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-else></TestReport>
                </div>
            </el-dialog>
            <div class="table-box">
                <el-table ref="reportTable" height="200" :max-height="800" :cell-style="{ textAlign: 'left' }" :header-cell-style="{
            border: '0px',
            background: '#f5f7fa',
            color: '#606266',
            boxShadow: 'inset 0 1px 0 #ebeef5',
            textAlign: 'left',
          }" :data="reportTable" @selection-change="handleSelectionChange" style="width: 100%">
                    <el-table-column type="selection" min-width="5%" />
                    <el-table-column prop="type" label="报告类型" min-width="5%">
                        <template slot-scope="scope">
                            <el-tag>{{scope.row.type == 0?'原材料报告':scope.row.type==1?'成品报告':'委托报告'}}</el-tag>
                        </template></el-table-column>
                    <el-table-column prop="materialCode" label="样品编号" sortable min-width="10%">
                        <template slot-scope="scope">
                            <span style="color: #409eff;">
                                {{ scope.row.materialCode }}
                            </span>
                        </template></el-table-column>
                    <el-table-column prop="reportCode" label="报告单号" sortable min-width="10%">
                        <template slot-scope="scope">
                            <span style="color: #409eff;">
                                {{ scope.row.reportCode }}
                            </span>
                        </template></el-table-column>
                    <el-table-column prop="inspectionCode" label="申请单号" sortable min-width="10%">
                        <template slot-scope="scope">
                            <span style="color: #409eff;">
                                {{ scope.row.inspectionCode }}
                            </span>
                        </template></el-table-column>
                    <el-table-column prop="approver" label="审批人" min-width="8%">
                        <template slot-scope="scope">
                            <span>
                                <el-tag v-if="scope.row.approver!=null && scope.row.approver!=''" type="info" icon="el-icon-user">
                                    <i class="el-icon-user">{{ scope.row.approver }}</i>
                                </el-tag>
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="status" label="审批状态" min-width="8%">
                        <template slot-scope="scope">
                            <span>
                                <el-tag type="info">
                                    {{
                                    scope.row.status == 0
                                    ? "待审核"
                                    : scope.row.status == 1
                                    ? "待签字" : "已完成"
                                    }}
                                </el-tag>
                            </span>
                        </template></el-table-column>
                    <el-table-column prop="conclusion" label="检验结论" min-width="8%">
                        <template slot-scope="scope">
                            <span :style="`color: ${scope.row.conclusion=='合格'?'#67c23a':'#f56c6c'}`">{{scope.row.conclusion}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" label="编制人" min-width="8%">
                        <template slot-scope="scope">
                            <span>
                                <el-tag type="info" icon="el-icon-user">
                                    <i class="el-icon-user">{{ scope.row.name }}</i>
                                </el-tag>
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" min-width="8%">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="previewFun(scope.row)">查看报告</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页器 -->
                <div>
                    <el-pagination :current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
                        @current-change="handleCurrentChange" />
                </div>
            </div>
        </div>
        <Preview ref="preview" id="printRaw" :reportData="reportData" v-show="false"></Preview>
        <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-show="false"></TestReport>
        <el-dialog title="导出pdf" :visible.sync="dialogPdfVisible" width="30%">
            <span>确定开始导出吗?</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogPdfVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirmExport">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
 
<script>
    import {
        selectAllReport,
        getReportData
    } from "@/api/experiment/checkTheReport";
    import Preview from "@/components/experiment/checkTheReport/index.vue";
    import TestReport from "@/components/experiment/template_testReport/index.vue"
    import PrintJS from 'print-js'
    import html2pdf from 'html2pdf.js'
 
    export default {
        data() {
            return {
                reportData: [],
                reportType: 0,
                searchData: {
                    sample_code: '',
                    reportCode: '',
                    application_code: ''
                },
                checkStatus: undefined,
                reportTable: [],
                page: 1,
                total: 0,
                pageSize: 10,
                checked: true,
                dialogVisible: false,
                dialogPdfVisible: false,
                selectedRows: []
            };
        },
        created() {
            this.getData();
        },
        mounted() {},
        components: {
            Preview,
            TestReport
        },
        methods: {
            async queryReportByRCode(code,name) {
                const resp = await getReportData({
                    code: code
                });
                this.reportData = resp.data;
                this.reportData.preparerName = name;
                this.dialogVisible = true;
                console.log(this.reportData);
            },
            //查看报告按钮
            previewFun(row) {
                this.reportType = row.type;
                this.queryReportByRCode(row.reportCode,row.name);
                
            },
            handleSelectionChange(selection) {
                this.selectedRows = selection;
            },
            // 批量导出报告
            exportToPDF() {
                this.dialogPdfVisible = true;
            },
            // 确认导出模态框
            confirmExport() {
                this.selectedRows.forEach(async row => {
                    const element = document.getElementById('printFinished');
                    console.log(element)
                    // 设置TestReport组件的reportData属性为当前行的报告数据
                    const resp = await getReportData({
                        code: row.reportCode
                    });
                    this.$nextTick(() => {
                        this.$refs.testreport.reportData = resp.data;
                        html2pdf().from(element).save(`exported_${row.reportCode}.pdf`);
                    });
                });
                this.dialogPdfVisible = false;
                this.selectedRows = [];
            },
            //打印按钮
            printFun() {
                this.dialogVisible = false;
                PrintJS({
                    printable: this.reportType === 0 ? "printRaw" : "printFinished",
                    type: "html",
                    // header: "原材料检测报告",
                    targetStyles: ["*"],
                    ignoreElements: ["no-ignore"],
                });
            },
            // 状态按钮
            handleRadioChange() {
                this.getData();
            },
            // 每页条数改变时触发 选择一页显示多少行
            handleSizeChange(val) {
                this.pageSize = val;
                this.getData();
            },
            // 当前页改变时触发 跳转其他页
            handleCurrentChange(val) {
                this.page = val;
                this.getData();
            },
            // 重置按钮
            resetData() {
                this.searchData = {
                        sample_code: '',
                        reportCode: '',
                        application_code: ''
                    },
                    this.page = 1;
                this.pageSize = 10;
                this.checkStatus = undefined;
                this.getData();
            },
            // 查询列表
            async getData() {
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,
                    name: this.searchData.sample_code ? this.searchData.sample_code : undefined,
                    status: this.checkStatus ? this.checkStatus : undefined,
                };
                const {
                    data
                } = await selectAllReport(params);
                this.reportTable = data.row;
                this.total = data.total;
            },
        },
    };
</script>
 
<style lang="scss" scoped>
    .top-bar {
        margin: -25px -15px;
        background: #fff;
        display: flex;
        justify-content: space-between;
        padding: 5px 24px 0px 24px;
 
        .input-form {
            width: 250px;
            margin-right: 30px;
        }
 
        .el-dropdown-link {
            cursor: pointer;
            color: #409eff;
        }
 
        .el-icon-arrow-down {
            font-size: 12px;
        }
    }
 
    .library-table {
        height: 80vh;
        overflow: scroll;
        background-color: #fff;
        flex: 1;
        margin: 0px -15px;
        margin-top: 40px;
        display: flex;
        flex-direction: column;
 
        .table-header {
            padding: 20px;
            display: flex;
            justify-content: space-between;
 
            .el-form-item {
                margin-bottom: 30px !important;
            }
        }
 
        .table-box {
            height: 60vh;
            padding: 0px 20px;
            margin-top: 0px;
            flex: 1;
            background: #fff;
            display: flex;
            flex-direction: column;
            .el-table{
                overflow: scroll;
            }
            >div:nth-child(2) {
                display: flex;
                justify-content: end;
                margin: 10px 0;
            }
        }
 
        .printStyle {
            overflow: scroll;
            height: 600px;
 
            .el-button {
                position: absolute;
                top: 10vh;
                left: 90%;
            }
        }
    }
</style>