<template>
    <el-form :model="form" class="common-form" label-width="auto" :rules="rules">
        <el-form-item label="回收折扣：" prop="inListDiscount">
            <ele-input v-model="form.inListDiscount" placeholder="请输入" clearable suffixStr="折" />
        </el-form-item>
        <el-form-item label="最大回收量：" prop="inListMax">
            <ele-input v-model="form.inListMax" placeholder="请输入" suffixStr="本" clearable />
        </el-form-item>
        <el-form-item label="回收折扣小于 1(折)   单个订单回收数量：" prop="inListPerMaxLt1">
            <ele-input v-model="form.inListPerMaxLt1" placeholder="请输入" clearable suffixStr="本" />
        </el-form-item>
        <el-form-item label="回收折扣大于等于 1(折)   单个订单回收数量：" prop="inListPerMaxGe1">
            <ele-input v-model="form.inListPerMaxGe1" placeholder="请输入" clearable suffixStr="本" />
        </el-form-item>
        <el-form-item label="销量大于等于 100(本)   单个订单回收数量：" prop="inListSalesGe100">
            <ele-input v-model="form.inListSalesGe100" placeholder="请输入" clearable suffixStr="本" />
        </el-form-item>
        <el-form-item>
            <el-button type="success" style="width: 100px" plain @click="onSubmit" v-permission="'recycle:globalParameter:hasAddRecycleBooklist'">保存</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({
    inListDiscount: '',
    inListMax: '',
    inListPerMaxLt1: '',
    inListPerMaxGe1: '',
    inListSalesGe100: ''
});

watch(() => props.settings, (newVal) => {
    if (newVal) {
        form.inListDiscount = newVal.inListDiscount
        form.inListMax = newVal.inListMax
        form.inListPerMaxLt1 = newVal.inListPerMaxLt1
        form.inListPerMaxGe1 = newVal.inListPerMaxGe1
        form.inListSalesGe100 = newVal.inListSalesGe100
    }
}, { deep: true, immediate: true })

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