<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @change="getClassList" clearable standout="bg-primary text-white" v-model="msg.ClassName" label="班级名称"
            @clear="getClassList" />
        </div>
        <div class="col-3">
          <q-select @input="getClassList" standout="bg-primary text-white" option-value="Id" option-label="Name"
            v-model="msg.ClassStatus" :options="classStatusList" emit-value map-options label="课程状态" />
        </div>
        <div class="col-3">
          <q-input @change="getClassList" clearable standout="bg-primary text-white" v-model="msg.TeacherName" label="带班老师"
            @clear="getClassList" />
        </div>
        <div class="col-3">
          <q-input @change="getClassList" clearable standout="bg-primary text-white" v-model="msg.CourseName" label="学习课程"
            @clear="getClassList" />
        </div>
        <div class="col-3">
          <q-select @input="getClassList" standout="bg-primary text-white" option-value="SId" option-label="SName"
            v-model="msg.School_Id" :options="schoolList" emit-value map-options label="关联校区" />
        </div>
      </div>
      <div class="page-option">
        <q-btn color="accent" class="q-mr-md" icon="add" label="新增班级" @click="EditCourse(null)" />
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" title="班级信息" :data="data" :columns="columns" row-key="name">
        <template v-slot:body-cell-ClassName="props">
          <q-td auto-width :props="props">
            <q-avatar size="md" style="background:#d4dfff;color:#2961FE;font-weight:bold;" v-if="props.row.ClassName">
              {{GetFirst(props.row.ClassName)}}</q-avatar>
            <span style="color:#2961FE;margin-left:10px;cursor:pointer;" @click="getClassInfo(props.row)" title="点击查看详情">{{props.row.ClassName}}</span>
          </q-td>
        </template>
        <template v-slot:body-cell-TeacherName="props">
          <q-td auto-width :props="props">
            <span style="color:#3FC4FF;">{{props.row.TeacherName}}</span>
          </q-td>
        </template>
        <template v-slot:body-cell-ClassPersion="props">
          <q-td auto-width :props="props">
            <i class="iconfont icon-ren-" style="color:#2961FE;"></i>预招 <span
              style="color:#2961FE;">{{props.row.ClassPersion}} </span>
            <i class="iconfont icon-ren-" style="color:#3FC4FF;margin-left:30px;"></i>当前 <span
              style="color:#3FC4FF">{{props.row.OrderStudentCount}}</span>
            <q-linear-progress rounded size="20px"
              :value="getProgress(props.row.OrderStudentCount,props.row.ClassPersion)" style="background-color:#EEEEEF;color:#3FC4FF"
              class="q-mt-sm" />
          </q-td>
        </template>
        <template v-slot:body-cell-CompleteProgress="props">
          <q-td auto-width :props="props">
            已进行{{props.row.CompleteProgress}}%
            <q-linear-progress rounded size="20px" :value="getProgress(props.row.CompleteProgress,100)" style="background-color:#EEEEEF;color:#3FC4FF"
              class="q-mt-sm" />
          </q-td>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="订单中心"></q-btn>
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="收支明细"></q-btn>
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
              @click="EditCourse(props.row)" />
          </q-td>
        </template>
      </q-table>
      <class-form v-if="isShowClassForm" :save-obj="classObjOption" @close="closeClassSaveForm" @success="refreshPage">
      </class-form>
      <classinfo-form v-if="isShowClassInfo" :seting-obj="classObjOption" @close="closeClass" @success="refreshClass">
      </classinfo-form>
    </div>
  </div>
</template>
<script>
  import {
    queryClassPage,
    queryClassStatusList,
  } from '../../api/course/class';

  //获取校区列表
  import {
    getSchoolDropdown
  } from '../../api/school/index';
  import classForm from '../../components/course/class-form';
  import classinfoForm from '../../components/course/classinfo-form';
  export default {
    meta: {
      title: "班级管理"
    },
    components: {
      classForm,
      classinfoForm
    },
    data() {
      return {
        columns: [{
            name: 'ClassName',
            label: '班级名称',
            field: 'ClassName',
            align: 'left'
          },
          {
            name: 'SchoolName',
            label: '校区',
            field: 'SchoolName',
            align: 'left',
          },
          {
            name: 'CourseName',
            label: '课程',
            field: 'CourseName',
            align: 'left'
          },
          {
            name: 'TeacherName',
            label: '带班老师',
            field: 'TeacherName',
            align: 'left'
          },
          {
            name: 'ClassPersion',
            label: '招生/报名',
            field: 'ClassPersion',
            align: 'left'
          },
          {
            name: 'OpenTime',
            label: '开班时间',
            field: 'OpenTime',
            align: 'left'
          },
          {
            name: 'CompleteProgress',
            label: '课程进度',
            field: 'CompleteProgress',
            align: 'left'
          },
          {
            name: 'ClassStatusStr',
            label: '状态',
            align: 'left',
            field: 'ClassStatusStr'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'CourseId'
          }
        ],
        data: [],
        loading: false,
        isShowClassForm: false,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage:12,
          ClassName: '', //班级名称
          ClassStatus: 0, //班级状态
          TeacherName: '', //带班老师
          CourseName: '', //学习课程
          School_Id: 0, //关联校区  
        },
        //班级状态
        classStatusList: [],
        //关联校区列表
        schoolList: [],
        pageCount: 0,
        classObjOption: null,
        isShowClassInfo:false, //是否显示课程信息
      }
    },
    created() {
      this.getClassStatus();
      this.getSchool();
    },
    mounted() {
      this.getClassList();
    },
    methods: {
      //获取校区列表
      getSchool() {
        getSchoolDropdown({}).then(res => {
          if (res.Code == 1) {
            var tempArray = res.Data;
            if (!tempArray) {
              tempArray = [];
            }
            tempArray.unshift({
              SId: 0,
              SName: "不限"
            })
            this.schoolList = tempArray;
          }
        })
      },
      //获取班级状态列表
      getClassStatus() {
        queryClassStatusList({}).then(res => {
          if (res.Code == 1) {
            this.classStatusList = res.Data;
          }
        }).catch(() => {})
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getClassList()
      },
      //获取菜单分页列表
      getClassList() {
        this.loading = true;
        queryClassPage(this.msg).then(res => {
          this.loading = false;
          this.data = res.Data.PageData;
          this.pageCount = res.Data.PageCount;
        }).catch(() => {
          this.loading = false
        })
      },
      //刷新页面
      refreshPage() {
        this.isShowClassForm = false;
        this.getClassList();
      },
      //新增修改菜单
      EditCourse(obj) {
        if (obj) {
          this.classObjOption = obj
        } else {
          this.classObjOption = null
        }
        this.isShowClassForm = true
      },
      //关闭弹窗
      closeClassSaveForm() {
        this.isShowClassForm = false
      },
      GetFirst(val) {
        if (val) {
          return val.substr(0, 1);
        }
      },
      //获取进度条
      getProgress(num, total) {
        if (num == 0 || total == 0){
            return 0;
        }
        return (Math.round(num / total * 100) / 100.00);
      },
      //关闭班级信息弹窗
      closeClass(){
        this.isShowClassInfo = false
      },
      //刷新
      refreshClass(){

      },
      //点击班级名称
      getClassInfo(obj){
        this.classObjOption=obj;
        this.isShowClassInfo=true;
      }
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass');

</style>
