<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-select v-model="staff_health_cert_left_day_reminder" placeholder="请选择" style="width: 240px;">
                            <el-option label="向上取整" :value="0"></el-option>
                            <el-option label="向下取整" :value="1"></el-option> 
                            <el-option label="四舍五入" :value="2"></el-option>  
                        </el-select>  
                    </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-select v-model="staff_health_cert_left_day_reminder" placeholder="请选择" style="width: 240px;">
                            <el-option label="参考上次采购价格" :value="0"></el-option>
                            <el-option label="参考采集的市场价格" :value="1"></el-option>  
                        </el-select>  
                    </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.number="staff_health_cert_left_day_reminder" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" placeholder="30" maxlength="3" @input="(v)=>(staff_health_cert_left_day_reminder=v.replace(/[^\d]/g,''))"
                            ></el-input>
                        <span class="item-unit">天</span> 
                    </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.number="staff_morning_check_video_save_day" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" maxlength="3" placeholder="30" @input="(v)=>(staff_morning_check_video_save_day=v.replace(/[^\d]/g,''))"
                            ></el-input>
                        <span class="item-unit">天</span> 
                    </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.number="staff_morning_check_video_save_day" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" maxlength="3" placeholder="30" @input="(v)=>(staff_morning_check_video_save_day=v.replace(/[^\d]/g,''))"
                            ></el-input>
                    </div>
                    <div style="color: #999;font-size: 14px;margin-top: 10px">设置货品即将缺货数量,系统将根据货品的库存数量自动进行提醒</div>
                </div>
            </div> 
            <div style="display: flex;padding-left: 40px;">
                <el-button type="primary" @click="save1">保存</el-button>
                <el-button type="info" @click="reset1">恢复默认</el-button>
            </div>
        </div>
    </div>
</template>
  
<script> 
import { getSettingListApi,batchEditSettingApi,batchResetSettingApi } from "@/api/kitchen/setting.js";
  
export default {
        name: "",
        dicts: [],
        data() {
        return {
            //员工信息设置
            staff_health_cert_left_day_reminder:null,
            //存储设置
            staff_morning_check_video_save_day:null,
            staff_illegal_warning_record_save_day:null,
            //环境监控设置
            env_monitor_statis_frequency:null,
            metricSettingList:[],
            env_temperature_max_value:null,
            env_temperature_min_value:null,
            env_humidity_max_value:null,
            env_humidity_min_value:null,
            env_smoke_max_value:null,
            env_sample_cabinet_temp_max_value:null,
            env_sample_cabinet_temp_min_value:null,   
        };
    },
    created() {
        
    },
    mounted(){
        this.query1()
        this.query2() 
    },
    methods: {
        query1(){
            getSettingListApi({"itemName": "staff_health_cert_left_day_reminder"}).then(response => { 
                this.staff_health_cert_left_day_reminder = response.rows[0].itemValue
            }); 
        },
        save1(){
            let param = [
                {"itemName": "staff_health_cert_left_day_reminder","itemValue":this.staff_health_cert_left_day_reminder}
            ]
            batchEditSettingApi(param).then(response => {
                this.$message.success("保存成功");
                this.query1()
            }); 
        },
        reset1(){
            let param = [
                {"itemName": "staff_health_cert_left_day_reminder"}
            ]
            batchResetSettingApi(param).then(response => {
                this.$message.success("恢复成功");
                this.query1()
            }); 
        }, 
        query2(){
            getSettingListApi({"itemName": "staff_morning_check_video_save_day"}).then(response => { 
                this.staff_morning_check_video_save_day = response.rows[0].itemValue
            });
            getSettingListApi({"itemName": "staff_illegal_warning_record_save_day"}).then(response => { 
                this.staff_illegal_warning_record_save_day = response.rows[0].itemValue
            }); 
        },
        save2(){
            let param = [
                {"itemName": "staff_morning_check_video_save_day","itemValue":this.staff_morning_check_video_save_day},
                {"itemName": "staff_illegal_warning_record_save_day","itemValue":this.staff_illegal_warning_record_save_day},
            ]
            batchEditSettingApi(param).then(response => {
                this.$message.success("保存成功");
                this.query2()
            }); 
        },
        reset2(){
            let param = [
                {"itemName": "staff_morning_check_video_save_day"},
                {"itemName": "staff_illegal_warning_record_save_day"},
            ]
            batchResetSettingApi(param).then(response => {
                this.$message.success("恢复成功");
                this.query2()
            }); 
        }
    }
};
</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>
  