<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card shadow="hover" class="mgb20">
                    <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>                
                </el-card>

                <el-card shadow="hover" class="mgb20">
                    <div class="flex-center mgb20 user_header">
                        <p class="addhr_tag"></p>
                        <span>代理配置</span>
                    </div>

                    <div class="flex-between">
                        <span>内网地址配置</span>
                        <div class="border_lf flex-column">
                            <p class="marb30">平台服务</p>
                            <div class="flex-center">
                                <label>IP</label>
                                <el-input placeholder="请输入IP地址" class="mar_input"></el-input>
                                <label>端口</label>
                                <el-input placeholder="请输入端口号"></el-input>
                            </div>
                        </div>
                        <div class="border_lf pad_none flex-column">
                            <p class="marb30">流媒体服务</p>
                            <div class="flex-center">
                                <label>IP</label>
                                <el-input placeholder="请输入IP地址" class="mar_input"></el-input>
                                <label>端口</label>
                                <el-input placeholder="请输入端口号"></el-input>
                            </div>
                        </div>
                    </div>
                </el-card>

                <el-card shadow="hover" class="mgb20">
                    <div class="flex-center mgb20">
                        <p class="addhr_tag"></p>
                        <span>应用列表</span>
                    </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 prop="storeName" label="使用期限" align="center">
                        </el-table-column>
                        <el-table-column prop="total" label="启用时间" align="center">
                        </el-table-column>
                        <el-table-column prop="payamount" label="结束时间" align="center">
                        </el-table-column>
                        <el-table-column prop="payamount" label="剩余时间" align="center">
                        </el-table-column>
                        <el-table-column label="IP" align="center">
                            <template slot-scope="scope">
                                <div class="tab_temp" v-if="scope.row.Intranet != ''">
                                    <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" v-if="scope.row.Intranet != ''">
                                    <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>
                                <div v-else>
                                   <el-button type="plain" @click="chooseIp">选择IP与端口</el-button> 
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-switch
                                    v-model="scope.row.swtich"
                                    active-text="开启"
                                    inactive-text="关闭"
                                    @change="changeSwitch(scope.row)">
                                </el-switch>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination">
                        <el-pagination background layout="total, prev, pager, next" :total="totals">
                        </el-pagination>
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <!-- 选择IP -->
        <el-dialog :visible.sync="ipVisible" width="70%" center>
            <div class="flex-center mgb20">
                <p class="hr_tag"></p>
                <span>客户列表</span>
            </div>
            <el-table :data="permissionData" class="table" stripe header-align="center">
                <el-table-column type="index" width="100" 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="teacherVisible = false">取 消</el-button>
                <el-button type="primary" @click="editSure('teacherForm')">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data (){
            return {
                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',
                    payamount: '700d12h1min',
                    swtich: true,
                    Intranet: '',
                    extranet: ''
                }],
                totals: 1,
                ipVisible: false
            }
        },
        methods: {
            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>