gaoshp
2024-11-05 e2fdfe540eaf160dc7d063c60667041edcc64e86
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
<!--
 * @Date: 2024-06-23 19:58:50
 * @LastEditors: Sneed
 * @LastEditTime: 2024-06-23 21:07:31
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/console/basic-data/tpmComp1.vue
-->
<template>
    <el-conatiner>
        <el-header>
            <el-button type="primary" @click="addNew">新建</el-button>
            <!-- <el-button type="primary">导入</el-button> -->
            <import-table style="margin:0 8px" :exportUrl="exportUrlTpl" :uploadUrl="uploadUrl"></import-table>
            <el-button type="primary" @click="exportData">导出</el-button>
            <el-popconfirm width="220" cancel-button-text="停用" confirm-button-text="删除"
                title="删除数据会影响已关联的业务 ,若您想在已关联的业务中依然显示这些数据, 您可以选择 停用 操作。停用后此数据将不能再被新业务使用。"
                @confirm="table_del(selection, '0')" @cancel="table_del(selection, '1')">
                <template #reference>
                    <el-button :disabled="selection.length == 0" type="danger" plain icon="el-icon-delete"></el-button>
                </template>
            </el-popconfirm>
            <el-select v-model="params.status" placeholder="请选择" style="width: 240px;margin-left: auto;">
                <template #prefix><span style="margin-right: 6px;">状态</span></template>
                <el-option key="0" label="停用" :value="0" />
                <el-option key="1" label="启用" :value="1" />
            </el-select>
            <el-input style="width: 240px;margin-left: 8px;" v-model="params.keyWord" placeholder="请输入检索内容"></el-input>
            <el-button @click="search" style="margin-left: 8px;" type="primary" icon="el-icon-search"></el-button>
            <scDialog v-model="visible">
                <scForm v-if="visible" ref="form" :config="config" :rules="rules" v-model="form" @submit="submit">
                </scForm>
            </scDialog>
        </el-header>
        <el-main>
            <scTable ref="table" @selection-change="handleSelectionChange" row-key="id" border :apiObj="apiObj" stripe
                @dataChange="dataChange">
                <el-table-column type="selection" width="55" />
                <el-table-column prop="code" label="点检编号" />
                <el-table-column prop="name" label="点检项目" />
                <el-table-column prop="remark" label="点检备注" />
                <el-table-column prop="statusName" label="点检状态" />
                <el-table-column label="操作" fixed="right" align="left" width="160">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small"
                                @click="view(scope.row, scope.$index)">查看点检项</el-button>
                            <el-button text type="primary" size="small"
                                @click="table_edit(scope.row, scope.$index)">编辑</el-button>
                            <el-popconfirm width="220" cancel-button-text="停用" confirm-button-text="删除"
                                title="删除数据会影响已关联的业务 ,若您想在已关联的业务中依然显示这些数据, 您可以选择 停用 操作。停用后此数据将不能再被新业务使用。"
                                @confirm="table_del([scope.row], '0')" @cancel="table_del([scope.row], '1')">
                                <template #reference>
                                    <el-button type="danger" text size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <scDialog v-model="visibleCheck">
            <scFormTable ref="table1" v-model="tabledata" stripe hideDelete :addTemplate="addTemplate">
                <el-table-column label="点检项" prop="name">
                    <template #default="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.name"></el-input>
                        <span v-else>{{ scope.row.name }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="数值类型" prop="valueType">
                    <template #default="scope">
                        <el-select v-if="scope.row.isEdit" v-model="scope.row.valueType" style="width: 100%;"
                            @change="change($event, scope.row)">
                            <el-option v-for="(item, index) in options" :key="index" :label="item"
                                :value="item"></el-option>
                        </el-select>
                        <span v-else>{{ scope.row.valueType }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="点检要求" prop="requirement">
                    <template #default="scope">
                        <el-input v-if="scope.row.isEdit" v-model="scope.row.requirement"></el-input>
                        <span v-else>{{ scope.row.requirement }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="标准数值" prop="standardValue" width="180">
                    <template #default="scope">
                        <el-input v-if="scope.row.isEdit && scope.row.valueType === 'Text'"
                            v-model="scope.row.standardValue"></el-input>
                        <el-input-number v-model="scope.row.standardValue"
                            v-else-if="scope.row.isEdit && scope.row.valueType === 'Number'" :min="0" />
 
                        <el-date-picker style="width: 150px" value-format="YYYY-MM-DD" v-model="scope.row.standardValue"
                            v-else-if="scope.row.isEdit && scope.row.valueType === 'Date'" type="date" />
                        <span v-else>{{ scope.row.standardValue }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" prop="state">
                    <template #default="scope">
                        <el-button-group>
                            <el-button v-show="!scope.row.id || scope.row.isEdit" text type="primary" size="small"
                                @click="add(scope.row)">保存</el-button>
                            <el-button v-show="!scope.row.id || scope.row.isEdit" text type="primary" size="small"
                                @click="cancel(scope.row)">取消</el-button>
                            <el-button v-show="!scope.row.isEdit" text type="primary" size="small"
                                @click="edit(scope.row)">编辑</el-button>
                            <el-popconfirm width="220" title="确定将选择的数据删除" @confirm="del(scope.row)">
                                <template #reference>
                                    <el-button v-show="!scope.row.isEdit" text type="primary"
                                        size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
 
                    </template>
                </el-table-column>
            </scFormTable>
        </scDialog>
    </el-conatiner>
</template>
 
<script>
import importTable from '@/layout/components/importTable.vue'
export default {
    components: {
        importTable,
    },
    data() {
        return {
            params: {
                status: 1,
                key: ''
            },
            form: {},
            selection: [],
            visible: false,
            exportUrlTpl: '/api/smis/check-project/excel/template',
            uploadUrl: '/api/smis/check-project/excel/import',
            config: {
                labelWidth: 120,
                formItems: [
                    {
                        component: 'input',
                        label: '点检编号',
                        name: 'code',
                        options: {
                            placeholder: '',
                            maxlength: 100,
                        }
                    },
                    {
                        component: 'input',
                        label: '点检项目',
                        name: 'name',
                        options: {
                            multiple: false,
                            data: []
                        },
                        disabled: false
                    },
                    {
                        component: 'input',
                        label: '备注',
                        name: 'remark',
                        type: 'textarea',
                        options: {
                            multiple: false,
                            data: []
                        },
                        disabled: false
                    },
                    {
                        component: 'select',
                        label: '状态',
                        name: 'status',
                        options: {
                            multiple: false,
                            items: [
                                {
                                    value: 1,
                                    label: '启用'
                                },
                                {
                                    value: 0,
                                    label: '停用'
                                },
                            ]
                        },
                        disabled: false
                    }
                ]
            },
            rules: {
                code: [
                    { required: true, message: '请输入' },
                ],
                name: [
                    { required: true, message: '请输入' },
                ]
            },
            apiObj: {
                get: async (data) => {
                    let params = {
                        ...data,
                        ...this.params
                    }
                    return await this.$HTTP.get(`/api/smis/check-project/page`, {}, { params }).then(res => {
                        res.data.records = res?.data?.records.map(v => {
                            return {
                                ...v,
                                statusName: v.status ? '启用' : '禁用'
                            }
                        })
                        return res
                    })
                }
            },
            visibleCheck: false,
            tabledata: [],
            options: ['Text', 'Number', 'Date'],
            addTemplate: {
                isEdit: true,
                name: '',
                requirement: '',
                standardValue: '',
                valueType: ''
            }
        }
    },
    methods: {
        handleSelectionChange(selection) {
            this.selection = selection
        },
        addNew() {
            this.config.formItems[0].disabled = false
            this.config.formItems[1].disabled = false
            this.form = {
                status: 1,
            }
            this.visible = true
        },
        table_edit(row) {
            this.config.formItems[0].disabled = true
            this.config.formItems[1].disabled = true
            this.form = {
                ...row
            }
            this.visible = true
        },
        submit() {
            if (!this.form.id) {
                this.$HTTP.post(`/api/smis/check-project`, this.form).then(res => {
                    if (res.success) {
                        this.visible = false
                        this.search()
                    }
                })
            } else {
                this.$HTTP.put(`/api/smis/check-project`, this.form).then(res => {
                    if (res.success) {
                        this.visible = false
                        this.search()
                    }
                })
            }
 
        },
        exportData() {
            this.$HTTP.post(`/api/smis/check-project/excel/export`, {}, { params: this.params }).then(res => {
                if (res.success) {
                    window.open(res.data.link)
                }
            })
        },
        search() {
            this.$refs.table.reload()
        },
        table_del(selection, type) {
            this.$HTTP.delete(`/api/smis/check-project?type=${type}`, {}, {
                data: {
                    ids: selection.map(v => v.id),
                }
            }).then(res => {
                if (res.success) {
                    this.search()
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        view(row) {
            this.selectRow = row
            this.getList().then(() => {
                this.visibleCheck = true
            })
        },
        getList() {
            let row = this.selectRow
            return this.$HTTP.get(`/api/smis/check-item/list?projectId=${row.id}`).then(res => {
                if (res.success) {
                    this.tabledata = res.data
                }
            })
        },
        del(row) {
            this.$HTTP.delete(`/api/smis/check-item`, {}, {
                data: {
                    ids: [row.id]
                }
            }).then(res => {
                if (res.success) {
                    this.getList()
                }
            })
        },
        edit(row) {
            row.isEdit = true
        },
        change(e, row) {
            row.standardValue = ''
        },
        cancel(row) {
            row.isEdit = false
        },
        add(row) {
            if (!row.id) {
                this.$HTTP.post(`/api/smis/check-item`, {
                    checkProjectId: this.selectRow.id,
                    items: [{
                        ...row,
                        name: row.name,
                        requirement: row.requirement,
                        standardValue: row.standardValue,
                        valueType: row.valueType,
                        status: 1,
                        editable: true
                    }]
                }).then(res => {
                    this.getList()
                })
            } else {
                this.$HTTP.put(`/api/smis/check-item`, {
                    ...row,
                    name: row.name,
                    requirement: row.requirement,
                    standardValue: row.standardValue,
                    valueType: row.valueType,
                    status: 1,
                }).then(res => {
                    this.getList()
                })
            }
        }
    },
}
</script>
 
<style lang="scss" scoped></style>