<template>
  <div>
    <PageTable ref="userEditRoleTable" :resource="tableData" :columns="columns" :isPage="false">

    </PageTable>
  </div>
</template>
<script>
export default {
  components: {

  },
  props: {
    roles: Array,
    default() {
      return [];
    }
  },
  data() {
    return {
      tableData: [],
      columns: [
        {
          type: "selection",
          width: 60,
          align: "center"
        },
        {
          title: this.$t("module.userManage.roleName"),
          key: "roleName",
          sortable: true,
        },
        {
          title: this.$t("module.userManage.roleCode"),
          sortable: true,
          key: "roleCode",
        },
        {
          title: this.$t("module.userManage.affiliation"),
          sortable: true,
          key: "orgName",
        },
        {
          title: this.$t("common.status"),
          align: "center",
          key: "enabled",
          sortable: true,
          width: 140,
          render: (h, params) => {
            return h(
              "Tag",
              {
                props: {
                  type: "dot",
                  color: !!params.row.enabled ? "blue" : "red"
                }
              },
              !!params.row.enabled ? this.$t("module.userManage.enabled") : this.$t("module.userManage.frozen")
            );
          }
        }
      ]
    }
  },
  computed: {

  },
  created: function () {
    this.$emit('SetTitle', this.$t("module.userManage.addRole"));
    this.$emit('SetPageSize', 800);
    this.$emit('SetPageActions', [
      {
        text: this.$t("common.save"),
        theme: "primary",
        icon: "md-create",
        action: "EditUser",
        handle: () => {
          this.$emit('Close', this.$refs['userEditRoleTable'].getSelectioned() || []);
        }
      }
    ])
  },
  beforeMount: function () {

  },
  mounted: function () {
    setTimeout(() => {
      this.queryRole();
    }, 500)
  },
  beforeDestroy: function () {

  },
  destroyed: function () {

  },
  methods: {
    queryRole() {
      return $store.dispatch("QueryRole", {
        commonPageDTO: {
          currentPage: 1,
          pageSize: 10000
        },
        /*sortDTO: {
          fieldName: "",
          orderBy: ""
        },*/
        enabled: 1,
        effective: 1
      }).then((res) => {
        res.recordList.map((role) => {
          let j = this.roles.findIndex(row => {
            return row.roleId == role.roleId;
          });
          role.enabled = !!Number(role.enabled);
          role.effectBegin = undefined;
          role.effectEnd = undefined;
          ~j || this.tableData.push(role);
          // if (j > -1) {
          //   // role._disabled = true;
          //   role._checked = true;
          // } else {
          //   // role._disabled = false;
          //   role._checked = false;
          // }
        })
        // this.tableData = [].concat(res.recordList);
        this.$refs['userEditRoleTable'].refresh();
      });
    }
  },
  watch: {

  },
  directives: {

  }
}
</script>
