<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row class="last">
        <p><span>搜索条件</span> <i></i></p>
        <el-col :span="24">
          <el-col :span="8">
           <el-form-item label="请假类型" prop="type">
             <el-select style="width: 240px;" v-model="queryParams.type" placeholder="请选择类型" clearable>
               <el-option
                 v-for="dict in dict.type.sys_leave_type"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
               />
             </el-select>
           </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="请假人员" prop="absenteeName">
              <el-input
              style="width: 240px;"
                v-model="queryParams.absenteeName"
                placeholder="请输入请假人姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <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-form-item>
          </el-col>
        </el-col>


      </el-row>
    </el-form>

    <div class="navde">
      <el-row :gutter="10" class="mb8" style="background-color: #fafafa ;padding-top: 0;">
        <el-col :span="24">
          <div style="display: flex; align-items: center;justify-content: space-between;">
            <p style="border-left: 5px solid #3F73FD;padding-left: 5px;"><span>请假记录</span> </p>
            <div>
         <!-- <el-button
            type="danger"
            plain
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:leave:remove']"
          >删除</el-button> -->
            </div>
          </div>
        </el-col>


        <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
      </el-row>
      <div v-masonry class=" infinite-list" :style="dynamicStyle" style="display: flex; justify-content: flex-start; flex-wrap: wrap; ">
        <div v-masonry-tile class="group_8 flex-col" style="background-color: #fff; margin-right: 5px; margin-left: 5px; margin-bottom: 10px;" v-for="(item,index) in leaveList">
                    <div class="section_2 flex-row" style="justify-content: space-between;">
                      <div class="image-text_2 flex-row justify-between">
                        <img
                          class="thumbnail_20"
                          referrerpolicy="no-referrer"
                          src="https://lanhu-oss-2537-2.lanhuapp.com/psytg9dvwly5xjydf723bd8d17vzub9viwf0ccf5f0-42ed-42c1-ac4e-326004b6c888"
                        />
                        <span class="text-group_2" style="margin-left: 10px;">{{item.absenteeName == null?'暂无数据' : item.absenteeName + '/'+item.deptName}}</span>
                      </div>
                    </div>
                    <img
                      class="image_2"
                      referrerpolicy="no-referrer"
                      src="https://lanhu-oss-2537-2.lanhuapp.com/ps2ivkxa6dhy5173lwe8uhwdws00obqc648790f182-ec11-47f3-aac4-ca0b4ad9e851"
                    />
                    <div class="text-group_3 flex-col justify-between">
                      <div v-if="item.photo != null && item.photo !=''">
                         <image-preview :src="item.photo" :width="100 +'%'" :height="88"  style=""/>
                      </div>
                      <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                        <span class="text_28">请假类型：</span>
                        <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; display: flex;" >
                        <dict-tag :options="dict.type.sys_leave_type" :value="item.type"  />
                        </div>
                      </div>
                      <div>
                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">开始时间：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; " >
                               {{item.startTime == null?'' : item.startTime}}
                               </div>
                           </div>
                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">结束时间：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; " >
                               {{item.endTime == null?'' : item.endTime}}
                               </div>
                           </div>
                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">提交时间：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; " >
                               {{item.submitTime == null?'' : item.submitTime}}
                               </div>
                           </div>
                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">请假理由：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; " >
                               {{item.reason == null?'' : item.reason}}
                               </div>
                           </div>
                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">审批人员：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; " >
                               {{item.examinersName == null?'' : item.examinersName}}
                               </div>
                           </div>

                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">请假类别：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; display: flex;" >
                             <dict-tag :options="dict.type.sys_leave_category" :value="item.category"  />
                             </div>
                           </div>
                           <div  class="text-wrapper_8" style="display:flex; word-wrap: break-word; word-break: normal; align-items: center;">
                             <span class="text_28">是否通过：</span>
                             <div  class="syueg" style="color: #3d455b; font-size: 14px; line-height: 20px; font-weight: 400;margin: 0; width: 75%; display: flex;" >
                             <dict-tag :options="dict.type.sys_card_result" :value="item.isPass"  />
                             </div>
                           </div>
                      </el-tooltip>
                      </div>
                    </div>
                    <div class="bortt tongty" style="justify-content: space-between;" v-if="item.isPass==0">
                     <p  v-hasPermi="['system:leave:audit']" v-if="item.isPass==0"><span style="color: #28C529;cursor: pointer;"   @click="handleUpdatety(item)">通过</span>  </p>
                     <p  v-hasPermi="['system:leave:audit']" v-if="item.isPass==0" style="color:#E6A23C;cursor: pointer;" @click="handleUpdatebh(item)">驳回</p>
                     <!-- <span @click="handleUpdatef(item)">查看</span> -->
                     <!-- <p :class="item.isPass ==2?'wide':''"  style="border-left: 1px solid #DADADAd;border-right: 1px solid #DADADAd ;cursor: pointer;" @click="handleUpdate(item)">查看</p> -->
                     <p   v-hasPermi="['wuYe:staffManage:remove']"   style="color:red;cursor: pointer;" @click="handleDelete(item)">删除</p>
                    </div>
                  </div>
      </div>
      <paginations
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>


    <!-- 添加或修改请假记录信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </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>
    <el-dialog title="图片预览" :visible.sync="opende" width="1000px" append-to-body style="text-align: center;">
      <img :src="defaultSettings.urls  + '/prod-api'+ urls" style="width: 80%;" >
     <!-- <video-player v-if="jeuhse == true" style="width: 960px; " class="video-player vjs-custom-skin" ref="videoPlayer" name="videoPlayer" id="video"
        :playsinline="true"  :options="playerOptions" @play="onPlayerPlay($event)"
        @pause="onPlayerPause($event)" @ended="onPlayerEnded($event)" @waiting="onPlayerWaiting($event)"
        @timeupdate="onPlayerTimeupdate($event)" @statechanged="playerStateChanged($event)"
        @canplaythrough="onPlayerCanplaythrough($event)" @ready="playerReadied"></video-player> -->
    </el-dialog>
  </div>
</template>

<script>
import { listLeave, getLeave, delLeave, addLeave, updateLeave,audit } from "@/api/system/leave";
const defaultSettings = require("@/settings.js");
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import Masonry from "masonry-layout";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Leave",
  dicts: ['sys_leave_category', 'sys_leave_type', 'sys_card_result'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假记录信息表格数据
      leaveList: [],
      // 弹出层标题
      title: "",
      defaultSettings,
      // 是否显示弹出层
      open: false,
      opende:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        type: null,
        deptName: null,
        absenteeName: null,
        examinersName: null,
        category: null,
        isPass: null,
        submitTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      nhse:[{'value':0,'label':'未处理'},{'value':1,'label':'不通过'},{'value':2,'label':'通过'}],
      tableMaxHeight:'200',
      urls: '',
      // 部门树选项
      deptOptions: undefined,
    };
  },
  created() {
    this.getList();
    this.getTreeselect()
    window.onresize = () => {
          this.changeTableMaxHeight()
        }
        this.changeTableMaxHeight()
  },
  computed: {
    dynamicStyle() {
      return {
        overflow:'auto',
        height:  this.tableMaxHeight + 'px',
      }
    }
    },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  methods: {
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 查询请假记录信息列表 */
    getList() {
      this.loading = true;
      listLeave(this.queryParams).then(response => {
        this.leaveList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        type: null,
        startTime: null,
        endTime: null,
        reason: null,
        deptId: null,
        deptName: null,
        absenteeId: null,
        absenteeName: null,
        examinersId: null,
        examinersName: null,
        category: null,
        isPass: null,
        submitTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加请假记录信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLeave(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改请假记录信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLeave(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLeave(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除请假记录信息编号为"' + ids + '"的数据项？').then(function() {
        return delLeave(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/leave/export', {
        ...this.queryParams
      }, `leave_${new Date().getTime()}.xlsx`)
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 250
          // }
          console.log(height)
        },
    // 图片预览列表
    imagew(index) {
      this.urls = index
      this.opende = true
      var hyeowc = index
      console.log(hyeowc)
    },
    handleUpdatebh(item){
      let sngse={'id':item.id,'isPass':1}
      audit(sngse).then(response => {
        this.getList();
       this.$modal.msgSuccess("操作成功");
      });
    },
    handleUpdatety(item){
      let sngse={'id':item.id,'isPass':2}
      audit(sngse).then(response => {
        this.getList();
       this.$modal.msgSuccess("操作成功");
      });
    },
    // 获取屏幕高度
                showFilterForm () {
                      this.filterActive = !this.filterActive
                      this.changeTableMaxHeight()
                    },

                    changeTableMaxHeight () {
                      let height = document.body.offsetHeight // 网页可视区域高度
                      // if (this.filterActive) {
                      //   this.tableMaxHeight = height - 320
                      // } else {
                        this.tableMaxHeight = height - 250
                      // }
                      console.log(height)
                    }
  }
};
</script>
<style scoped lang="scss">
  .group_8 {
    width: 24%;
    padding: 0 20px;
    // height: 16px;
    overflow-wrap: break-word;
    color: rgba(61, 69, 91, 1);
    font-size: 16px;
    font-family: PingFang-SC-Heavy;
    font-weight: 900;
    text-align: left;
    // white-space: nowrap;

    // line-height: 80px;
  }
  .section_2 {
    // width: 246px;
    height: 16px;
    margin: 16px 0 0 0;
  }
  .image-text_2 {
    width: 74px;
    height: 16px;
  }
  .thumbnail_20 {
    width: 16px;
    height: 16px;
  }
  .text-group_2 {
    // width: 48px;
    height: 16px;
    overflow-wrap: break-word;
    color: rgba(61, 69, 91, 1);
    font-size: 16px;
    font-family: PingFang-SC-Heavy;
    font-weight: 900;
    text-align: left;
    white-space: nowrap;
    line-height: 16px;
  }
  .box_5 {
    background-color: rgba(255, 255, 255, 1);
    border-radius: 4px;
    width: 14px;
    height: 14px;
    border: 1px solid rgba(230, 230, 230, 1);
    // margin: 1px 0 0 138px;
  }
  .thumbnail_21 {
    width: 2px;
    height: 12px;
    margin: 2px 0 0 18px;
  }
  .image_2 {
    // width: 287px;
    height: 1px;
    margin-top: 15px;
  }
  .text-group_3 {
    // width: 238px;
    // height: 152px;
    // margin: 23px 0 0 0;
    // padding-bottom: 20px;
  }
  .text-wrapper_7 {
    // width: 207px;
    // height: 104px;
    overflow-wrap: break-word;
    font-size: 0;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 20px;
  }
  .text_23 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(34, 40, 56, 1);
    font-size: 14px;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 30px;
  }
  .paragraph_1 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(61, 69, 91, 1);
    font-size: 14px;
    font-family: PingFang-SC-Medium;
    font-weight: 500;
    text-align: left;
    line-height: 30px;
  }
  .text_24 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(34, 40, 56, 1);
    font-size: 14px;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 30px;
  }
  .paragraph_2 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(61, 69, 91, 1);
    font-size: 14px;
    font-family: PingFang-SC-Medium;
    font-weight: 500;
    text-align: left;
    line-height: 30px;
  }
  .text_25 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(34, 40, 56, 1);
    font-size: 14px;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 30px;
  }
  .paragraph_3 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(61, 69, 91, 1);
    font-size: 14px;
    font-family: PingFang-SC-Medium;
    font-weight: 500;
    text-align: left;
    line-height: 30px;
  }
  .text_26 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(34, 40, 56, 1);
    font-size: 14px;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 30px;
  }
  .text_27 {
    width: 207px;
    height: 104px;
    overflow-wrap: break-word;
    color: rgba(255, 105, 105, 1);
    font-size: 14px;
    font-family: PingFang-SC-Medium;
    font-weight: 500;
    text-align: left;
    line-height: 30px;
  }
  .text-wrapper_8 {
    // width: 238px;
    // height: 32px;
    overflow-wrap: break-word;
    font-size: 0;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 18px;
    // margin-top: 8px;
  }
  .text_28 {
    width: 76px;
    height: 32px;
    overflow-wrap: break-word;
    color: rgba(34, 40, 56, 1);
    font-size: 14px;
    font-family: PingFang-SC-Bold;
    font-weight: 700;
    text-align: left;
    line-height: 32px;
  }
  .paragraph_4 {
    width: 238px;
    height: 32px;
    overflow-wrap: break-word;
    color: rgba(61, 69, 91, 1);
    font-size: 14px;
    font-family: PingFang-SC-Medium;
    font-weight: 500;
    text-align: left;
    line-height: 18px;
  }
  .section_3 {
    background-color: rgba(245, 249, 255, 1);
    border-radius: 4px;
    // width: 246px;
    height: 168px;
    // margin: 13px 0 16px 20px;
    margin-bottom: 20px;
  }

  .flex-col {
    display: flex;
    flex-direction: column;
  }
  .flex-row {
    display: flex;
    flex-direction: row;
  }
  .justify-between {
    display: flex;
    justify-content: space-between;
  }
  .syueg{
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>
<style scoped lang="scss">
  .tongty{
    display: flex;
    align-items: center;
  }
  .bortt{
    border-top: 1px solid #DADADA;
    margin-top: 15px;

    p{
      margin: 0;
      font-weight: bold;
      font-size: 14px;
      color: #5F8BF4;
      width:50%;
      padding: 10px;
      text-align: center;
    }
  }
  .wide{
      width:100% !important;
    }
</style>
