licp
2024-05-22 ef4e46f182aee6253805e66286dee847c573cbde
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
<template>
    <div>
    <el-dialog
    title="检验项管理"
    top="5vh"
    :visible.sync="inspectDialog"
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    width="80%">
        <avue-crud
        ref="inspectDetail"
        :data="dataList"
        :option="option"
        @row-save="addInspectHandler"
        @row-del="delInspectHandler"
        :page="page">
            <template slot="inspectNameForm" slot-scope="scope">
                <el-input
                placeholder="请输入检验项目名称"
                type="textarea"
                v-model="scope.row.inspectName"
                :rows="2" />
            </template>
            <template slot="inspectRequiredForm" slot-scope="scope">
                <el-input
                placeholder="请输入检验标准"
                type="textarea"
                v-model="scope.row.inspectRequired"
                :rows="2" />
            </template>
            <template #menu="{size,row,index}">
                <el-button v-if="row.children!=null" class="menu-button" :size="size" @click="addChildren(size,row,index)" type="text" icon="el-icon-circle-plus-outline">添加子项目</el-button>
                <el-button v-if="row.children==null" class="menu-button" :size="size" @click="showUpdateDialog(size,row,index)" type="text" icon="el-icon-edit">编辑</el-button>
                <el-button v-if="row.children==null" class="menu-button" :size="size" @click="delInspectHandler(size,row,index)" type="text" icon="el-icon-delete">删除</el-button>
            </template>
        </avue-crud>
    </el-dialog>
    <el-dialog
    title="编辑"
    :visible.sync="updateVisible"
    width="50%">
        <el-form :model="editForm" label-position="right" label-width="100px" ref="editForm">
            <el-form-item label="检验项" prop="inspectName" :rules="{required:true,message:'检验项不能为空',trigger:'blur'}">
                <el-input
                disabled
                placeholder="请输入检验项目名称"
                type="textarea"
                v-model="editForm.inspectName"
                :rows="2" />
            </el-form-item>
            <el-form-item label="检验标准" prop="inspectRequired" :rules="{required:true,message:'检验标准不能为空',trigger:'blur'}">
                <el-input
                placeholder="请输入检验标准"
                type="textarea"
                v-model="editForm.inspectRequired"
                :rows="2" />
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="updateVisible = false">取 消</el-button>
            <el-button type="primary" @click="updateInspectHandler">确 定</el-button>
        </span>
    </el-dialog>
    <el-dialog
    title="添加子项目"
    :visible.sync="addChildrenVisible"
    width="50%">
        <el-form :model="addChildrenForm" label-position="right"
        label-width="100px" ref="addChildrenForm">
            <el-form-item label="检验项" prop="inspectName">
                <el-input
                placeholder="请输入检验项目名称"
                type="textarea"
                disabled
                v-model="addChildrenForm.inspectName"
                :rows="2" />
            </el-form-item>
            <el-form-item label="检验标准" prop="inspectRequired" :rules="{required:true,message:'检验标准不能为空',trigger:'blur'}">
                <el-input
                placeholder="请输入检验标准"
                type="textarea"
                v-model="addChildrenForm.inspectRequired"
                :rows="2" />
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="addChildrenVisible = false">取 消</el-button>
            <el-button type="primary" @click="addChildrenHandler">确 定</el-button>
        </span>
    </el-dialog>
</div>
</template>
 
<script>
import {getInspectList,addInspect,updateInspect,deleteInspect} from '@/api/quality/packageInspectTemp'
export default {
    props: {
        currshowlist: {
            type: Boolean,
            default: false
        },
        paramObj: {
            type: Object,
            default: ()=>{
                return null
            }
        }
    },
    watch: {
        updateVisible(newVal){
            if(!newVal){
                this.$refs.editForm.resetFields()
            }
        },
        addChildrenVisible(newVal){
            if(!newVal){
                this.$refs.addChildrenForm.resetFields()
            }
        },
        currshowlist() {
            this.inspectDialog = this.currshowlist
            if (this.currshowlist) {
                this.$nextTick(() => {
                    this.getData()
                })
            }
        }
    },
    data(){
        return {
            addChildrenVisible: false,
            addChildrenForm: {
                inspectName: null,
                inspectRequired: null,
            },
            editForm: {
                inspectName: null,
                inspectRequired: null,
            },
            updateVisible: false,
            inspectDialog: false,
            dataList: [],
            page:{
                currentPage: 1,
                pageSize: 20,
                total: 0
            },
            option: {
                rowKey: 'id',
                rowParentKey: 'id',
                defaultExpandAll: true,
                dialogWidth: '60%',
                menu: true,
                addBtn: true,
                editBtn: false,
                delBtn: false,
                border: true,
                index: true,
                height: 350,
                indexLabel: '序号',
                align: 'center',
                refreshBtn: false,
                columnBtn: false, // 是否显示显影按钮H
                headerAlign: 'center',
                column: [{
                    label: '检验项',
                    prop: 'inspectName',
                    overHidden: true,
                    formslot: true,
                }, {
                    label: '检验标准',
                    prop: 'inspectRequired',
                    overHidden: true,
                    formslot: true,
                }]
            },
        }
    },
    methods:{
        addChildren(size,row,index){
            this.addChildrenForm.inspectName = row.inspectName
            this.addChildrenVisible = true
        },
        addInspectHandler(row,done,loading){
            const _than = this
            let obj = {
                parentId: this.paramObj.id,
                ...row
            }
            addInspect(obj).then(res=>{
                if(res.status===200){
                    _than.getData()
                    _than.$message.success("添加成功")
                }
            }).catch(error=>{
                console.error(error)
            })
            done()
        },
        delInspectHandler(size,row,index){
            const _than = this
            this.$confirm('此操作将永久删除该检验项, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteInspect(row.id).then(res=>{
                    if(res.status===200){
                        _than.$message.success("删除成功")
                        _than.getData()
                    }
                }).catch(error=>{
                    console.error(error)
                })
            }).catch(() => {});
        },
        showUpdateDialog(size,row,index){
            this.editForm = {
                id: row.id,
                inspectName: row.templateName,
                inspectRequired: row.inspectRequired
            }
            this.updateVisible = true
        },
        updateInspectHandler(){
            this.$refs.editForm.validate(valid=>{
                if(valid){
                    updateInspect(this.editForm).then(res=>{
                        if(res.status===200){
                            this.$message.success("修改成功")
                            this.getData()
                            this.updateVisible = false
                        }
                    }).catch(error=>{
                        console.error(error)
                    })
                }
            })
        },
        addChildrenHandler(){
            const _than = this
            this.$refs.addChildrenForm.validate(valid=>{
                if(valid){
                    let obj = {
                        parentId: this.paramObj.id,
                        ...this.addChildrenForm
                    }
                    addInspect(obj).then(res=>{
                        if(res.status===200){
                            _than.getData()
                            _than.$message.success("添加成功")
                            _than.addChildrenVisible = false
                        }
                    }).catch(error=>{
                        console.error(error)
                    })
                }
            })
        },
        getData(){
            getInspectList(this.paramObj.id).then(res=>{
                if(res.status===200){
                    let dataList = res.data.data.records
                    dataList.forEach(ele=>{
                        ele.id = Math.random()
                    })
                    this.dataList = dataList
                    this.page.total = res.data.data.total
                }
            }).catch(error=>{
                console.error(error)
            })
        },
    }
}
</script>
 
<style scope>
.avue-crud__pagination {
    position: relative;
    padding: 0px 0 0px 20px;
    text-align: right;
    z-index: 10;
}
</style>