<template>
  <div class="app-container fixed-scroll-error">
    <el-form :model="queryParams" ref="queryForm" :inline="true" size="small" label-width="86px">
      <el-form-item label="学生姓名" prop="studentName">
        <el-input v-model="queryParams.studentName" clearable placeholder="请输入学生姓名"></el-input>
      </el-form-item>
      <el-form-item label="学生班级：" prop="classValue">
        <el-input v-model="queryParams.classValue" clearable placeholder="请输入学生班级"></el-input>
      </el-form-item>
      <el-form-item label="审批状态：" prop="state" label-width="105px">
        <el-select v-model="queryParams.state" placeholder="请选择审批状态">
          <el-option v-for="dict in dict.type.approval_status" :key="dict.value" :label="dict.label"
                     :value="dict.value">
            {{ dict.label }}
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="ml20">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="teacherLeaveList">
      <el-table-column type="index" width="55" label="序号" fixed="left" align="center"/>
      <el-table-column label="姓名" width="100" align="center" fixed="left" prop="studentName"/>
      <el-table-column label="班级" width="100" align="center" prop="className"/>
      <el-table-column label="请假开始时间" prop="startTime" align="center" min-width="180"/>
      <el-table-column label="请假结束时间" align="center" prop="endTime" min-width="180"/>
      <el-table-column label="请假类型" align="center" prop="type" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.biz_leave_type" :value="scope.row.type"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="请假原因" min-width="220" align="center" prop="leaveReason"
                       show-overflow-tooltip/>
      <el-table-column label="申请人" align="center" prop="applyUser" width="100"
                       show-overflow-tooltip/>
      <el-table-column label="申请时间" align="center" prop="applyTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" align="center" prop="state" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.approval_status" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="返校时间" align="center" prop="revokeTime" width="100"/>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width" min-width="120"
                       key="operate">
        <template slot-scope="scope">
          <el-button v-if="scope.row.taskName === '等待销假'" type="text" size="mini" icon="el-icon-edit"
                     @click="handleResolve(scope.row, false)">销假
          </el-button>
          <el-button v-else size="mini" type="text" icon="el-icon-search" @click="handleDetail(scope.row)">详情查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--    <ExPagination v-show="total > 0" :total="total" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum"-->
    <!--                  @pagination="getList"></ExPagination>-->

    <HandleResolve v-if="process.open" :process-open.sync="process.open" :instanceId="process.instanceId"
                   :id="process.id" :taskId="process.taskId" :readOnly="process.readOnly" :revoke="process.revoke"
                   @refreshData="refreshData"></HandleResolve>

    <el-dialog :title="title" :visible.sync="dialogTeacherLeave" width="1000px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px" style="width: 100%; margin: auto">
        <el-row>
          <el-col :span="11">
            <el-form-item label="姓名" prop="studentName">
              <el-input :value="form.studentName"/>
            </el-form-item>
          </el-col>
          <el-col :offset="2" :span="11">
            <el-form-item label="班级" prop="className">
              <el-input :value="form.className" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="请假开始时间" prop="startTime">
              <el-date-picker style="width: 100%" :value="form.startTime" type="datetime"
                              value-format="yyyy-MM-dd HH:mm" placeholder="选择开始时间"></el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :offset="2" :span="11">
            <el-form-item label="请假结束时间" prop="endTime">
              <el-date-picker style="width: 100%" :value="form.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm"
                              placeholder="选择结束时间"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="请假类型" prop="type">
              <el-select :value="form.type" style="width: 100%" placeholder="请选择请假类型">
                <el-option v-for="dict in dict.type.biz_leave_type" :key="dict.value" :label="dict.label"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="请假原因" prop="leaveReason">
          <el-input type="textarea" resize="none" :autosize="{ minRows: 5 }" :value="form.leaveReason"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {getlistStuLeave, getStuLeaveOne} from '@/api/smartSchool/classAdviser/stuLeaveView'
import HandleResolve from '@/views/smartSchool/classAdviser/studentLeaveView/HandleResolve'

export default {
  name: 'ClassAdviserStudentLeaveView',
  dicts: ['biz_leave_type', 'Class', 'approval_status'],
  components: {
    HandleResolve
  },
  created() {
    this.getList()
  },
  data() {
    return {
      // 日期范围
      // dateRange: [],
      teacherSelect: '教师信息',
      teacherSelectDialog: false,
      // 显示搜索条件
      showSearch: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: '',
      dialogTeacherLeaveView: false,
      dialogViewTeacherLeave: false,
      dialogTeacherLeave: false,
      // 教师请假信息表格数据
      // 表单参数
      form: {},
      teacherLeaveList: [],
      // 查询参数
      queryParams: {
        studentName: null,
        classValue: null,
        state: null,

      },
      // 总数
      total: 0,
      // 导出选项
      exportOptions: {
        title: '选择导出类别',
        open: false
      },
      // 办理流程
      process: {
        id: undefined,
        instanceId: undefined,
        taskId: undefined,
        open: false,
        title: '流程办理',
        readOnly: false,
        // 是否销假
        revoke: false
      }
    }
  },
  methods: {
    /** 查询学生请假信息列表 */
    getList() {
      this.loading = true
      getlistStuLeave(this.queryParams).then(response => {
        this.teacherLeaveList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    /** 重置按钮操作 */
    resetQuery() {
      // this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNum = 1
      this.getList()
    },
    /** 导出按钮操作 */
    handleExport() {
      // 导出选中，导出全部，根据查询条件导出
      this.exportOptions.open = true
    },
    confirm() {
      this.dialogViewTeacherLeave = false
    },
    // 取消按钮
    cancel() {
      this.dialogTeacherLeave = false
      // this.reset();
    },
    /** 查看/销假 */
    handleResolve({id, taskId, instanceId, taskName}, readOnly, revoke = false) {
      const isRevoke = new RegExp('销假', 'g')
      this.process.open = true
      this.process.instanceId = instanceId
      this.process.id = id
      this.process.taskId = taskId
      this.process.readOnly = readOnly // 主要用来判断是否为历史任务。或者是申请人查看
      // 是等待销假状态，同时保证不是在历史任务中
      this.process.revoke = isRevoke.test(taskName) && !readOnly
    },
    /** 审核人提交表单(刷新数据) */
    refreshData() {
      this.getList()
    },
    /** 查看 */
    handleDetail(row) {
      let stuId = row.id
      getStuLeaveOne(stuId).then(response => {
        this.form = response.data
        this.dialogTeacherLeave = true
        this.title = '学生请假信息详情'
      })
    }
  }
}
</script>
