<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card shadow="hover" class="mgb20">
                    <div class="flex-between">
                        <div class="per_title" v-preventReClick @click="goback()">
                            <i class="el-icon-arrow-left"></i>
                            <span class="per_back">返回</span>
                            <span class="per_school">系统服务器地址配置</span>
                        </div>
                        <div>
                            <el-button type="primary" round class="mag" v-preventReClick @click="saveAdd('form')">确定</el-button>
                        </div>
                    </div>              
                </el-card>

                <el-card shadow="hover" class="mgb20">
                    <div class="flex-center mgb20 user_header">
                        <p class="addhr_tag"></p>
                        <span>系统信息</span>
                    </div>

                    <div>
                        <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="flex-end-around">
                            <el-col :span="6">
                                <el-form-item prop="systemName" label="系统名称">
                                    <el-input v-model="form.systemName" placeholder="请输入系统名称"></el-input>
                                </el-form-item>

                                <el-form-item prop="systemType" label="系统类型">
                                    <el-select v-model="form.systemType" clearable placeholder="请选择系统类型">
                                        <el-option v-for="(item,index) in systemTypeList" :key="index" :label="item.name" :value="item.value"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>


                            <el-col :span="6" style="margin-left: 60px;">
                                <el-form-item prop="systemAttribution" label="系统归属">
                                    <el-select v-model="form.systemAttribution" clearable placeholder="请选择系统归属">
                                        <el-option v-for="(item,index) in systemList" :key="index" :label="item.name" :value="item.value"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-form>
                    </div>
                </el-card>

                <el-card shadow="hover" class="mgb20">
                    <div class="mgb20 flex-between">
                        <div class="flex-center">
                            <p class="addhr_tag"></p>
                            <span>地址列表</span>
                        </div>
                        <div>
                            <el-input placeholder="请输入系统名称" prefix-icon="el-icon-search" v-model="keyword" clearable></el-input>
                        </div>
                    </div>
                    <el-table :data="permissionData" class="table" stripe :span-method="SpanMethod" header-align="center">
                        <el-table-column prop="id" label="序号" align="center">
                        </el-table-column>
                        <el-table-column prop="age" label="服务器名称" align="center">
                        </el-table-column>
                        <el-table-column label="IP" align="center">
                            <template slot-scope="scope">
                                <div class="tab_temp">
                                    <div class="flex-center">
                                        <label>内网:</label>
                                        <el-input v-model="scope.row.Intranet" placeholder="请输入IP地址"></el-input>
                                    </div>
                                    <div class="flex-center mar10">
                                        <label>外网:</label>
                                        <el-input v-model="scope.row.extranet" placeholder="请输入端口号"></el-input>
                                    </div>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="端口" align="center">
                            <template slot-scope="scope">
                                <div class="tab_temp">
                                    <div class="flex-center">
                                        <label>内网:</label>
                                        <el-input v-model="scope.row.Intranet" placeholder="请输入内网IP地址"></el-input>
                                    </div>
                                    <div class="flex-center mar10">
                                        <label>外网:</label>
                                        <el-input v-model="scope.row.extranet" placeholder="请输入外网IP地址"></el-input>
                                    </div>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="storeName" label="后台" align="center">
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="text">编辑</el-button>
                                <el-button type="text">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination">
                        <el-pagination background layout="total, prev, pager, next" :total="pages">
                        </el-pagination>
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <!-- 选择IP -->
        <el-dialog :visible.sync="ipVisible" width="50%" center>
            <div class="flex-center mgb20">
                <p class="addhr_tag"></p>
                <span>客户列表</span>
            </div>
            <el-table :data="permissionData" class="table" stripe header-align="center">
                <el-table-column prop="id" label="序号" align="center">
                </el-table-column>
                <el-table-column prop="age" label="服务器名称" align="center">
                </el-table-column>
                <el-table-column label="IP" align="center">
                    <template slot-scope="scope">
                        <div class="tab_temp">
                            <div class="flex-center">
                                <label>内网:</label>
                                <el-input v-model="scope.row.Intranet" placeholder="请输入IP地址"></el-input>
                            </div>
                            <div class="flex-center mar10">
                                <label>外网:</label>
                                <el-input v-model="scope.row.extranet" placeholder="请输入端口号"></el-input>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="端口" align="center">
                    <template slot-scope="scope">
                        <div class="tab_temp">
                            <div class="flex-center">
                                <label>内网:</label>
                                <el-input v-model="scope.row.Intranet" placeholder="请输入内网IP地址"></el-input>
                            </div>
                            <div class="flex-center mar10">
                                <label>外网:</label>
                                <el-input v-model="scope.row.extranet" placeholder="请输入外网IP地址"></el-input>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="选择" align="center">
                    <template slot-scope="scope">
                        <i class="el-icon-success radio_icon"></i>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button @click="ipVisible = false">取 消</el-button>
                <el-button type="primary" @click="editSure('teacherForm')">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data (){
            return {
                form: {
                    systemName: '',
                    systemType: '',
                    systemAttribution: ''
                },
                rules: {
                    systemName:[
                        { required: true, message: '请输入系统名称', trigger: 'blur' }
                    ],
                    systemType:[
                        { required: true, message: '请选择系统类型', trigger: 'change' }
                    ],
                    systemAttribution:[
                        { required: true, message: '请选择系统归属', trigger: 'change' }
                    ] 
                },
                permissionData: [{
                    id: 1,
                    age: '小额贷系统',
                    storeName: '1个月',
                    total: '2019.01.02 11:00',
                    payamount: '2019.01.02 11:00',
                    payamount: '700d12h1min',
                    swtich: true,
                    Intranet: '10.20.202.1',
                    extranet: '10.20.202.1'
                },
                {
                    id: 2,
                    age: '小额贷系统',
                    storeName: '1个月',
                    total: '2019.01.02 11:00',
                    payamount: '2019.01.02 11:00',
                    swtich: true,
                    Intranet: '',
                    extranet: ''
                }],
                pages: 1,
                ipVisible: false,
                 educationDegreeList: [{
                    name: '研究生及以上',
                    value: 1
                }],
                systemList: [{
                    name: '外部产品',
                    value: 1
                },
                {
                    name: '内部系统',
                    value: 0
                }],
                systemTypeList: [{
                    name: '工具',
                    value: 1
                },
                {
                    name: '实训',
                    value: 2
                },
                {
                    name: '网站',
                    value: 3
                }],
                configId : this.$store.state.configId,
                keyword: ''
            }
        },
        mounted(){
            if(this.configId){
                this.getData()
            }
        },
        methods: {
            getData(){
                let data = {
                    systemId: this.configId
                }
                this.$get(this.api.queryServiceConfigDetails,data).then((res) => {
                        this.form = {
                            systemName: res.message[0].systemName,
                            systemType: res.message[0].systemType,
                            systemAttribution: res.message[0].systemAttribution,
                        }
                    }).catch((res) => {
                })
            },
            saveAdd(){
                let data = {
                    systemId: this.configId,
                    systemName: this.form.systemName,
                    systemType: this.form.systemType,
                    systemAttribution: this.form.systemAttribution,
                }
                if(this.configId){
                    this.$post(this.api.updateServiceConfig,data).then((res) => {
                            this.$message.success('编辑成功');
                            this.goback()
                        }).catch((res) => {
                    })
                }else{
                    this.$post(this.api.updateServiceConfig,data).then((res) => {
                            this.$message.success('添加成功');
                            this.goback()
                        }).catch((res) => {
                    })
                }
            },
            SpanMethod({ row, column, rowIndex, columnIndex }) {
                if (rowIndex % 2 === 0) {
                    if (columnIndex === 6) {
                        if(!row.Intranet){
                            return [1, 2];
                        }
                    } 
                    // else if (columnIndex === 1) {
                    //     return [0, 0];
                    // }
                }
            },
            chooseIp(){
                this.ipVisible = true
            },
            goback(){
                this.$router.go(-1)
            }
        }
    }
</script>

<style scoped>
.border_lf{
    border-left: 1px dashed #eee;
    padding: 0 60px;
}
.border_lf label{
    width: 120px;
}
.pad_none{
    padding: 0 0 0 60px;
}
.mar_input{
    margin-right: 80px;
}
.marb30{
    margin-bottom: 30px;
}
.tab_temp label{
    width: 60px;
}
.mar10{
    margin-top: 10px;
}
.radio_icon{
    font-size: 26px;
    color: #9278FF;
}
</style>