<template>
    <div class="app-container">
        <h3 style="font-weight: bold;">摄像头设置</h3>
        <div style="width: 100%;margin: 10px auto;border: 1px solid #ccc;padding: 10px;border-radius: 10px;">
            <div style="font-weight: bold;border-left: 4px solid #1890FF;padding-left: 4px;">摄像头设置</div>
            <div class="item">
                <div>
                    <div>
                        <span class="item-label">实名抓拍:</span>
                         <el-switch @change="changeSwitch"
                            v-model="camera_real_name_capture"
                            active-value="1" active-text="开启"
                            inactive-value="2" inactive-text="关闭">
                        </el-switch>
                    </div>
                    <div style="color: #999;font-size: 14px;margin-top: 10px">说明：开启后仅上传摄像头人脸识别成功的员工违规抓拍记录</div>
                </div>
            </div> 
            <div class="item">
                <div>
                    <div>
                        <span class="item-label">人脸识别相似度:</span>
                        <el-input
                            v-model="camera_face_recognition_similarity" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" maxlength="9"
                            placeholder="70" 
                            ></el-input>
                        <span class="item-unit">%</span> 
                    </div>
                    <div style="color: #999;font-size: 14px;margin-top: 10px">说明：旷世分析盒用于识别人脸的配置参数,违规照片人脸识别分超过本参数且分数最高的将被确定为违规人员,如果违规人员识别率偏高,可将本参数调高来减少误识别</div>
                </div>
                <div style="display: flex;padding-left: 40px;">
                    <el-button type="primary" @click="save41">保存</el-button>
                    <el-button type="info" @click="reset41">恢复默认</el-button>
                </div>
            </div> 
            <div class="item">
                <div>
                    <div>
                        <span class="item-label">摄像头抓拍设置:</span>
                    </div>
                    <div style="color: #999;font-size: 14px;margin-top: 10px">说明：同一摄像头对同一个人的同一种违规类型的抓拍时间范围和抓拍频率设置。</div>
                </div>
               
            </div>
            <div class="item" >
                <div style="width: 80%;height: auto;border: 1px solid #e0e0e0;">
                    <el-table v-loading="loading" :data="tableList">
                        <el-table-column label="违规类型" align="center" prop="itemDescription" :show-overflow-tooltip="true"  />
                        <el-table-column label="抓拍时间" align="center" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-time-picker
                                is-range v-model="scope.row.timeList" style="width: 100%;"
                                range-separator="至" format="HH:mm:ss" value-format="HH:mm:ss" 
                                start-placeholder="00:00:00" end-placeholder="23:59:59"
                                @change="changeOrderTimeList(scope.row)"
                                placeholder="选择时间范围"></el-time-picker>
                            </template>
                        </el-table-column>
                        <el-table-column label="抓拍频率" align="center" prop="frequency" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.frequency" style="width: 60%;" maxlength="9"
                                auto-complete="off" placeholder="60"></el-input><span class="item-unit">秒</span> 
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" width="300" class-name="small-padding fixed-width">
                            <template slot-scope="scope"> 
                                <el-button 
                                type="primary" 
                                @click="save42(scope.row)" 
                                >保存</el-button>
                                <el-button
                                type="info" 
                                @click="reset42(scope.row)" 
                                >恢复默认</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <!-- <div style="width: 30%;display: flex;padding-left: 40px;align-self: self-end;">
                    <el-button type="primary" @click="save42">保存</el-button>
                    <el-button type="info" @click="reset42">恢复默认</el-button>
                </div> -->
            </div> 
            
        </div> 
    </div>
</template>
  
<script> 
import { getSettingListApi,batchEditSettingApi,batchResetSettingApi,getCameraSettingListApi,batchEditCameraSettingApi,batchResetCameraSettingApi } from "@/api/kitchen/setting.js";
export default {
        name: "",
        dicts: [],
        data() {
        return {
            //摄像头设置
            camera_real_name_capture:1,
            camera_face_recognition_similarity:null,
            loading:false,
            tableList:[],
            timeList1:[],
            camera_capture_without_hat_frequency:null,
            timeList2:[],
            camera_capture_without_mask_frequency:null,
            timeList3:[],
            camera_capture_without_uniform_frequency:null,
            timeList4:[],
            camera_capture_without_glove_frequency:null,
            timeList5:[],
            camera_capture_smoking_frequency:null,
            timeList6:[],
            camera_capture_calling_frequency:null,
            timeList7:[],
            camera_capture_trash_no_cover_frequency:null,
            timeList8:[],
            camera_capture_found_mouse_frequency:null,
            timeList9:[],
            camera_capture_fire_without_staff_frequency:null,
            timeList10:[],
            camera_capture_unauthorized_entry_frequency:null,




        };
    },
    created() {
        
    },
    mounted(){
        this.query41()
        this.query42()
    },
    methods: {
        changeSwitch(e){
            console.log(e)
            let param = [
                {"itemName": "camera_real_name_capture","itemValue":this.camera_real_name_capture}
            ]
            batchEditSettingApi(param).then(response => {
                this.$message.success("修改成功");
                this.query41()
            }); 
        },
        query41(){
            getSettingListApi({"itemName": "camera_real_name_capture"}).then(response => { 
                this.camera_real_name_capture = response.rows[0].itemValue
            }); 
            getSettingListApi({"itemName": "camera_face_recognition_similarity"}).then(response => { 
                this.camera_face_recognition_similarity = response.rows[0].itemValue
            });
        },
        save41(){
            let param = [
                {"itemName": "camera_face_recognition_similarity","itemValue":this.camera_face_recognition_similarity}
            ]
            batchEditSettingApi(param).then(response => {
                this.$message.success("保存成功");
                this.query41()
            }); 
        },
        reset41(){
            let param = [
                {"itemName": "camera_face_recognition_similarity"}
            ]
            batchResetSettingApi(param).then(response => {
                this.$message.success("恢复成功");
                this.query41()
            }); 
        },
        query42(){
            this.loading=true;
            getCameraSettingListApi().then(response => {
                this.tableList = response.rows;
                this.tableList.forEach(item=>{ 
                    this.$set(item,"timeList",[item.startTime,item.endTime])
                })
                this.loading=false
            });
        },
        changeOrderTimeList(row){
            console.log(row)
            row.startTime = row.timeList[0]
            row.endTime = row.timeList[1]
        },
        save42(row){ 
            let param = [row]
            batchEditCameraSettingApi(param).then(response => {
                this.$message.success("保存成功");
                this.query42()
            }); 
        },
        reset42(row){
            let param = [{"itemName":row.itemName}]
            batchResetCameraSettingApi(param).then(response => {
                this.$message.success("恢复成功");
                this.query42()
            }); 
        },




    }
};
</script>
<style scoped>
    .item{
        width: 96%;margin: 10px auto;padding: 20px 10px;border-radius: 8px;display: flex;align-items: center;
    }
    .item-label{
        display: inline-block;
        width: 240px;
    }
    .item-unit{
        margin-left: 10px;
    }
    .item-th{
        width: 100%;height: 60px;display: flex;line-height: 60px;
    }
</style>
  