<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
    >
      <el-form-item label="任务名称" >
        <el-input
          v-model="queryParams.taskName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人">
        <el-input
          v-model="queryParams.applyUserName"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" >
        <el-date-picker
          v-model="value1"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="handleQuery"
        >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery"
        >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          plain-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="handleAdd"-->
      <!--          v-hasPermi="['system:dept:add']"-->
      <!--        >新增</el-button-->
      <!--        >-->
      <!--      </el-col>-->

    </el-row>

    <div class="table">
      <el-table
        v-loading="loading"
        :data="deptList"
        row-key="deptId"
        max-height="350px"
        highlight-current-row
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column
          prop="seriervs"
          label="序号"
          min-width="30"
        ></el-table-column>
        <el-table-column
          prop="taskName"
          label="任务名称"
          min-width="180"
        >
          <template slot-scope="{row}" >
            <span @click="appNoDidet(row)" style="color: #00afff;cursor: pointer">{{row.taskName}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="申请人"
          align="center"
          prop="applyUserName"
        >
        </el-table-column>
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
        >
        </el-table-column>
        <el-table-column prop="auditResult" label="状态" >
        </el-table-column>
        <el-table-column prop="status" label="状态" >
          <template slot-scope="scope">
            已办
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="display: flex;justify-content: flex-end ;margin: 15px 0px 0px 0px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total" />
    </div>
    <modal ref="modal" @updata="getList"/>
  </div>
</template>

<script>
import {
  finishPage,
} from "@/api/system/dept";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import  moment from 'moment'
import modal from './modal'

export default {
  provide() {
    return {
      getList: this.getList
    };
  },
  components:{
    modal,
  },
  data() {
    return {
      deptList:[],
      value1:null,
      // 遮罩层
      loading: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        taskName: undefined,
        applyUserName: undefined,
        startDate:null,
        endDate:null,
      },
      pageNo:1,
      pageSize:10,
      total:0,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    moment,
    appNoDidet(row){
      row.type='已办'
      this.$refs.modal.handle(row)
    },
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      let data={
        pageNo:this.pageNo,
        pageSize:this.pageSize,
      }
      if(this.value1){
        this.queryParams.startDate=moment(this.value1[0]).format('YYYY-MM-DD')
        this.queryParams.endDate=moment(this.value1[1]).format('YYYY-MM-DD')
      }else {
        this.queryParams.startDate=''
        this.queryParams.endDate=''
      }
      finishPage(this.queryParams,data).then((response) => {
        if(response && response.data && response.data.records){
          this.loading = false;
          this.deptList = response.data.records;
          this.total=response.data.total
          this.deptList.forEach((item,index)=>{
            item.seriervs=index+1
          })
        }else {
          this.loading = false;
        }
      });
    },
    handleSizeChange(val) {
      this.pageSize=val
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageNo=val
      this.getList()
    },
    // 表单重置
    reset() {
      this.form = {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams= {
        taskName: undefined,
        applyUserName: undefined,
        startDate:null,
        endDate:null,
      },
        this.value1=null
    },

  },
};
</script>
<style lang="scss" scoped>
.table {
  height: calc(100% - 80px);
}
::v-deep {
  .el-table {
    height: 100%;
    width: 100%;
    .el-table__body-wrapper {
      width: 100% !important;
      height: calc(100% - 50px) !important; // 表格高度减去表头的高度
      overflow-y: scroll;
    }
  }
}
</style>
