export default {
  methods: {
    async handlePageChange(val) {
      this.parmValue.page = val;
      this.pageInfo.curr = val;
      await this.searchList();
    },
    async handleSizeChange(val) {
      this.parmValue.page = 1;
      this.pageInfo.curr = 1;
      this.pageInfo.size = val;
      this.parmValue.size = val;
      await this.searchList();
    },
    async pageHttpDownload(url, model, httpType, excelName) {
      return await new Promise(async (resolve, reject) => {
        axios({
          method: "post",
          url: url,
          responseType: "blob",
          data: model,
          headers: {
            Accept: httpType,
          },
        })
          .then((res) => {
            const { status, data } = res ?? {};
            if (status == 200) {
              this.pageDownload(data, httpType, excelName);
              resolve({ code: 0 });
            } else {
              resolve({ code: -1 });
            }
          })
          .catch(() => {
            resolve({ code: -2 });
          });
      });
    },
    pageDownload(data, httpType, excelName) {
      const url = window.URL.createObjectURL(
        new Blob([data], {
          type: httpType,
        })
      );
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", excelName);
      document.body.appendChild(link);
      link.click();
      link.remove();
      window.URL.revokeObjectURL(url); //释放掉blob对象
    },
  },
};
