<!--
 * @desc
 * @author linyuanjie
 * @date 2023/9/23
-->

<template>
  <avue-crud
    :data="tableData"
    :option="optionData"
    :page.sync="page"
    :table-loading="tableLoading"
    @on-load="getList"
    @size-change="sizeChange"
    @search-change="searchVal"
    @current-change="currentChange"
    @search-reset="searchReset"
  >
    <template slot="menu" slot-scope="scope">
      <el-button
        type="text"
        size="small"
        icon="el-icon-view"
        @click="toView(scope.row, scope.index)"
      >
        查看
      </el-button>
    </template>
  </avue-crud>
</template>

<script>
import { enterpriseTaskData } from "@/const/crud/enterpriseTask";
import { getEntTaskPage } from "@/api/enterpriseTask";
import Config from "@/settings";

export default {
  name: "taskRecord",
  data() {
    return {
      optionData: enterpriseTaskData,
      tableData: [],
      page: {
        pageSize: 20,
        pagerCount: 5
      },
      tableLoading: false
    };
  },
  methods: {
    // 查看
    toView(row) {
      window.open(
        Config.outsideUrl + "/h5/#/pages/task/task-detail/index?id=" + row.id,
        "newwindow",
        "height=750, width=400, top=200, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
      );
    },
    // 初始化页面
    getList(page, params) {
      this.tableLoading = true;
      getEntTaskPage(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      )
        .then(response => {
          this.tableData = [];
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    // 查询
    searchVal(form, done) {
      this.searchForm = form;
      this.page.currentPage = 1;
      this.getList(this.page, form);
      done();
    },
    searchReset() {},
    // 分页查询
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    }
  }
};
</script>

<style scoped></style>
