<template>
    <div class="basic-param-config">
        <el-scrollbar class="editScroll">
            <el-form
                class="param-config-form"
                ref="publicForm"
                :model="publicForm"
                label-width="180px"
                label-suffix=":"
                :rules="pubRules"
            >
                <!-- <h3>常规参数配置</h3> -->
                <el-divider content-position="left">常规参数配置</el-divider>
                <el-row :gutter="10">
                    <el-col :span="6">
                        <el-form-item label="程序端口" prop="serverPort">
                            <el-input
                                disabled
                                v-model.number="publicForm.serverPort"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="风场标识" prop="windFarmId">
                            <el-input
                                v-model="publicForm.windFarmId"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="9">
                        <el-form-item label="系统标识" prop="systemName">
                            <el-input
                                v-model="publicForm.systemName"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item label="日志配置路径" prop="logPath">
                            <el-input v-model="publicForm.logPath"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="临时文件存放目录"
                            prop="localTmpFilePath"
                        >
                            <el-input
                                v-model="publicForm.localTmpFilePath"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item
                            label="压缩文件存放目录"
                            prop="localZipFilePath"
                        >
                            <el-input
                                v-model="publicForm.localZipFilePath"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="错误文件存放目录"
                            prop="errorFilePath"
                        >
                            <el-input
                                v-model="publicForm.errorFilePath"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="10">
                    <!-- 文件压缩 -->
                    <el-col :span="6">
                        <el-form-item
                            label="是否开启数据压缩"
                            prop="dataZipOpen"
                        >
                            <el-switch
                                v-model="publicForm.dataZipOpen"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                            >
                            </el-switch>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="false">
                        <el-form-item
                            label="本地文件压缩周期（天）"
                            prop="fileZipCron"
                        >
                            <el-input
                                v-model.number="publicForm.fileZipCron"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="10">
                    <el-col :span="6">
                        <el-form-item
                            label="是否开启数据清除"
                            prop="fileDeleteOpen"
                        >
                            <el-switch
                                v-model="publicForm.fileDeleteOpen"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                            >
                            </el-switch>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="publicForm.fileDeleteOpen">
                        <el-form-item
                            label="数据清除周期（天）"
                            prop="fileDeleteDay"
                        >
                            <el-input
                                v-model.number="publicForm.fileDeleteDay"
                            ></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12" v-if="publicForm.fileDeleteOpen">
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="多个目录时,用英文逗号分隔"
                            placement="top-end"
                        >
                            <el-form-item
                                label="数据清除文件目录"
                                prop="fileDeletePath"
                            >
                                <el-input
                                    v-model="publicForm.fileDeletePath"
                                ></el-input>
                            </el-form-item>
                        </el-tooltip>
                    </el-col>
                </el-row>
                <!-- <h3>采集数据参数配置</h3> -->
                <el-divider content-position="left"
                    >采集数据参数配置</el-divider
                >
                <!-- scada采集参数设置 -->
                <el-row :gutter="10">
                    <el-col :span="6">
                        <el-form-item
                            label="是否开启scada采集"
                            prop="scadaCollectOpen"
                        >
                            <el-switch
                                v-model="publicForm.scadaCollectOpen"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                            >
                            </el-switch>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="publicForm.scadaCollectOpen">
                        <el-form-item
                            label="是否开启scada本地存储"
                            prop="scadaStorageOpen"
                        >
                            <el-switch
                                v-model="publicForm.scadaStorageOpen"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                            >
                            </el-switch>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="publicForm.scadaCollectOpen">
                        <el-form-item
                            label="scada数据keys刷新配置"
                            prop="scadaKeysCron"
                        >
                            <el-input
                                v-model="publicForm.scadaKeysCron"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- cms采集设置 -->
                <el-row :gutter="10">
                    <el-col :span="6">
                        <el-form-item
                            label="是否开启cms采集"
                            prop="cmsCollectOpen"
                        >
                            <el-switch
                                v-model="publicForm.cmsCollectOpen"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                            >
                            </el-switch>
                        </el-form-item>
                    </el-col>

                    <el-col :span="6" v-if="publicForm.cmsCollectOpen">
                        <el-form-item
                            label="是否开启cms本地存储"
                            prop="cmsStorageOpen"
                        >
                            <el-switch
                                v-model="publicForm.cmsStorageOpen"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                            >
                            </el-switch>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="publicForm.cmsCollectOpen">
                        <el-form-item
                            label="cms采集时间间隔（分）"
                            prop="cmsDataCron"
                        >
                            <el-input
                                disabled
                                v-model.number="publicForm.cmsDataCron"
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="publicForm.cmsCollectOpen">
                        <el-form-item
                            label="cms采集风场编号"
                            prop="cmsWindFarmId"
                        >
                            <el-input
                                v-model="publicForm.cmsWindFarmId"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="10" v-if="publicForm.cmsCollectOpen">
                    <el-col :span="12">
                        <el-form-item label="cms采集地址及端口" prop="cmsUrl">
                            <el-input v-model="publicForm.cmsUrl"></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="cms采集厂家名称" prop="cmsFactory">
                            <el-input
                                v-model="publicForm.cmsFactory"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="10" v-if="publicForm.cmsCollectOpen">
                    <el-col :span="7">
                        <el-form-item
                            label="cms状态数据采集接口"
                            prop="cmsStateData"
                        >
                            <el-input
                                v-model="publicForm.cmsStateData"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item
                            label="cms状态数据类型标志"
                            prop="cmsStateType"
                        >
                            <el-input
                                v-model.number="publicForm.cmsStateType"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="cms状态数据指令类型"
                            prop="cmsStateCmd"
                        >
                            <el-input v-model="publicForm.cmsStateCmd">
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="10" v-if="publicForm.cmsCollectOpen">
                    <el-col :span="7">
                        <el-form-item
                            label="cms实时数据采集接口"
                            prop="cmsCurrentTimeData"
                        >
                            <el-input
                                v-model="publicForm.cmsCurrentTimeData"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item
                            label="cms实时数据类型标志"
                            prop="cmsDataType"
                        >
                            <el-input
                                v-model.number="publicForm.cmsDataType"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item
                            label="cms实时数据指令类型"
                            prop="cmsDataCmd"
                        >
                            <el-input v-model="publicForm.cmsDataCmd">
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- <h3>指令透传参数配置</h3> -->
                <el-divider content-position="left"
                    >指令透传参数配置</el-divider
                >
                <el-row :gutter="10">
                    <el-col :span="7">
                        <el-form-item
                            label="风场平台地址及端口号"
                            prop="fanHost"
                        >
                            <el-input v-model="publicForm.fanHost"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item label="风场登录用户名称" prop="fanName">
                            <el-input
                                v-model="publicForm.fanName"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item
                            label="风场登录用户密码"
                            prop="fanPassword"
                        >
                            <el-input v-model="publicForm.fanPassword">
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- public参数提交 -->
                <el-row :gutter="10" style="margin: 40px 0 20px">
                    <el-col :span="5">
                        <el-form-item></el-form-item>
                    </el-col>
                    <el-col :span="14" style="text-align: center">
                        <!-- <el-button type="info" @click="getPubParams"
                                >获取参数</el-button
                            > -->
                        <el-button
                            type="primary"
                            @click="submitPubForm('publicForm')"
                            >修改参数</el-button
                        >
                        <el-button type="warning" @click="activConfigParams"
                            >激活参数</el-button
                        >
                        <!-- <el-button
                                type="danger"
                                @click="resetPubForm('publicForm')"
                                >重置参数</el-button
                            > -->
                    </el-col>
                </el-row>
            </el-form>
        </el-scrollbar>
    </div>
</template>

<script>
export default {
    name: 'BasicParamConfig',
    data() {
        return {
            publicForm: {
                cmsCollectOpen: true,
                cmsCurrentTimeData: '',
                cmsDataCmd: '',
                cmsDataCron: 5,
                cmsDataType: '',
                cmsFactory: '',
                cmsStateCmd: '',
                cmsStateData: '',
                cmsStateType: '',
                cmsStorageOpen: '',
                cmsUrl: '',
                cmsWindFarmId: '',
                dataZipOpen: true,
                errorFilePath: '',
                fanHost: '',
                fanName: '',
                fanPassword: '',
                fileDeleteDay: '',
                fileDeleteOpen: true,
                fileDeletePath: '',
                fileZipCron: '',
                localTmpFilePath: '',
                localZipFilePath: '',
                logPath: '',
                scadaCollectOpen: true,
                scadaStorageOpen: true,
                scadaKeysCron: '',
                serverPort: '',
                systemName: '',
                windFarmId: '',
            },
            pubRules: {
                serverPort: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'change',
                    },
                    {
                        type: 'number',
                        message: '请填写数字值',
                    },
                ],
                windFarmId: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                systemName: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                logPath: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                localTmpFilePath: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                localZipFilePath: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                errorFilePath: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                fileZipCron: [
                    {
                        required: false,
                        message: '',
                        trigger: 'change',
                    },
                    {
                        type: 'number',
                        message: '请填写数字值',
                    },
                ],
                fileDeleteDay: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'change',
                    },
                    {
                        type: 'number',
                        message: '请填写数字值',
                    },
                ],
                fileDeletePath: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                // 提供
                fanHost: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                fanName: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                fanPassword: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                scadaKeysCron: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsDataCron: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                    {
                        type: 'number',
                        message: '请填写数字值',
                    },
                ],
                cmsCurrentTimeData: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsDataCmd: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsDataType: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsFactory: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsStateCmd: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsStateData: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsStateType: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsUrl: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
                cmsWindFarmId: [
                    {
                        required: true,
                        message: '必填',
                        trigger: 'blur',
                    },
                ],
            },
            baseUrl: window.context.Collection
        }
    },
    created() {
        this.getParams()
    },
    methods: {
        getParams() {
            this.$http
                .get(this.baseUrl + '/getSystemConfigParams')
                .then((res) => {
                    if (res.data.success) {
                        this.publicForm = res.data.data
                    }
                })
                .catch((err) => {
                    console.log(err)
                })
        },
        // public参数提交
        submitPubForm(pu) {
            this.$refs[pu].validate((valid) => {
                if (valid) {
                    this.$http
                        .post(
                            this.baseUrl +  '/editSysConfigParams',
                            this.publicForm
                        )
                        .then((res) => {
                            console.log(res, res.data)
                            if (res.data.success) {
                                this.$message.success('修改成功')
                                this.getParams()
                            }
                        })
                        .catch((err) => {
                            console.log(err)
                        })
                } else {
                    console.log('error submit!!')
                    return false
                }
            })
        },
        activConfigParams() {
            this.$http
                .post(this.baseUrl + '/activSysConfigParams')
                // .post('/collectConfig/activSysConfigParams', this.publicForm)
                .then((res) => {
                    console.log(res, res.data)
                    if (res.data.success) {
                        this.$message.success('激活成功');
                    }
                })
                .catch((err) => {
                    console.log(err)
                })
        },
    },
}
</script>

<style lang="scss" scoped>
.basic-param-config {
    width: 100%;
    height: 100%;
    .editScroll {
        height: 100% !important;
    }
    .param-config-form {
        width: calc(100% - 20px);
        margin: 0 auto;
        box-sizing: border-box;
    }
    h3 {
        font-size: 16px;
    }
    .el-row + .el-divider--horizontal {
        margin-top: 40px;
    }
    /deep/ .el-divider__text {
        font-size: 16px;
        font-weight: bold;
    }
}
</style>
<style>
.basic-param-config .el-scrollbar__wrap {
    overflow-x: hidden !important;
}
</style>