<template>
<el-dialog

  :modal="true"
  :close-on-click-modal="false"
  :close-on-press-escape="false"
  destroy-on-close
  title="添加用户"
  :model-value="dialogVisible"

  :before-close="handleClose"

>
  <my-table

    border
    :table-data="tableData"
    ref="tableRef"
    @getCheckedTable="getCheck"
    :has-selection="true"
    :each-tr-height="32"
    :is-has-order="false"

    row-key="NAME"
    :headers="[{prop:'NAME',label:'用户'}]"

    :page-size="30"

    :tree-props="{ children: 'children',hasChildren:'hasChildren'}"
  ></my-table>
  <template #footer >
    <el-button :icon="Select" @click="saveS">保存</el-button>
    <el-button :icon="Close" @click="handleClose">关闭</el-button>
  </template>
</el-dialog>
</template>

<script>
import {Close, Select} from "@element-plus/icons-vue";
import MyTable from "@/components/common/MyTable.vue";
import {onBeforeMount, ref} from "vue";
import {addUserRoleInfo, getUserNotHasRoleSpace, getUserNotHasRoleZw} from "@/service/system-manage/root-manage";
import {UserInfo} from "@/unit/UserInfo";
import {handleLeftMenu3} from "@/data/handleLayer";
import {elAlert} from "@/unit/element-ui/tip";

export default {
  name: "AddUserModuleDilog",
  components: {MyTable},
  computed: {
    Close() {
      return Close
    },
    Select() {
      return Select
    }
  },
  props:{
    dialogVisible:{},
    currentDialogObj:{

    },
    currentOpObj:{}
  },
  setup(props,{emit}){
    const tableData= ref([])
    const checkedT = ref([])
    function getCheck(checked){
      checkedT.value = checked
    }
    onBeforeMount(() => {
       let url = +props.currentOpObj.ROLE_TYPE === 0?getUserNotHasRoleSpace:getUserNotHasRoleZw
      let params = {
        pageIndex:1,
        pageSize:2000,
        UNIT_CODE:'',
        a_role_id:props.currentOpObj.ROLE_ID,
        appkey:new UserInfo().GetUserKeyCode()
      }
      url(params).then(res => {

        // let arr = []
       let arr = handleLeftMenu3(res.msg[0].Rows,[])
        tableData.value = arr
        console.log('未配置角色的用户',res,arr)
      })
    })
    function saveS(){
      if (!(checkedT.value.length > 0)){
        elAlert('请选择要添加的用户')
        return
      }
      addUserRoleInfo({
        "ROLE_ID": props.currentOpObj.ROLE_ID,
        "USER_IDS":checkedT.value.filter(i => i.layer === 2).map(i => i.USERID).join('-'),
        "ROLE_TYPE":props.currentOpObj.ROLE_TYPE,
        "appkey": "0161D649DBA33B97E063017910AC5E26"
      }).then(res => {
        emit('successAddUser')
      })
    }
    function handleClose(){
      emit('update:dialogVisible',false)
    }
    return {
      handleClose,
      saveS,
      getCheck,
      tableData
    }
  }
}
</script>

<style scoped lang="scss">

</style>
