<template>
    <el-form :model="form" class="common-form" label-width="auto">
        <el-form-item label="每人每日申请恢复订单限量：" prop="everyLimit">
            <ele-input
                v-model="form.everyLimit"
                placeholder="请输入"
                clearable
                suffixStr="次"
            />
        </el-form-item>
        <el-form-item label="每日申请恢复订单总限量：" prop="totalLimit">
            <ele-input
                v-model="form.totalLimit"
                placeholder="请输入"
                suffixStr="次"
                clearable
            />
        </el-form-item>
        <el-form-item label="预留手机号：" prop="mobile">
            <el-input
                v-model="form.mobile"
                placeholder="请输入"
                clearable
                style="width: 190px"
            />
            <el-button
                type="primary"
                style="margin-left: 10px"
                @click="sendCode"
                >发送验证码</el-button
            >
        </el-form-item>
        <el-form-item label="验证码：" prop="code">
            <el-input
                v-model="form.code"
                placeholder="请输入"
                clearable
                style="width: 190px"
            />
        </el-form-item>
        <el-form-item>
            <el-button
                type="success"
                style="width: 100px"
                plain
                @click="onSubmit"
                v-permission="'recycle:orderSetting:restoreOrderSettings'"
                >保存</el-button
            >
        </el-form-item>
    </el-form>
</template>

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

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

    const form = reactive({
        everyLimit: '',
        totalLimit: '',
        mobile: ''
    });

    watch(
        () => props.settings,
        (newVal) => {
            if (newVal) {
                form.everyLimit = newVal.customerRecoverOrderEveryLimit;
                form.totalLimit = newVal.customerRecoverOrderTotalLimit;
                form.mobile = newVal.customerRecoverOrderMobile;
            }
        },
        { immediate: true, deep: true }
    );

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