<template>
    <el-form :model="form" class="common-form" label-width="auto">
        <el-form-item label="回收折扣：">
            <ele-input
                v-model="form.notInListDiscount"
                placeholder="请输入"
                clearable
                suffixStr="折"
            />
        </el-form-item>
        <el-form-item label="最大回收量：">
            <ele-input
                v-model="form.notInListMax"
                placeholder="请输入"
                suffixStr="本"
                clearable
            />
        </el-form-item>
        <el-form-item label="单个订单回收数量：">
            <ele-input
                v-model="form.notInListPerMax"
                placeholder="请输入"
                clearable
                suffixStr="本"
            />
        </el-form-item>
        <el-form-item>
            <el-button
                type="success"
                style="width: 100px"
                plain
                @click="onSubmit"
                v-permission="'recycle:globalParameter:notAddRecycleBooklist'"
                >保存</el-button
            >
        </el-form-item>
    </el-form>
</template>

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

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

    const form = reactive({
        notInListDiscount: '',
        notInListMax: '',
        notInListPerMax: ''
    });

    watch(
        () => props.settings,
        (newVal) => {
            if (newVal) {
                form.notInListDiscount = newVal.notInListDiscount;
                form.notInListMax = newVal.notInListMax;
                form.notInListPerMax = newVal.notInListPerMax;
            }
        },
        { deep: true, immediate: true }
    );

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