<template>
    <div v-loading="loading">
        <div class="white-box">
            <el-form ref="form" :model="form" label-width="250px" class="form-page" style="margin-top: 25px;">
                <el-form-item :label="form.TITLE" :key="form.CONFIG_NAME">
                    <el-input v-model="form.VALUE" placeholder="请输入内容">
                        <template slot="append">naira / $</template>
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <span style="font-weight: bold; color: red; font-size: 12px;">提示：修改汇率会刷新商品的销售价格(naira)，请谨慎操作！！</span>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="onSubmit" :loading="submitButtonStat">保存并刷新商品价格</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import network from '@/utils/network'
export default {
    name: 'config_exchange_rate',
    mounted() {
        this.getData()
    },
    data() {
        return {
            form: {
                CONFIG_NAME: '',
                VALUE: 0,
                TITLE: '',
            },
            loading: true,
            submitButtonStat: false,
        }
    },
    methods: {
        onSubmit() {
            let _this = this
            _this.$confirm('修改汇率会刷新商品销售价格(naira), 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                _this.submitButtonStat = true
                network.postData('config/exchange-rate', this.form).then(response => {
                    _this.$message({
                        message: response,
                        type: 'success'
                    })
                    _this.submitButtonStat = false
                    _this.getData()
                }).catch(response => {
                    _this.submitButtonStat = false
                    _this.getData()
                })
            }).catch(() => {
                _this.submitButtonStat = false
            })
        },
        getData() {
            network.getData('config/exchange-rate').then(response => {
                this.form = response
                this.loading = false
            })
        }
    }
}
</script>

<style scoped>

</style>
