<template>
  <basic-container>
    <avue-crud
      v-bind="bindVal"
      v-on="onEvent"
      v-model="form"
      :page.sync="page"
    >
      <template slot="menuLeft">
        <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          plain
          @click="handleDelete"
        >
          删 除
        </el-button>
        <el-button
          type="success"
          size="small"
          plain
          icon="el-icon-upload2"
          @click="handleImport"
        >
          导入
        </el-button>
        <el-button
          type="warning"
          size="small"
          plain
          icon="el-icon-download"
          @click="handleExport"
        >
          导出
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-printer"
          @click="printTable"
        >
          打印
        </el-button>
      </template>
      <template slot="menuLeft">

      </template>
    </avue-crud>
    <upload-excel-dialog ref="uploadExcelDialog" :uploadAfter="uploadAfter"/>
    <WideTablePrinter
      ref="printWideTable"
      :columns="wideTableColumns"
      :data="data"
      :print-title="printTitle"
      :rows-per-page="30"
      :default-landscape="true"
    />
  </basic-container>
</template>

<script>
import {exportBlob} from "@/api/common";
import UploadExcelDialog from "@/components/upload-excel-dialog";
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import {getToken} from "@/util/auth";
import {downloadXls} from "@/util/util";


export default window.$crudCommon({
  components: {
    UploadExcelDialog,
  },
  data() {
    return {
      params: {},
      wideTableColumns: [],
      printTitle: "",
    };
  },
  methods: {
    handleImport() {
      // let excelParams = { yearAndMonth: this.params.yearAndMonth };
      this.$refs.uploadExcelDialog.open('/api/kd-scientific/kycg/rjzzq/import', {});
    },
    uploadAfter() {
      this.$message({
        type: "success",
        message: "导入成功!"
      });
      this.page.currentPage = 1;
      this.getList(this.page);
    },
    handleExport() {
      this.$confirm("是否导出吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        NProgress.start();
        exportBlob(`/api/kd-scientific/kycg/rjzzq/export?${this.website.tokenHeader}=${getToken()}`, {}).then(res => {
          downloadXls(res.data, `软件著作.xlsx`);
          NProgress.done();
        })
      });
    },
    printTable() {
      this.wideTableColumns = this.$refs.crud.columnOption;
      this.printTitle = `科研成果`;
      this.$nextTick(() => {
        this.$refs.printWideTable.printTable(false);
      })
    },
  },
}, {
  // 模块路径
  name: 'achievement/softWorks'
});
</script>
