<template>
    <div class="order">
        <header>支付列表
            <van-dropdown-menu>
                <van-dropdown-item @change="onChange" v-model="voicyPart" :options="voicyPartList" />
            </van-dropdown-menu>
        </header>
        <h2>{{schoolName}}</h2>
        <van-tabs>
            <van-tab title="缴费信息">
                <div class="orderList">
                    <div class="table">
                        <div class="title">
                            <span></span>
                            <span>姓名</span>
                            <span>声部</span>
                            <span>支付金额</span>
                            <span>到账时间</span>
                        </div>
                        <div class="content">
                            <div v-for="(data, index) in dataList" :key="data.id">
                            <!-- <div> -->
                                <span> {{ ++index }} </span>
                                <span> {{ data.userName }} </span>
                                <span> {{ data.voicyPart }} </span>
                                <span> {{ data.amount }} </span>
                                <span> {{ data.payTime }} </span>
                            </div>
                            
                        </div>
                    </div>
                </div>
            </van-tab>
            <van-tab title="报名信息">
                <div class="table">
                    <div class="title">
                        <span></span>
                        <span>姓名</span>
                        <span>班级</span>
                        <span>声部</span>
                        <span>备注</span>
                        <span>调剂</span>
                    </div>
                    <div class="content">
                        <div v-for="(data, index) in studentList" :key="data.id">
                        <!-- <div> -->
                            <span> {{ ++index }} </span>
                            <span> {{ data.name }} </span>
                            <span> {{ data.grade + data.gClass }} </span>
                            <span> {{ data.subName ? data.subName.split('.').reverse()[0] : data.subName }} </span>
                            <span> {{ data.remark }} </span>
                            <span> <van-button 
                                    :disabled="data.pushStatus <= 1 && data.status == 0 ? false : true" 
                                    round 
                                    @click = "adjust(data)"
                                    type = "danger" 
                                    size = "small">调剂</van-button> 
                            </span>
                        </div>
                    </div>
                </div>
                <van-action-sheet
                    v-model="adjustStatus"
                    :actions="couresList"
                    cancel-text="取消"
                    @cancel="adjustStatus = false"
                    @select="adjustSelect" />
            </van-tab>
        </van-tabs>
    </div>
</template>

<script>
import qs from 'qs'
export default {
    name: 'order',
    data() {
        return {
            classId: this.$route.query.classId,
            schoolName: this.$route.query.schoolName,
            dataList: {}, // 订单列表
            studentList: {}, // 学生列表
            couresList: [], // 课程列表
            voicyPart: 0,
            voicyPartList: [{
                text: '全部声部',
                value: 0
            }],
            adjustStatus: false, //
            changeStudent: null, // 修改的学生对象
        }
    },
    mounted() {
        // 获取所有课程
        this.$axios.post('/user/getCourses ', qs.stringify({
            clazzId: this.classId
        })).then(c => {
            let result = c.data.data
            result.forEach(r => {
                this.couresList.push({
                    name: r.subName.split('.').reverse()[0],
                    subId: r.subId,
                    id: r.id
                })

                this.voicyPartList.push({
                    text: r.subName.split('.').reverse()[0],
                    value: r.subId
                })
            })
        })
        
        // 获取订单信息
        this.getOrderList()
        // 获取学生列表信息
        this.getStudents()
    },
    methods: {
        getOrderList(voicyPart) {
            // 获取订单信息
            this.$axios.post('/order/checkOrderList', qs.stringify({
                classId: this.classId,
                voicyPart: voicyPart ? voicyPart : '',
                type: 1
            })).then(r => {
                this.dataList = r.data.data
            })
        },
        getStudents(item) {
            if(!item) {
                item = {}
            }
            this.$axios.post('/user/getMusicTeamStu', qs.stringify({
                musicTeamId: this.classId, // 乐团Id
                name: '', // 学生姓名
                status: '', // 学生状态
                subId: item.subId ? item.subId : '', // 声部编号
                page: item.page ? item.page : 1, //默认1第一页
                rows: item.rows ? item.rows : 9999 // 默认20条数据
            })).then(r => {
                this.studentList = r.data.data.rows
            })
        },
        adjustSelect(item) {
            this.$axios.post('/user/updateUserSub', qs.stringify({
                courseId: item.id,
                subId: item.subId,
                userId: this.changeStudent.id
            })).then(student => {
                if(student.data.code == 200) {
                    this.$toast(student.data.msg)
                    this.changeStudent.subName = item.name
                    this.adjustStatus = false
                }
            })
        },
        adjust(item) {
            // 开始调剂
            if(item.pushStatus <= 1 && item.status == 0) {
                this.adjustStatus = true
                this.changeStudent = item
            }
        },
        onChange(value) {
            // 切换声部时
            let subId = value ? value : ''
            this.getStudents({ subId: subId })
            this.voicyPartList.forEach(vp => {
                if(vp.value == value) {
                    // 如果选择全部则传空
                    let text = value ? vp.text : ''
                    this.getOrderList(text)
                }
            })
            
        }
    }
}
</script>

<style lang="less" scoped>
.order {
    background: #fff;
    min-height: 100vh;
}
header {
    height: .40rem;
    line-height: .40rem;
    color: #000;
    font-size: .17rem;
    background: #fff;
    box-shadow: 0px 1px 8px 0px rgba(0,0,0,0.07);
    text-align: center;
}
h2 {
    font-size: .16rem;
    color: #fff;
    padding: .1rem 0;
    text-align: center;
    background: #14928a;
}


.table {
    .title {
        display: flex;
        align-items: center;
        text-align: center;
        border-bottom: 1px solid #eaeaea;
    }

    span {
        flex: 1;
        padding: .08rem 0;
        font-size: .14rem;
        &:first-child {
            width: .3rem;
            flex: inherit;
        }
    }

    .content > div{
        // border: 1px solid #ccc;
        // border-left: 0;
        // border-right: 0;
        width: 100%;
        display: flex;
        align-items: center;
        text-align: center;
        &:nth-child(2n+2) {
            background: #eaeaea;
        }

    }
}
/deep/.van-dropdown-menu {
    height: .4rem;
    position: absolute;
    right: .15rem;
    top: 0;
}
</style>