烟花爆竹实名登记前端
祖安之光
2026-03-25 66900bcf11faa01ea740ee14ee8d8a59a13a8e26
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
<template>
    <el-dialog
        :visible.sync="dialogVisible"
        append-to-body
        :close-on-click-modal="false"
        title="设备管理"
        center
        width="75%"
    >
        <el-button
            type="primary"
            style="margin-bottom: 20px"
            @click="openAdd('新增设备', {})"
            >绑定设备</el-button
        >
        <el-table
            :data="deviceList"
            border
            :stripe="false"
            style="width: 100%;"
        >
            <el-table-column
                label="序号"
                type="index"
                align="center"
            ></el-table-column>
            <el-table-column
                label="设备名称"
                prop="deviceName"
                align="center"
            ></el-table-column>
            <el-table-column
                label="设备ID"
                prop="deviceId"
                align="center"
            ></el-table-column>
            <!-- <el-table-column label="设备类型" prop="deviceId" align="center">
                <template slot-scope="scope">
                    {{scope.row.deviceType == 1?'温湿度':'摄像头'}}
                </template>
            </el-table-column>
            <el-table-column label="分组ID" prop="groupId" align="center"></el-table-column> -->
            <el-table-column
                label="操作"
                align="center"
                width="180"
                class-name="small-padding fixed-width"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        @click="openAdd('修改设备', scope.row)"
                        >修改</el-button
                    >
                    <el-button
                        type="text"
                        style="color: red"
                        @click="delDevice(scope.row)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogVisible = false"
                >关 闭</el-button
            >
        </span>
        <el-dialog
            :visible.sync="addVisible"
            append-to-body
            :close-on-click-modal="false"
            :title="title"
            center
            width="50%"
            @close="reset()"
        >
            <el-form
                ref="form"
                :rules="formRules"
                :model="deviceForm"
                label-width="140px"
                class="form"
            >
                <el-form-item label="设备类型:" prop="deviceType">
                    <el-radio-group v-model="deviceForm.deviceType">
                        <el-radio :label="1">AI盒子</el-radio>
                        <el-radio :label="2">AI摄像头</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="设备名称:" prop="deviceName">
                    <el-input v-model.trim="deviceForm.deviceName" />
                </el-form-item>
                <el-form-item label="设备ID:" prop="deviceId">
                    <el-input v-model.trim="deviceForm.deviceId" />
                </el-form-item>
                <el-form-item v-if="deviceForm.deviceType == 2" label="云端用户名:" prop="accessKey">
                    <el-input v-model.trim="deviceForm.accessKey" :disabled="title == '修改设备'"/>
                </el-form-item>
                <el-form-item v-if="deviceForm.deviceType == 2" label="云端密码:" prop="accessSecret">
                    <el-input v-model.trim="deviceForm.accessSecret" :disabled="title == '修改设备'"/>
                </el-form-item>
                <!-- <el-form-item label="类型:" prop="deviceType">
                    <el-select v-model="deviceForm.deviceType" placeholder="请选择类型">
                        <el-option key="1" label="温湿度" :value="1"></el-option>
                        <el-option key="2" label="摄像头" :value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="分组ID:" prop="groupId">
                    <el-input v-model.trim="deviceForm.groupId"/>
                </el-form-item> -->
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirm()">确 认</el-button>
            </span>
        </el-dialog>
    </el-dialog>
</template>
 
<script>
import { mapGetters } from "vuex";
import { getCityListData, getProvinceListData } from "../../../../api/area";
// import {saveReserveInfo, getInfoById, editReserveInfo, delStore} from '../../../api/warehouse'
import Cookies from "js-cookie";
import { MessageBox } from "_element-ui@2.14.1@element-ui";
import {
    addOrUpdateStoreroomDevice,
    deleteStoreroomDevice,
    getDeviceList,
    getDevicePageList,
    getStoreroomPage,
    getStoreroomPageV2
} from "../../../../api/monitorAlert";
export default {
    name: "deviceDialog",
    data() {
        return {
            dialogVisible: false,
            title: "",
            addVisible: false,
            deviceQuery: {
                companyCode: "",
                storeNum: "",
                storeroomNum: ""
            },
            deviceList: [],
            deviceForm: {
                id: "",
                companyCode: "",
                deviceId: "",
                deviceName: "",
                deviceType: null,
                groupId: "",
                storeNum: "",
                storeroomNum: "",
                accessKey: "",
                accessSecret: ""
            },
            formRules: {
                deviceType: [
                    {
                        required: true,
                        message: "请选择设备类型",
                        trigger: "blur"
                    }
                ],
                deviceName: [
                    {
                        required: true,
                        message: "请输入设备名称",
                        trigger: "blur"
                    }
                ],
                deviceId: [
                    {
                        required: true,
                        message: "请输入设备id",
                        trigger: "blur"
                    }
                ],
                accessKey: [
                    {
                        required: true,
                        message: "请输入云端用户名",
                        trigger: "blur"
                    }
                ],
                accessSecret: [
                    {
                        required: true,
                        message: "请输入云端密码",
                        trigger: "blur"
                    }
                ]
            }
        };
    },
    created() {
        const t = this;
    },
    computed: {
        ...mapGetters(["userType", "username"])
    },
    methods: {
        open(data) {
            const { companyCode, storeNum, storeroomNum } = data;
            this.deviceQuery = { companyCode, storeNum, storeroomNum };
            this.getDataList();
            this.dialogVisible = true;
        },
        isKey(key, obj) {
            return key in obj;
        },
        async getDataList() {
            let res = await getDeviceList({
                filter: this.deviceQuery
            });
            if (res.data.code === "200") {
                if (Array.isArray(res.data.result)) {
                    this.deviceList = res.data.result;
                } else {
                    this.dataList = [];
                }
            } else {
                this.$message({
                    type: "warning",
                    message: res.data.message
                });
            }
            this.listLoading = false;
        },
 
        openAdd(type, data) {
            this.addVisible = true;
            this.title = type;
            this.deviceForm.companyCode = this.deviceQuery.companyCode;
            this.deviceForm.storeNum = this.deviceQuery.storeNum;
            this.deviceForm.storeroomNum = this.deviceQuery.storeroomNum;
            if (type == "修改设备") {
                for (let i in this.deviceForm) {
                    if (this.isKey(i, data)) {
                        this.deviceForm[i] = data[i];
                    }
                }
            }
        },
 
        confirm() {
            this.$refs.form.validate(async valid => {
                if (valid) {
                    if(this.deviceForm.deviceType == 1){
                        this.deviceForm.accessKey = ''
                        this.deviceForm.accessSecret = ''
                    }
                    const { id, ...data } = this.deviceForm;
                    const res = await addOrUpdateStoreroomDevice(
                        this.title == "新增设备" ? data : this.deviceForm
                    );
                    if (res.data.code == 200) {
                        if (this.title == "新增设备") {
                            this.$message.success("设备新增成功");
                        } else {
                            this.$message.success("设备修改成功");
                        }
                    } else {
                        this.$message.warning(res.data.message);
                    }
                    this.addVisible = false;
                    await this.getDataList();
                }
            });
        },
        delDevice(data) {
            const t = this;
            t.$confirm("此操作将删除该设备, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(async () => {
                const res = await deleteStoreroomDevice({ id: data.id });
                console.log(res, "res");
                if (res.data.code == 200) {
                    t.$message.success("设备删除成功");
                } else {
                    t.$message.warning(res.data.message);
                }
                await this.getDataList();
            });
        },
        reset() {
            this.deviceForm = {
                id: "",
                companyCode: "",
                deviceId: "",
                deviceName: "",
                deviceType: null,
                groupId: "",
                storeNum: "",
                storeroomNum: "",
                accessKey: "",
                accessSecret: ""
            };
            this.$refs.form.clearValidate();
        }
    }
};
</script>
 
<style lang="scss" scoped>
.part-title {
    font-size: 16px;
    font-weight: bolder;
}
.selector {
    /deep/ .el-form-item__content {
        margin-left: 0 !important;
    }
}
.editForm {
    .el-form-item {
        display: flex !important;
    }
    /deep/ .el-form-item__content {
        width: 100%;
        margin-left: 0 !important;
    }
}
 
.numInput {
    /deep/ .el-input__inner {
        padding-right: 0;
    }
}
tr {
    display: flex;
    td {
        flex: 1;
        display: flex;
        justify-content: center;
        padding: 5px;
        align-items: center;
    }
    .w-12 {
        flex: 0.5;
    }
    .w-20 {
        flex: 2;
    }
}
</style>