<template>
  <common-sta-layout
    ref="outRef"
    @addOp="$emit('changeOperation','roleDetail')"
    :table-attrs="{
   'has-operation':true
 }"
  >
    <template #USERMODULE="{data}">
      <div @click="openModuleDialog(data)"><img src="../../../../../../assets/imgs/system/mk.png" width="24" alt=""></div>
    </template>
    <template #USER="{data}">
      <div @click="toUserDetail(data)"><img src="../../../../../../assets/imgs/system/szyh.png" width="24" alt=""></div>
    </template>
    <template #ROLE_TYPE="{data}">
      {{getRoleType(data.ROLE_TYPE)}}
    </template>
    <template #operation="{data}">
     <template v-if="data.ROLE_NAME === '超级管理员'">

     </template>
      <template v-else-if="+useRootStore().userInfo.ptjk_role !== 0 ||useRootStore().isUserVisiter">

      </template>

      <template v-else-if="data.ROLE_NAME === '平台管理员' || data.ROLE_NAME === '数据管理员' || data.ROLE_NAME === '数据审核员'">

      </template>
      <template v-else>
        <span class="fa fa-trash cur-point my-link" title="删除" @click="delRole(data)"></span>
        <span class="fa fa-pencil cur-point" title="签名验签" v-if="data.B64_CERT"  @click="validName(data)"></span>
      </template>


    </template>
      <template #dialog>
        <template v-if="isModuleDialogIsShow">
          <root-manage-module-dialog @changeUserModule="changeUserModule" :current-op-obj="currentOpObj" v-model:dialog-visible="isModuleDialogIsShow"/>
        </template>
      </template>

  </common-sta-layout>

</template>

<script>
import CommonStaLayout from "@/components/common/CommonStaLayout.vue";
import {nextTick, onBeforeMount, ref} from "vue";
import {delRoleInfo, getAllModuleInfoD} from "@/service/system-manage/root-manage";
import {useRootStore} from "@/stores/useStore";
import RootManageModuleDialog
  from "@/view/other/c-views/system-manage/system-manage/root-manage/RootManageModuleDialog.vue";
import {useActiveGetTableData, useDetailOrEdit} from "@/unit/use-method/usePagination";
import {UserInfo} from "@/unit/UserInfo";
import {handleMes, showConfirm} from "@/unit/element-ui/tip";
import {deleteAppArrangeWatchData} from "@/service/data-process-watch/app-arrange-watch";
import {validNameYq} from "@/service/common/common";

export default {
  name: "RootManageHome",
  components: {RootManageModuleDialog, CommonStaLayout},
  setup(props,{emit}) {

    const outRef = ref(null)

    const {currentOpObj,changeOperation,operationType} = useDetailOrEdit()
    const isModuleDialogIsShow = ref(false)
    function toUserDetail(data){
      emit('changeOperation','userDetail',data)
    }
    function validName(item){
      validNameYq({
        b64OriginData:item.B64_ORIGIN_DATA,
        b64SignedData:item.B64_SIGNED_DATA,
        b64Cert:item.B64_CERT,
      }).then(res => {
        handleMes(res,() => {

        })
      })
    }
    function delRole(data){
      showConfirm(() => {
        delRoleInfo({
          A_ROLE_ID:data.ROLE_ID,
          ROLE_TYPE:data.ROLE_TYPE,
          appkey:new UserInfo().GetUserKeyCode(),
        }).then(res => {
          handleMes(res,() => {
            outRef.value.statContent[0]?.getTableListData()
          })
        })
      },'确定要删除吗','系统提示',{
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })

    }
    function openModuleDialog(item) {
      console.log('带你三撒')
      isModuleDialogIsShow.value = true
      changeOperation('add',item)
    }
    function changeUserModule(){
        isModuleDialogIsShow.value = false
      outRef.value.statContent[0]?.getTableListData()
    }
    onBeforeMount(() => {
      nextTick(() => {
        useActiveGetTableData(outRef.value?.statContent[0]?.getTableListData)
      })
    })
    function getRoleType(value,row,index){
      if(value == "0"){
        return "空间";
      }
      if(value == "1"){
        return "政务";
      }
    }
    return {
      getRoleType,
      openModuleDialog,
      isModuleDialogIsShow,
      currentOpObj,changeOperation,operationType,
      useRootStore,
      changeUserModule,
      outRef,
      delRole,
      toUserDetail,
      validName
    }
  }
}
</script>

<style scoped lang="scss">
.fa{
  font-size: 24px;
}
</style>
