<template>
    <div class='app-container'>
        <el-form ref="dataFormRef" :rules="rules" :model="dataForm" status-icon label-width="300px">
            <el-form-item label="税率值" prop="mall_tax_rate">
                <el-input v-model="dataForm.mall_tax_rate" />
            </el-form-item>
            <el-form-item>
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" @click="doUpdate">确定</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import { taxConfig, saveTaxConfig } from '@/services/api/config/index'
import { ElMessage } from 'element-plus'

let dataFormRef = ref()
let dataForm = ref({
    mall_tax_rate: 0,
})
let rules = ref({
    mall_tax_rate: [
        { required: true, message: '不能为空', trigger: 'blur' }
    ]
})

let cancel = () => {
    init()
}

let doUpdate = () => {
    saveTaxConfig(dataForm.value).then((res: any) => {
        if (res.code === 200)
            ElMessage({
                type: 'success',
                message: '税率配置修改成功'
            })

    }).catch((res: any) => {
        ElMessage({
            type: 'error',
            message: res.msg
        })
    })
}

let init = () => {
    taxConfig().then((res: any) => {
        if (res.code === 200)
            dataForm.value = res.data
    })
}
init()
</script>
 
<style lang = "scss" scoped>
</style>