<template>
  <div>
    <BizTable
      ref="bt"
      :formatCol="formatCol"
      modelName="user"
      metaName="tanent_info"
      packageName="auth"
      isMulti
      @onnew="onnew"
      @onedit="onedit"
      @onexec="onexec"
    ></BizTable>
  </div>
</template>
  <script>
import BizTable from "../components/tables/biztables";
import { allowOrNot } from "@/api/user";
export default {
  name: "userinfo_page",
  data() {
    return {};
  },
  components: {
    BizTable
  },
  mounted(){

  },
  methods: {
    onexec(k, row, btninfo) {
      if (btninfo) {
        if (k == "allowornot") {
          this.$Modal.confirm({
            title: "提示",
            content: "<p>您真的要禁用租户及相关所有用户吗?</p>",
            loading: true,
            onOk: () => {
              allowOrNot({
                isEnabled: row.isEnabled,
                company_id: row.company_id
              }).then(res => {
                let ret = res.data;
                if (ret.status == 0) {
                  this.$Modal.remove();
                  this.$Message.success("当前操作成功完成.");
                  if (row.isEnabled) {
                    btninfo.title = "禁用";
                  } else {
                    btninfo.title = "启用";
                  }
                  this.$refs.bt.fetchData()
                }else{
                      this.$Message.error("当前操作失败，请稍后重试或联系管理员.");
                }
              });
            }
          });
        }
      }
    },
    onnew() {
      this.$refs.bt.setFormCtlVisable("userName", true);
    },
    onedit() {
      this.$refs.bt.setFormCtlVisable("userName", false);
    },
    formatCol(row, key, index) {
      if (key == "roleName") {
        let rolestr = row.Roles.map(item => item.name).join(",");
        row.roles = row.Roles.map(item => item.id);
        return `<span>${rolestr}</span>`;
      }
      if (key == "isAdmin" || key == "isSuper") {
        return `<span>${row[key] ? "是" : "否"}</span>`;
      }
      if (key == "created_at") {
        return `<span>${new Date(row[key]).toLocaleString()}</span>`;
      }
      return row[key];
    }
  }
};
</script>
  <style>
</style>
