<template>
  <div>
    <BizTable
      ref="bt"
      :formatCol="formatCol"
      metaName="user_info"
      packageName="auth"
     :tblheight="tblheight"
      isMulti
      @onnew="onnew"
      @onedit="onedit"
      :savebefore="beforesave"
      :editbefore="beforedit"
      :addbefore="beforeadd"
    ></BizTable>
  </div>
</template>
  <script>
import BizTable from "../components/tables/biztables";
export default {
  name: "userinfo_page",
  data() {
    return {};
  },
  components: {
    BizTable
  },
  props: {
    tblheight:Number,
    beforesave: {
      type: Function,
      default() {
        return (key, row, cbk) => {
          return cbk(row);
        };
      }
    },
    beforedit: {
      type: Function,
      default() {
        return (row, cbk) => {
          return cbk({ value: true, message: null });
        };
      }
    },
    beforeadd: {
      type: Function,
      default() {
        return (row, cbk) => {
          return cbk({ value: true, message: null });
        };
      }
    }
  },
  methods: {
    searchWhere(obj) {
      this.$refs.bt.initWhere = obj;
      this.$refs.bt.fetchData();
    },
    setHeight(h) {
      this.$refs.bt.setHeight(h);
    },
    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>
