<!--新增、编辑、查看参数详情-->
<template>
    <div>
        <!--<div class="title">选择普通账户</div>
        <tableList
            ref="table"
            style="width:60%;min-width: 900px;margin: auto;"
            :columns="columns"
            :getDataWay="getDataWay"
            :checkedData="checkedData"
            index
            selection
        >
            
        </tableList>-->
        <el-form
            ref="form"
            :model="form"
            :rules="rules"
            label-width="220px"
            class="flexBox"
        >
            <div class="formItemBox">
                <el-form-item label="账户名称:" prop="userName">
                    {{form.userName}}
                </el-form-item>
                <el-form-item label="可创建子账户数量:" prop="numCreateUser">
                    <el-input
                        type="number"
                        placeholder="请输入"
                        maxlength="10"
                        v-autoTrim="{ obj: form, key: 'numCreateUser' }"
                        v-model="form.numCreateUser"
                    >
                    </el-input>
                </el-form-item>
                <el-form-item label="最多可创建场景测试包数量:" prop="numCreateScenePackage">
                    <el-input
                        type="number"
                        placeholder="请输入"
                        maxlength="10"
                        v-autoTrim="{ obj: form, key: 'numCreateScenePackage' }"
                        v-model="form.numCreateScenePackage"
                    >
                    </el-input>
                </el-form-item>
                <el-form-item label="场景数据包的最大场景数量:" prop="numScenePerPackage">
                    <el-input
                        type="number"
                        placeholder="请输入"
                        maxlength="10"
                        v-autoTrim="{ obj: form, key: 'numScenePerPackage' }"
                        v-model="form.numScenePerPackage"
                    >
                    </el-input>
                </el-form-item>
            </div>

        </el-form>
        <div class="btns">
            <el-button type="primary" @click="save">保存</el-button>
            <el-button type="primary" plain @click="cancel">取消</el-button>
        </div>
    </div>
</template>

<script>
import tableList from "@/components/grid/TableList";

let maxCount = 0; // 用于校验
export default {
    name: "parameterDetail",
    components: {tableList},
    data() {
        return {
            form: {
                id:'',
                userId:'',
                userName:'111',
                numCreateUser: '',
                numCreateScenePackage: '',
                numScenePerPackage: '',
            },
            rules: {
                numCreateUser:  [
                    { required: true, message: "请输入", trigger: "blur" },
                    {
                        validator: (rule, value, callback) => {
                            if(this.$validateInteger(value)){
                                callback()
                            }else{
                                callback(new Error('格式错误'))
                            }
                        },
                        trigger: "blur"
                    },
                ],
                numCreateScenePackage:  [
                    { required: true, message: "请输入", trigger: "blur" },
                    {
                        validator: (rule, value, callback) => {
                            if(this.$validateInteger(value)){
                                callback()
                            }else{
                                callback(new Error('格式错误'))
                            }
                        },
                        trigger: "blur"
                    }
                ],
                numScenePerPackage:  [
                    { required: true, message: "请输入", trigger: "blur" },
                    {
                        validator: (rule, value, callback) => {
                            if(this.$validateInteger(value)){
                                callback()
                            }else{
                                callback(new Error('格式错误'))
                            }
                        },
                        trigger: "blur"
                    },
                    {
                        validator: (rule, value, callback) => {
                            if(Number(value)<=10000){
                                callback()
                            }else{
                                callback(new Error('超出最大值'))
                            }
                        },
                        trigger: "blur"
                    },
                ],
            }
        };
    },
    computed: {},
    async created(){
        if(this.$route.query){
            this.form = {...this.$route.query}
            delete this.form.modifyTime
        }
        /*获取修改历史
        this.$axios({
            method:'POST',
            url:this.$api.systemManagement.getParamHistory,
            data:{
                userId: this.$route.query.userId
            }
        })
        */
    },
    methods: {
        save(){
            this.$refs.form.validate(valid=>{
                if(valid){
                    this.$axios({
                        method:'POST',
                        url:this.$api.systemManagement.saveParameter,
                        data:{
                            ...this.form
                        }
                    }).then(res => {
                        if(res.code == 200){
                            this.$message.success("保存成功");
                            this.cancel()    
                        }else{
                            this.$message.error(res.message || "保存失败");
                        }
                    }) 
                }
            })
        },
        cancel(){
            this.$router.replace({
                path: '/parameterManagement'
            })
        },
    },
};
</script>

<style lang="less" scoped>
.el-form {
    width: 60%;
    min-width: 900px;
    padding-top: 60px;
    margin: 0 auto;

    .formItemBox {
        flex: 1;

        /deep/ .el-input,
        .el-select {
            width: 100%;
        }
    }

    .el-textarea {
        height: 96px;
    }
}

.btns {
    padding-top: 30px;
    text-align: center;
}
.title {
    width: 60%;
    min-width: 900px;
    margin: 4px auto;
    border-left: 6px solid @themeColor;
    padding-left: 20px;
    color: @themeColor;
    font-size: 16px;
    font-weight: bold;
}
/deep/ input::-webkit-outer-spin-button,
/deep/ input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/ input[type='number'] {
  -moz-appearance: textfield !important;
}
</style>