<template>
 <div class="position-re">
   <my-breadcrumb :breadcrumb-arr="myBread" class="my-breadcrumb"/>
   <div class="back">
     <span class="fa fa-plus cur-po" v-if="+useRootStore().userInfo.ptjk_role === 0" @click="openSetUserDialog">添加</span>
     <span class="fa fa-reply cur-po" @click="$emit('changeOperation','')">返回</span>
   </div>
  <div class="my-detail-main">
    <my-table
      border
      :has-operation="!(+useRootStore().userInfo.ptjk_role !== 0 ||useRootStore().isUserVisiter)"
      :headers="currentOpObj.ROLE_TYPE === '0'?rootManageUserDetailTableHeaderSpace:rootManageUserDetailTableHeader"
      :table-data="tableData"
    >
      <template #operation="{data}">
        <span class="fa fa-trash cur-point" title="删除"  @click="delUser(data)"></span>
      </template>
    </my-table>
    <ele-pagination  ref="refEl"

                     @sizeOrPageChange="handleSizeChange"
                     class="page"
                     :default-page-size="pageSize"


                     :total-count="totalCount">

      <template #default>
        <div class="m-s">
          显示第 {{pageSize * (pageIndex -1) + 1 }} 到第 {{pageSize * pageIndex}} 条记录，总共 {{totalCount}} 条记录 共显示

        </div>
      </template>
    </ele-pagination>
  </div>
   <template v-if="isAddUseRoleDialogIsShow">
     <add-user-module-dilog @successAddUser="successAddUser" :current-op-obj="currentOpObj" v-model:dialog-visible="isAddUseRoleDialogIsShow" :current-dialog-obj="currentDialogOpObj"/>
   </template>
 </div>
</template>

<script>
import MyBreadcrumb from "@/components/common/MyBreadcrumb.vue";
import {onBeforeMount, ref} from "vue";
import {useRootStore} from "@/stores/useStore";
import MyTable from "@/components/common/MyTable.vue";
import {rootManageUserDetailTableHeader, rootManageUserDetailTableHeaderSpace} from "@/data/all-table-header";
import {elAlert, handleMes, showConfirm} from "@/unit/element-ui/tip";
import {deleteProcessTableHomeData} from "@/service/data-gather-watch/process-table";
import {delRoleUserInfoSpace,delRoleUserInfoZw, getUserInfoKj, getUserInfoZw} from "@/service/system-manage/root-manage";
import {UserInfo} from "@/unit/UserInfo";
import ElePagination from "@/components/common/ElePagination.vue";
import {useDetailOrEdit, usePagination} from "@/unit/use-method/usePagination";
import AddUserModuleDilog from "@/view/other/c-views/system-manage/system-manage/root-manage/AddUserModuleDilog.vue";

export default {
  name: "RootManageUserDetail",

  components: {AddUserModuleDilog, ElePagination, MyTable, MyBreadcrumb},
  props:{
    currentOpObj:{

    }
  },
  setup(props,{emit}) {
    const isAddUseRoleDialogIsShow= ref(false)
    const {changeOperation:changeDialogOperation,currentOpObj:currentDialogOpObj,operationType:dialogOperation} = useDetailOrEdit()
    const {pageIndex,pageSize,tableData,totalCount,initSearch,handleSizeChange,refEl}  = usePagination(getTableData)
    const store = useRootStore()
    function successAddUser(){
      isAddUseRoleDialogIsShow.value = false
      getTableData()
    }
    function openSetUserDialog(item){
      isAddUseRoleDialogIsShow.value = true
      changeDialogOperation('add',{})
    }
    function delUser(data){
      if(+store.userInfo.ptjk_role === 1 && +data.USERID === 1){
        elAlert('不能删除超级管理员!')
      }else {
        let url = +props.ROLE_TYPE === 0?delRoleUserInfoSpace:delRoleUserInfoZw
        let params = {
          a_role_id:props.currentOpObj.ROLE_ID,
          a_userid:data.USERID,
          ROLE_TYPE:props.currentOpObj.ROLE_TYPE,
          appkey:new UserInfo().GetUserKeyCode()
        }


        showConfirm(() => {
          url(params).then(res => {
            handleMes(res,() => {
              getTableData()
            })
          })

          // delUser()

        },'确定要删除吗','系统提示',{
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
      }
      // USERID
    }

    const myBread = [
      {name:'权限管理'},
      {name:'设置用户'},
    ]
    function getTableData(){
      let url = props.currentOpObj.ROLE_TYPE === '0'?getUserInfoKj:getUserInfoZw
      url({
        "pageIndex": pageIndex.value,
        "pageSize": pageSize.value,
        "a_role_id": props.currentOpObj.ROLE_ID,
        appkey:new UserInfo().GetUserKeyCode()
      }).then(res =>{
        tableData.value = res.msg[0].Rows
        totalCount.value = res.msg[0].TotalRowCount
      })
    }
    onBeforeMount(() => {

    })
    return {
      myBread,
      useRootStore,
      rootManageUserDetailTableHeader,
      rootManageUserDetailTableHeaderSpace,
      delUser,
      pageIndex,pageSize,tableData,totalCount,initSearch,handleSizeChange,refEl,
      changeDialogOperation,currentDialogOpObj,dialogOperation,
      isAddUseRoleDialogIsShow,
      openSetUserDialog,
      successAddUser
    }
  }
}
</script>

<style scoped lang="scss">
.my-detail-main{
  margin-top: 20px;
}
.fa-trash{
  font-size: 24px;
}
.fa-plus{

  margin-right: 12px;
}
</style>
