<template>

   <div style="padding:40px;">
    <el-form
        ref="ruleFormRef"
        :model="formData"
        :rules="rules"
        label-width="100px"
        style="width: 100%"
    >
        <el-form-item label="账号" prop="account">
            <el-input v-model="formData.account"/>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="formData.password"/>
        </el-form-item>
    </el-form>
    <div class="flex justify-flex-end mt-20">
        <el-button type="primary" @click="save" :disabled="!auth('edit')">保存</el-button>
    </div>
</div>
</template>

<script setup lang="ts">

import {onMounted, ref} from "vue";
import request from "/@/api/request";
import {sysConfig} from "/@/api/controllerUrls";
import {ElNotification} from "element-plus/es";
import {auth} from '/@/utils/common'

onMounted(() => {
    getFormData()
})


let formData = ref({
    account: '',
    password: '',
})

let rules = ref({
    account: [{required: true, message: '请输入', trigger: 'blur',}],
    password: [{required: true, message: '请输入', trigger: 'blur',}],
})

function getFormData() {
    request.index(sysConfig, {configName: 'sms'}, 'edit').then((res: any) => {
        formData.value = res.data.configValue
    })
}

let ruleFormRef = ref()

function save() {
    ruleFormRef.value.validate((valid: any, fields: any) => {
        if (valid) {
            request.edit(sysConfig, {
                configName: 'sms',
                configValue: formData.value
            }).then((res: any) => {
                ElNotification({type: 'success', message: res.msg,})
            })
        }
    })

}
</script>

<style scoped>

</style>
