1
lzhe
2024-06-05 dcf9c9e0410fe1186239e3f8d6f7bdc789c08010
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
<!--
 * @Date: 2024-05-08 21:29:53
 * @LastEditors: Sneed
 * @LastEditTime: 2024-05-09 20:55:54
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/console/basic-data/material-warehousing-data/material-infoComp2.vue
-->
<template>
    <el-containter>
        <el-header>
            <el-button @click="table_add" type="primary" icon="el-icon-plus"></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"
                        @click="batchDel"></el-button>
                </template>
            </el-popconfirm>
 
            <el-select v-model="params.status" style="width: 240px;margin-left: auto;" :prefix-icon="Search">
                <template #prefix>
                    状态
                </template>
                <el-option v-for="item in options.status" :key="item.value" :label="item.label" :value="item.value" />
            </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>
        </el-header>
        <el-main>
            <scTable ref="table" @selection-change="handleSelectionChange" row-key="id" border :params="params"
                :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="status" label="状态">
                    <template #default="scope">
                        {{ this.options.status.find(v => v.value == scope.row.status)?.label }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="left" width="160">
                    <template #default="scope">
                        <el-button-group>
                            <el-button text type="primary" size="small"
                                @click="table_edit(scope.row, scope.$index)">编辑</el-button>
                            <el-popconfirm v-if="scope.row == 1" 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 text type="primary" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                            <el-popconfirm v-else width="220" title="确定将选择的数据删除" @confirm="table_del([scope.row], '0')">
                                <template #reference>
                                    <el-button text type="primary" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
        <el-drawer v-model="drawer" title="物料类型">
            <el-form :model="form" :rules="rules" ref="dialogForm" label-width="120px" label-position="center">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="物料类型编码" prop="code">
                            <el-input style="width: 240px" v-model="form.code" placeholder=""></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="物料类型名称" prop="name">
                            <el-input style="width: 240px" v-model="form.name" placeholder=""></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="备注" prop="remark">
                            <el-input type="textarea" style="width: 240px" v-model="form.remark"
                                placeholder=""></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="状态" prop="status">
                            <el-select v-model="form.status" style="width: 240px;">
                                <el-option v-for="item in options.status" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <el-button type="primary" @click="save">保存</el-button>
            </template>
        </el-drawer>
    </el-containter>
</template>
 
<script>
export default {
    data() {
        return {
            activeName: '1',
            options: {
                status: [
                    {
                        label: '启用',
                        value: 1
                    },
                    {
                        label: '停用',
                        value: 0
                    },
                ],
            },
            params: {
                keyWord: '',
                status: 1
            },
            apiObj: {
                get: async (data) => {
                    let params = {
                        ...data
                    }
                    return await this.$HTTP.get(`/api/blade-cps/material-type/page`, params).then(res => {
                        return res
                    })
                }
            },
            selection: [],
            drawer: false,
            form: {
                id: '',
                status: 1,
                remark: '',
                name: '',
                code: '',
            },
            rules: {
                name: [
                    { required: true, message: '必填' }
                ],
                code: [
                    { required: true, message: '必填' }
                ],
            },
        }
    },
    created() {
        this.init()
    },
    methods: {
        init() {
            this.$HTTP.get(`/api/blade-cps/material-type/list`).then(res => {
                this.options.typeId = res.data.map(item => ({
                    label: item.name,
                    value: item.id
                }))
            })
            this.$HTTP.get(`/api/blade-system/dict/dictionary?code=material_property`).then(res => {
                this.options.property = res.data.map(item => ({
                    label: item.dictValue,
                    value: item.dictKey - 0
                }))
            })
        },
        search() {
            this.$refs.table.reload(this.params)
        },
        handleSelectionChange(selection) {
            this.selection = selection
        },
        table_add() {
            this.drawer = true
            this.form = {
                status: 1
            }
        },
        table_edit(row) {
            this.drawer = true
            this.form = {
                ...row
            }
        },
        batchDel() {
 
        },
        dataChange() {
 
        },
        table_del(rowArr, type) {
            this.$HTTP.delete(`/api/blade-cps/material-type/delete-material-type?ids=${rowArr.map(v => v.id).toString()}&type=${type}`).then(res => {
                if (res.code === 200) {
                    this.$message.success("操作成功");
                    this.$refs.table.reload(this.params)
                }
            })
        },
        save() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    if (this.form.id) {
                        this.$HTTP.put(`/api/blade-cps/material-type/update-material-type`, {
                            ...this.form
                        }).then(res => {
                            this.drawer = false
                            this.$refs.table.reload(this.params)
                        })
                    } else {
                        this.$HTTP.post(`/api/blade-cps/material-type/create-material-type`, {
                            ...this.form
                        }).then(res => {
                            this.drawer = false
                            this.$refs.table.reload(this.params)
                        })
                    }
                }
            })
 
        }
    }
}
</script>
 
<style lang="scss" scoped></style>