<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="material_conversion_rounding_method" 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="purchase_plan_reference_price" 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="goods_expireing_day_reminder" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" placeholder="30" maxlength="3" @input="(v)=>(goods_expireing_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="qualification_certificates_expiring_day_reminder" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" maxlength="3" placeholder="30" @input="(v)=>(qualification_certificates_expiring_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="goods_lacking_number_reminder" style="width: 200px;margin-left: 50px;"
                            auto-complete="off" maxlength="3" placeholder="30" @input="(v)=>(goods_lacking_number_reminder=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> 
            </div>
        </div>
    </div>
</template>
  
<script> 
import { getSettingListApi,batchEditSettingApi } from "@/api/foodManage/baseInfo.js";
  
export default {
        name: "",
        dicts: [],
        data() {
        return { 
            material_conversion_rounding_method:null, 
            purchase_plan_reference_price:null,
            goods_expireing_day_reminder:null, 
            qualification_certificates_expiring_day_reminder:null, 
            goods_lacking_number_reminder:null,
            
        };
    },
    created() {
        
    },
    mounted(){
        this.query1() 
    },
    methods: {
        query1(){
            getSettingListApi().then(response => { 
                let arr = response.rows;
                arr.forEach(item=>{
                    if(item.itemName=='material_conversion_rounding_method'){
                        this.material_conversion_rounding_method = item.itemValue
                    }
                    if(item.itemName=='purchase_plan_reference_price'){
                        this.purchase_plan_reference_price = item.itemValue
                    }
                    if(item.itemName=='goods_expireing_day_reminder'){
                        this.goods_expireing_day_reminder = item.itemValue
                    }
                    if(item.itemName=='qualification_certificates_expiring_day_reminder'){
                        this.qualification_certificates_expiring_day_reminder = item.itemValue
                    }
                    if(item.itemName=='goods_lacking_number_reminder'){
                        this.goods_lacking_number_reminder = item.itemValue
                    }
                }) 
            }); 
        },
        save1(){
            let param = [
                {"itemName": "material_conversion_rounding_method","itemValue":this.material_conversion_rounding_method},
                {"itemName": "purchase_plan_reference_price","itemValue":this.purchase_plan_reference_price},
                {"itemName": "goods_expireing_day_reminder","itemValue":this.goods_expireing_day_reminder},
                {"itemName": "qualification_certificates_expiring_day_reminder","itemValue":this.qualification_certificates_expiring_day_reminder},
                {"itemName": "goods_lacking_number_reminder","itemValue":this.goods_lacking_number_reminder},
            ]
            batchEditSettingApi(param).then(response => {
                this.$message.success("保存成功");
                this.query1()
            }); 
        }, 
    }
};
</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>
  