<template>
  <div class="page_info">
    <div class="search_pannel">
      <el-form
        ref="dataForm"
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
        @submit.native.prevent
      >
        <el-form-item prop="name" label="" label-width="200px">
          <el-date-picker
            v-model="dataForm.workDate"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div class="search_btn">
        <el-button type="primary" @click="getDataList">{{
          $t("query")
        }}</el-button>
        <el-button plain @click="resetForm('dataForm')">重置</el-button>
      </div>
    </div>
    <div class="card_info">
      <div class="function_btn">
        <el-button
          v-if="$hasPermission('sys:role:save')"
          icon="el-icon-plus"
          type="primary"
          @click="addOrUpdateHandle()"
          >{{ $t("add") }}</el-button
        >
        <el-button
          v-if="$hasPermission('sys:role:delete')"
          icon="el-icon-delete"
          plain
          class="btn_color"
          @click="deleteHandle()"
          >{{ $t("deleteBatch") }}</el-button
        >
      </div>
      <div class="info_list">
        <el-table
          v-loading="dataListLoading"
          :data="dataList"
          stripe
          :header-cell-style="{ background: '#e6e7ea', color: '#0C1935' }"
          @selection-change="dataListSelectionChangeHandle"
          @sort-change="dataListSortChangeHandle"
          style="width: 100%"
          :height="screenHeight"
        >
          <el-table-column
            type="selection"
            header-align="center"
            align="center"
            width="50"
          ></el-table-column>
          <el-table-column
            prop="title"
            label="标题"
            header-align="center"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="content"
            label="内容"
            header-align="center"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="workDate"
            label="日程日期"
            header-align="center"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="createDate"
            label="创建时间"
            header-align="center"
            align="center"
            width="180"
          ></el-table-column>
          <el-table-column
            label="操作"
            fixed="right"
            header-align="center"
            align="center"
            width="200"
          >
            <template slot-scope="scope">
              <el-link
                v-if="$hasPermission('work:workprogram:update')"
                type="primary"
                :underline="false"
                @click="addOrUpdateHandle(scope.row.id)"
                >编辑</el-link
              >
              <el-link
                v-if="$hasPermission('work:workprogram:delete')"
                type="primary"
                :underline="false"
                @click="deleteHandle(scope.row.id)"
                >删除</el-link
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <template v-if="total > 0">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          background
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        >
        </el-pagination>
      </template>
    </div>
    <!-- 弹窗, 新增 / 修改 -->
    <el-drawer
      size="25%"
      :visible.sync="drawer"
      :with-header="false"
      :modal="false"
      @close="closedrawer"
    >
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
    </el-drawer>
  </div>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./job-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      screenHeight: "512px",
      mixinViewModuleOptions: {
        createdIsNeed:false,
        getDataListURL: "/work/workprogram/page",
        getDataListIsPage: true,
        deleteURL: "/work/workprogram",
        deleteIsBatch: true,
        
      },
      dataForm: {
        workDate: "", //日期
      },
    };
  },
  components: {
    AddOrUpdate,
  },
  created(){
    this.dataForm.workDate=this.$route.query.data;
    this.getDataList();
  },
  mounted() {
    this.setTableHeight();
    // 页面创建完成后添加监听
    window.addEventListener("resize", this.setTableHeight);
  },
  methods: {
    setTableHeight() {
      setTimeout(() => {
        this.screenHeight = getComputedStyle(
          document.querySelector(".info_list")
        ).height;
      }, 1000);
    },
    //表单重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  destroyed() {
    window.removeEventListener("resize", this.setTableHeight);
  },
};
</script>
