export default {
  methods: {
    async logout() {
      if (this.$route.path !== '/login') {
        await this.$store.dispatch('user/logout')
        await this.$router.push(`/login?redirect=${this.$route.fullPath}`)
      }
    },
    async routeGoto(path, query) {
      await window.vm.$router.push({
        path: path,
        query: query
      })
    },
    async routeReGoto(path, query) {
      await window.vm.$router.replace({
        path: path,
        query: query
      })
    },
    async useResHandle(res, type) {
      return await new Promise(async (resolve, reject) => {
        const { code, data, message } = res ?? {};
        const rescode = parseInt(code + "");
        if (rescode === 0) {
          resolve(res);
        } else if (rescode >= 101 && rescode <= 104) {
          if (this.loading) {
            this.loading = false;
          }

          await this.logout();
        } else if (rescode >= 105 && rescode <= 106) {
          // if (this.loading) {
          //   this.loading = false;
          // }
          // this.$notify({
          //   title: "当前供应商参数错误",
          //   dangerouslyUseHTMLString: true,
          //   message: "5秒后，请您重新登录！",
          // });
          // await setTimeout(async () => {
          //   await this.logout();
          // }, 5000);
        } else {
          if (this.loading) {
            this.loading = false;
          }
          if (type) {
            resolve(res);
          } else {
            this.$message.warning(message);
          }
        }
      });
    },
    setNum(s) {
      return s ? parseFloat(s + '').toFixed(2) : '-'
    }
  }
}
