<template>
    <el-form :model="form" class="common-form" label-width="auto">
        <el-form-item label="" prop="maxMoney">
            <div class="flex w-full">
                <ele-text>自动初审最大金额 </ele-text>
                <el-input
                    v-model="form.maxMoney"
                    placeholder="请输入"
                    style="width: 120px; margin: 0 10px"
                />
                <ele-text>元</ele-text>
                <el-button
                    type="success"
                    style="width: 100px; margin-left: 20px"
                    plain
                    @click="onSubmit"
                    v-permission="'recycle:orderSetting:autoAuditSettings'"
                    >保存</el-button
                >
            </div>
        </el-form-item>
    </el-form>
</template>

<script setup>
    import { reactive, watch } from 'vue';
    import { ElMessage } from 'element-plus';
    import request from '@/utils/request';

    const props = defineProps({
        settings: {
            type: Object,
            default: () => ({})
        }
    });

    const form = reactive({
        maxMoney: ''
    });

    watch(
        () => props.settings,
        (newVal) => {
            if (newVal) {
                form.maxMoney = newVal.autoFirstAuditMaxMoney;
            }
        },
        { immediate: true, deep: true }
    );

    const onSubmit = () => {
        request
            .post('/recycle/manage/overall/update/autoFirstAudit', {
                maxMoney: form.maxMoney
            })
            .then((res) => {
                if (res.data.code === 200) {
                    ElMessage.success('保存成功');
                } else {
                    ElMessage.error(res.data.msg);
                }
            });
    };
</script>
