<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" size="small" @submit.native.prevent>
      <el-form-item label="教师姓名" prop="teacherName">
        <el-input v-model="queryParams.teacherName" clearable placeholder="请输入教师姓名"
          @keyup.enter.native="handleQuery"></el-input>
      </el-form-item>
      <el-form-item label="请假类型" prop="type">
        <el-select v-model="queryParams.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-form-item label="标题" prop="title">
        <el-input v-model="queryParams.title" clearable placeholder="请输入标题" @keyup.enter.native="handleQuery"></el-input>
      </el-form-item>
      <el-form-item label="请假时间">
        <el-date-picker v-model="dateRange" style="width: 300px" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange"
          range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <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-button type="warning" plain icon="el-icon-upload2" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="teacherLeaveList">
      <el-table-column type="index" width="55" label="序号" align="center" />
      <el-table-column label="教师名称" key="teacherName" min-width="120" align="center" prop="teacherName"
        show-overflow-tooltip />
      <el-table-column label="标题" min-width="120" align="center" prop="title" />
      <el-table-column label="请假开始时间" key="startTime" min-width="150" align="center" prop="startTime">
        <template slot-scope="scope">
          {{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
          <dict-tag style="display: inline-block" :options="dict.type.course_num" :value="scope.row.startSort" />
        </template>
      </el-table-column>
      <el-table-column label="请假结束时间" key="endTime" min-width="150" align="center" prop="endTime">
        <template slot-scope="scope">
          {{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
          <dict-tag style="display: inline-block" :options="dict.type.course_num" :value="scope.row.endSort" />
        </template>
      </el-table-column>
      <el-table-column label="请假时长" key="applyUser" align="center" min-width="180" prop="totalTime">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="60" key="operate">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-search" @click="handleDetail(scope.row)"
            v-hasPermi="['system:teacherOvertime:edit']">查看
          </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>
    <!-- 添加或修改教师请假信息对话框 -->
    <el-dialog :title="title" :visible.sync="dialogTeacherLeave" width="1100px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px" :disabled="isEdit">
        <el-row>
          <el-col :span="11">
            <el-form-item label="教师名称" prop="teacherName">
              <el-input :value="form.teacherName" @click.native="openTeacherSelect" placeholder="请输入教师名称" />
            </el-form-item>
          </el-col>
          <el-col :offset="2" :span="11">
            <!--            <el-form-item label="标题" prop="title">-->
            <!--              <el-input v-model="form.title" placeholder="请输入标题"/>-->
            <!--            </el-form-item>-->
            <el-form-item label="标题" prop="title">
              <el-input :value="form.title" clearable placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="请假开始时间" prop="startTime">
              <el-row>
                <template v-if="form.startSort">
                  <el-col :span="12">
                    <el-date-picker :value="form.startTime" type="date" value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择开始时间"></el-date-picker>
                  </el-col>
                  <el-col :span="12">
                    <el-input :value="selectDictLabel(dict.type.course_num, form.startSort)"></el-input>
                  </el-col>
                </template>
                <template v-else>
                  <el-col :span="12">
                    <el-date-picker :value="form.startTime" type="datetime" style="width: 365.83px"
                      value-format="yyyy-MM-dd HH:mm" placeholder="选择开始时间"></el-date-picker>
                  </el-col>
                </template>

              </el-row>
            </el-form-item>
          </el-col>
          <el-col :offset="2" :span="11">
            <el-form-item label="请假结束时间" prop="endTime">
              <el-row>
                <template v-if="form.endSort">
                  <el-col :span="12">
                    <el-date-picker :value="form.endTime" type="date" value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择结束时间"></el-date-picker>
                  </el-col>
                  <el-col :span="12">
                    <el-input :value="selectDictLabel(dict.type.course_num, form.endSort)"></el-input>
                  </el-col>
                </template>
                <template v-else>
                  <el-col :span="12">
                    <el-date-picker style="width: 365.83px" :value="form.startTime" type="datetime"
                      value-format="yyyy-MM-dd HH:mm" placeholder="选择开始时间"></el-date-picker>
                  </el-col>
                </template>
              </el-row>
            </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-form-item label="请假时长" prop="totalTime">
              <el-input :value="form.totalTime" placeholder="请输入" />
            </el-form-item>
          </el-col>

        </el-row>
        <!-- <el-form-item label="请假原因" prop="reasonForLeave">
          <el-input type="textarea" resize="none" :autosize="{ minRows: 5 }" :value="form.reasonForLeave" />
        </el-form-item> -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
    <!--    &lt;!&ndash; 查看教师请假信息对话框 &ndash;&gt;-->
    <!--    <el-dialog :title="title" :visible.sync="dialogTeacherLeaveView" width="1000px" append-to-body>-->
    <!--      <el-card>-->
    <!--        <el-descriptions title="请假基本消息">-->
    <!--          <el-descriptions-item label="教师名称">{{ form.teacherName }}</el-descriptions-item>-->
    <!--          <el-descriptions-item label="标题">{{ form.title }}</el-descriptions-item>-->
    <!--          <el-descriptions-item label="请假开始时间">{{ form.startTime }}</el-descriptions-item>-->
    <!--          <el-descriptions-item label="请假结束时间">{{ form.endTime }}</el-descriptions-item>-->
    <!--          <el-descriptions-item label="请假类型">-->
    <!--            <dict-tag :options="dict.type.biz_leave_type" :value="form.type"/>-->
    <!--          </el-descriptions-item>-->
    <!--        </el-descriptions>-->
    <!--      </el-card>-->
    <!--      <br/>-->
    <!--      <el-card>-->
    <!--        <el-descriptions title="请假原因"/>-->
    <!--        <span v-html="form.reasonForLeave"/>-->
    <!--      </el-card>-->
    <!--      <div slot="footer" class="dialog-footer">-->
    <!--        <el-button type="primary" @click="dialogTeacherLeaveView=false">确 定</el-button>-->
    <!--      </div>-->
    <!--    </el-dialog>-->

    <!-- 导出对话框 -->
    <!-- <ExportTable :open-export.sync="exportOptions.open" :title="exportOptions.title" @export="exportFile"></ExportTable> -->
  </div>
</template>
<script>
import {
  listTeacherLeave,
  getTeacherLeave,
} from "@/api/smartSchool/teacherManage/teacherLeaveInfoSum";
import { ExportType } from "@/enums/common";

export default {
  name: "index",
  dicts: ['biz_leave_type', 'course_num'],
  created() {
    this.getList();
  },
  data() {
    return {
      //禁用
      isEdit: false,
      // 日期范围
      dateRange: [],
      teacherSelect: '教师信息',
      teacherSelectDialog: false,
      // 显示搜索条件
      showSearch: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      dialogTeacherLeaveView: false,
      dialogViewTeacherLeave: false,
      dialogTeacherLeave: false,
      // 教师请假信息表格数据
      // 表单参数
      form: {},
      teacherLeaveList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        submitState: 0,
        teacherName: null,
      },
      // 总数
      total: 0,
      // 导出选项
      exportOptions: {
        title: '选择导出类别',
        open: false
      }
    };
  },
  methods: {
    /** 查询教师请假信息列表 */
    getList() {
      this.loading = true;
      listTeacherLeave(this.addDateRange(this.queryParams, this.dateRange)).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;
    //   this.$confirm(`是否确认导出${!!this.ids.length ? this.ids.length + '条' : '所有'}数据？`, '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     if (this.ids.length) {
    //       this.download('/school/teacherLeave/export/' + this.ids, {
    //         ...this.queryParams
    //       }, `教师请假信息.xlsx`)
    //     } else {
    //       this.download('/school/teacherLeave/export', {
    //         ...this.queryParams
    //       }, `教师请假信息.xlsx`)
    //     }
    //   }).catch(() => {
    //   });
    // },

    /** 导出 */
    // exportFile(callback) {
    //   const ids = this.ids;
    // TODO: 这里因为是两种状态： 提交和未提交，所以需要判断状态
    // const options = [
    //   { type: ExportType.TOTAL, path: '/school/teacherLeave/export', params: {} },
    // {
    //   type: ExportType.SELECT,
    //   path: '/school/teacherLeave/export/' + ids,
    //   params: {}
    // },
    // { type: ExportType.QUERY, path: '/school/teacherLeave/export', params: this.queryParams },
    //   ]
    //   callback(options, `老师请假信息${new Date().getTime()}.xlsx`);
    // },
    //导出
    handleExport() {
      this.download('/school/teacherLeave/exportTeacherLeaveList', {
        ...this.queryParams
      }, `教职工请假信息_${Date.now()}.xlsx`)
    },

    //时间格式化
    dateFormat(row, column, cellValue, index) {
      const data = row[column.property]
      if (data) {
        let date1 = new Date(data.date).toJSON();
        let date = new Date(+new Date(date1) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
        return date;
      }
    },

    confirm() {
      this.dialogViewTeacherLeave = false;
    },
    // 取消按钮
    cancel() {
      this.dialogTeacherLeave = false;
      // this.reset();
    },
    /** 查看详情 */
    handleDetail(row) {
      let teacherId = row.id
      getTeacherLeave(teacherId).then(response => {
        this.form = response.data;
        console.log('object', this.form);
        this.dialogTeacherLeave = true;
        this.isEdit = true;
        this.title = "教师请假信息详情";
      });
    },

  }
};
</script>
