<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-select filled v-model="msg.MainId" use-input :dense="false" ref="Teacher_Id" label="筛选问卷" option-value="Id"
            option-label="Title" :options="ServeyMainList" @input="refreshPage()" class="col-3 q-pb-lg" emit-value
            map-options>
          </q-select>
        </div>
        <div class="col-3">
          <q-select filled v-model="msg.TeacherId" use-input :dense="false" ref="Teacher_Id" label="选择评价的老师"
            option-value="TId" option-label="TeacherName" :options="TeacherList" @filter="filterFnTeacher"
            @input="refreshPage()" class="col-3 q-pb-lg" emit-value map-options>
            <template v-slot:no-option>
              <q-item>
                <q-item-section class="text-grey">
                  No results
                </q-item-section>
              </q-item>
            </template>
          </q-select>
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-tow-column-table"
        separator="none" :data="data" :columns="columns" row-key="name">
        <template v-slot:top1>
          <div class="col-2 q-table__title">老师问卷调查汇总</div>
          <q-space />
        </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="详情"
              @click="editSurvey(props.row)" />
          </q-td>
        </template>
      </q-table>
      <area-form v-if="isShowAreaForm" :save-obj="areaObjOption" @close="refreshPage" @success="refreshPage">
      </area-form>
    </div>
  </div>
</template>
<script>
  import {
    queryStudentSurveyPage,
    queryEducationSurveyMainList
  } from '../../api/common/common'
  import {
    getTeacherListByGroupId
  } from '../../api/school/index'
  import areaForm from '../../components/system/surveyStudentList-form'
  export default {
    meta: {
      title: "老师上课质量调查问卷"
    },
    components: {
      areaForm,
    },
    data() {
      return {
        currentUrl: "",
        columns: [{
            name: 'Title',
            label: '问卷名称',
            field: 'Title',
            align: 'left'
          },
          {
            name: 'TeacherName',
            label: '老师',
            field: 'TeacherName',
            align: 'left'
          },
          {
            name: 'StudentName',
            label: '学生',
            field: 'StudentName',
            align: 'left'
          },
          {
            name: 'CreateDate',
            label: '时间',
            field: 'CreateDate',
            align: 'left'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'MenuId'
          }
        ],
        data: [],
        TeacherList: [], //关联教师下拉数据 
        AllTeacherList: [], //关联教师下拉数据 
        loading: true,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          TeacherId: -1,
          StudentId: -1,
          MainId: "",
        },
        pageCount: 0,
        isShowAreaForm: false, //是否显示新增修改地区表单
        areaObjOption: null,
        ServeyMainList: [], //问卷列表
      }
    },
    mounted() {
      this.currentUrl = this.$route.path;
      this.getServeyMainList();
      this.GetTeacherList();
      this.getSurveypage();
    },
    methods: {
      getServeyMainList() {
        queryEducationSurveyMainList({}).then(res => {
          this.ServeyMainList = res.Data;
        })
      },
      //获取教师下拉
      GetTeacherList() {
        getTeacherListByGroupId(this.msg).then(res => {
          if (res.Code == 1) {
            this.TeacherList = res.Data;
            var obj = {
              TeacherName: '请选择',
              TId: -1
            }
            this.TeacherList.unshift(obj);
            this.AllTeacherList = this.TeacherList;
          }
        })
      },
      filterFnTeacher(val, update) {
        update(() => {
          if (val === "") {
            this.TeacherList = JSON.parse(JSON.stringify(this.AllTeacherList));
          } else {
            const needle = val.toLowerCase();
            this.TeacherList = this.AllTeacherList.filter(
              (v) => v.TeacherName.toLowerCase().indexOf(needle) > -1
            );
          }
        });
      },
      //刷新页面
      refreshPage() {
        this.isShowAreaForm = false;
        this.areaObjOption = null;
        this.getSurveypage();
      },
      //新增修改学生调查
      editSurvey(obj) {
        if (obj != null) {
          this.areaObjOption = obj;
        }
        this.isShowAreaForm = true;
      },
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getSurveypage();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getSurveypage()
      },
      //获取地区分页列表
      getSurveypage() {
        this.loading = true;
        queryStudentSurveyPage(this.msg).then(res => {
          this.loading = false
          this.data = res.Data.PageData
          this.pageCount = res.Data.PageCount
        }).catch(() => {
          this.loading = false
        })
      },
    }
  }

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

</style>
