<template>
    <div class="context">
        <div class="panel">
            <h5>{{pageTitle}}</h5>
        </div>
        <div class="panel-body">
            <div class="panel_control">
                <el-row :gutter="20">
                    <el-col :span="9">
                        <em>课程表模板名称:</em>
                        <el-input v-model="panel.name" placeholder="请输入课程表模板名称"></el-input>
                    </el-col>
                </el-row>
            </div>
        </div>
        <br>
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            <el-tab-pane label="星期一" name="Monday"></el-tab-pane>
            <el-tab-pane label="星期二" name="Tuesday"></el-tab-pane>
            <el-tab-pane label="星期三" name="Wednesday"></el-tab-pane>
            <el-tab-pane label="星期四" name="Thursday"></el-tab-pane>
            <el-tab-pane label="星期五" name="Friday"></el-tab-pane>
            <el-tab-pane label="星期六" name="Saturday"></el-tab-pane>
            <el-tab-pane label="星期天" name="Sunday"></el-tab-pane>
        </el-tabs>
        <el-button class="seeTemp">预览模板</el-button>
        <div class="table">
            <el-table
                    :data="tableData"
                    border
                    is-horizontal-resize
                    :default-sort="{prop: 'date', order: 'descending'}"
                    element-loading-background="rgba(0, 0, 0, 0.8)"
                    class=""
                    @selection-change="handleSelectionChange"                                   @current-change="clickChange"
>
            >
                <el-table-column
                        prop="timeScope"
                        label="时间"
                        width="260px"
                        align="center"
                >
                    <template slot-scope="scope">
                        <el-time-picker
                                is-range
                                v-model="scope.row.timeScope"
                                range-separator="至"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                                placeholder="选择时间范围">
                        </el-time-picker>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="课程"
                        align="center"
                >
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.vipType">
                            <el-option
                                    v-for="item in panel.options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Recovered"
                        label="预约名额"
                        align="center"
                >
                    <template slot-scope="scope">
                        <el-input-number v-model="scope.row.Recovered" :min="1" :max="9999" label=""></el-input-number>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Recovered"
                        label="消耗课时"
                        align="center"
                >
                    <template slot-scope="scope">
                        <el-input-number v-model="scope.row.Recovered" :min="1" :max="9999" label=""></el-input-number>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="Status"
                        label="操作"
                        width="100px"
                        align="center"
                >
                    <template slot-scope="scope">
                        <el-button type="text" class="red">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="rowBottom">
                <el-button type="primary">新增课表</el-button>
                <el-button type="primary">提交</el-button>
            </div>
        </div>
        <br>
        <div v-show="true">
            <el-pagination :total="pageination.total" :page-size="pageination.pageItem"
                           @current-change="pageChange"></el-pagination>
        </div>


        <el-dialog title="增删课程会员" :visible.sync="dialogVisible">
            <div class="dialogTitle">
                <span>基础功能</span>
            </div>
            <div>
                <el-transfer filterable v-model="dialogValue" :data="dialogdata"></el-transfer>
            </div>
            <div class="dialogFooter">
                <el-button type="primary" size="small">确定</el-button>
                <el-button @click="dialogVisible = false" size="small">取消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import Global from '../Global.js'
    import {
        testTable,
        testTableLong,
        testSelect
    } from "../api/getApiRes";

    let qs = require('qs');
    export default {
        data() {
            return {
                pageTitle: '新增课程表模板',
                dialogVisible: false,
                dialogdata: [],
                dialogValue: [],
                temId: '',
                activeName: 'Monday',
                tableData: [],
                // panel 配置项目
                panel: {
                    usercode: '',
                    username: '',
                    compname: '',
                    keyword: '',
                    USERCODE: '',
                    taskstatus: 99,
                    draw: 1,
                    start: 0,
                    recordsTotal: 0,
                    tableData: [],
                    allTableData: [],
                    limit: '10',
                    multipleSort: false,
                    loading: false,
                    fileList: [],
                    multipleSelection: [],
                    detectedmac: '',
                    options: [
                        {value: 99, label: '全部'},
                        {value: 1, label: '进行中'},
                        {value: 2, label: '已完成'},
                    ],
                    time1: globalBt(),
                },
                multipleSelection: [],
                pageination: {
                    pageItem: 7,
                    pageoptions: pageOptions(),
                    total: 70,
                    pageIndex: 1,
                },
            }
        },
        mounted() {
            this.getTableQuery();
        },
        methods: {
            handleClick() {
            },
            changeWechat(e, row) {
                // todo
                this.$message.success('当前用户微信已可见');
            },
            // 增删会员课程
            lessonStudenChange() {
                this.dialogVisible = true
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 页面数据查询
            getTableQuery() {
                let that = this;
                that.loading = true;
                let param = {
                    token: localStorage.token,
                    supregionid: 0,//
                };
                let postdata = qs.stringify(param);
                testTableLong(postdata).then(res => {
                    let json = res;
                    if (json.Code == 0) {
                        that.loading = false;
                        if (json.Rs) {
                            that.allTableData = json.Rs;
                            that.recordsTotal = json.Rs.length;
                        } else {
                            that.allTableData = [];
                            that.recordsTotal = 0;
                        }

                        // 设置分页数据
                        that.setPaginations();

                    } else {
                        that.$message.error(json.Memo);
                    }
                })
            },
            // 设置分页数据
            setPaginations() {
                // 分页属性
                let that = this;
                that.pageination.total = that.recordsTotal;
                // 默认分页
                that.tableData = that.allTableData.filter((item, index) => {
                    return index < that.pageination.pageItem;
                });
            },
            // 每页显示数量
            handleSizeChange() {
                let that = this;
                that.tableData = that.allTableData.filter((item, index) => {
                    return index < that.pageination.pageItem;
                });
                that.draw = that.pageination.pageItem;
                that.getTableQuery();
            },
            // 翻页
            pageChange(pageIndex) {
                let that = this;
                // 获取当前页
                let index = that.pageination.pageItem * (pageIndex - 1);
                // 数据总数
                let nums = that.pageination.pageItem * pageIndex;
                // 容器
                let tables = [];
                for (var i = index; i < nums; i++) {
                    if (that.allTableData[i]) {
                        tables.push(that.allTableData[i])
                    }
                    this.tableData = tables;
                }
                that.start = index * that.draw;
            },
            // 自动排序
            sortChange(params) {
                console.log(params)
            },
            // 过滤时间
            filterFmtDate(value, row, column) {
                let that = this;
                return nonTfmtDate(column, 11);
            },
        },
        watch: {
            $route() {
                this.temId = this.$route.query.id
            },
            temId(e) {
                if (parseInt(e) == 0) {
                    this.pageTitle = '新增课程表模板'
                } else {
                    this.pageTitle = '编辑课程表模板'
                }
            },
            activeName(e) {
                switch (e) {
                    case "Monday":
                        this.pageChange(1);
                        break;
                    case "Tuesday":
                        this.pageChange(2);
                        break;
                    case "Wednesday":
                        this.pageChange(3);
                        break;
                    case "Thursday":
                        this.pageChange(4);
                        break;
                    case "Friday":
                        this.pageChange(5);
                        break;
                    case "Saturday":
                        this.pageChange(6);
                        break;
                    case "Sunday":
                        this.pageChange(7);
                        break;
                }
            }
        },
    }
</script>

<style scoped>
    @import "../assets/css/panel.css";

    em {
        font-style: normal;
    }

    .context {   height: 770px;
         overflow-y: scroll;

        display: block;
        margin: 0 auto;
        background-color: #fff !important;
        padding: 30px;
    }

    .panel-body {
        padding: 20px;
        background: #F0F2F5;
    }

    .change {
        width: 100%;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .change button {
        float: left;
    }

    .change button.pull-right {
        float: right;
    }

    .dialogTitle {
        width: 100%;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        color: #000000;
        font-size: 18px;
        text-align: center;
    }

    .dialogTitle span {
        width: 169px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        color: #fff;
        background: #3799FF;
        border-radius: 250px;
        font-size: 18px;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        margin-bottom: 30px;
    }

    .dialogTitle em {
        float: none;
        font-style: normal;
        color: #3799FF;
        margin: 0;
    }

    /deep/ .el-transfer-panel__item .el-checkbox__input {
        left: 40px;
    }

    .dialogFooter {
        width: 90%;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        margin-top: 10px;
    }

    .dialogFooter button {
        float: right;
        margin-left: 10px;
    }

    /deep/ .panel_control .el-input {
        width: 200px;
        float: left;
    }

    .panel_control em {
        float: left;
        font-size: 14px;
        color: #545454;
        line-height: 45px;
        margin-right: 10px;
    }

    .seeTemp {
        position: relative;
        float: right;
        bottom: 60px;
    }

    .table {
        position: relative;
        top: -50px;
    }

    .el-range-editor.el-input__inner {
        width: 220px;
        padding: 3px 6px;
    }

    .rowBottom {
        width: 100%;
        overflow: hidden;
        display: block;
        margin: 0 auto;
        margin-top: 10px;
    }

    .rowBottom button {
        float: left;
        margin-right: 10px;
    }
</style>
