<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">

      <el-form-item label="费用名称" prop="feeName">
        <el-input
          v-model="queryParams.feeName"
          placeholder="请输入费用名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="申请时间">
        <el-date-picker
          v-model="registrationDate"
          size="small"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="timeChange"
          style="width: 340px"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="状态" prop="approvalStatus">
        <el-select
          v-model="queryParams.approvalStatus"
          placeholder="请选择项目状态"
          clearable
          size="small"
        >
          <el-option label="待核算部审批" value="1"/>
          <el-option label="完成" value="2"/>
          <el-option label="驳回" value="3"/>
        </el-select>

      </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-form-item>
    </el-form>

    <el-button
      type="warning"
      plain
      icon="el-icon-download"
      size="mini"
      style="margin-bottom: 10px"
      @click="handleExport">
      导出
    </el-button>

    <TableList ref="tableList" :param="queryParams"/>
  </div>
</template>

<script>
  import TableList from "./components/TableList";
  export default {
    name: "borrowing-index",
    components:{
      TableList,
    },
    created(){
      this.getCurrentMonthTime();
    },
    data(){
      return{
        queryParams: {
          feeName: null,
          userIdName: null,
          borrowingDeptId: this.$store.state.user.deptId,
          applicationDescription: null,
          registrationDate: null,
          registrationBeginDate: null,
          registrationEndDate: null,
          approvalStatus: null
        },
        deptOptions: [],
        registrationDate: []
      }
    },
    methods:{
      /** 搜索按钮操作 */
      handleQuery() {
        this.$refs.tableList.getBorrowingList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.queryParams.registrationBeginDate = null;
        this.queryParams.registrationEndDate = null;
        this.registrationDate = [];
        this.queryParams.sortType = '0';
        this.handleQuery();
      },
      //时间切换
      timeChange(value) {
        if (value) {
          this.queryParams.registrationBeginDate = value[0];
          this.queryParams.registrationEndDate = value[1];
        }else{
          this.queryParams.registrationBeginDate = null;
          this.queryParams.registrationEndDate = null;
        }
      },
      handleExport(){
        this.$refs.tableList.borrowingExport();
      },
      getCurrentMonthTime(){
        let now = new Date(); // 获取当前日期时间
        let firstDate = new Date(now.getFullYear(), now.getMonth(), 1);
        let lastDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
        let firstDateStr = firstDate.toLocaleDateString().replace(/\//g, "-") + " " + firstDate.toTimeString().substr(0, 8);
        let lastDateStr = lastDate.toLocaleDateString().replace(/\//g, "-") + " " + lastDate.toTimeString().substr(0, 8);
        this.registrationDate = [firstDateStr,lastDateStr];
        this.timeChange(this.registrationDate);
      }
    }
  }
</script>

<style scoped>

</style>
