<template>
 <div>
   <common-sta-layout
     @addOp="$emit('changeOperation','add')"
     ref="outRef"
     v-model:parent-active-tab="currentActiveTab"
     :table-attrs="{
   'has-operation':(!(+(useRootStore().userInfo.ptjk_role) !==0 || useRootStore().isUserVisiter) || currentActiveTab === 'lm')
   }"
   >
     <template #BROWER_DIR="{data}">

       <span class="cur-point" @click="openModel(data,0)"><img width="24" src="../../../../../../assets/imgs/system/aq.png" alt=""></span>
     </template>
     <template #DATA_DIR="{data}">

       <span class="cur-point"  @click="openModel(data,1)"><img width="24" src="../../../../../../assets/imgs/system/aq.png" alt=""></span>
     </template>
     <template #CONTACT="{data}">

       {{data.CONTACT?decode(data.CONTACT):''}}
     </template>
     <template #TELPHONE="{data}">

       {{data.TELPHONE?decode(data.TELPHONE):''}}
     </template>
     <template #MAIL="{data}">
       {{data.MAIL?decode(data.MAIL):''}}
     </template>
     <template #operation="{data}">
       <slot name="operation" :data="data">
         <template v-if="currentActiveTab !== 'lm'">
           <span class="fa fa-edit my-link cur-point" title="编辑" @click="$emit('changeOperation','edit',data)"></span>
           <span class="fa fa-trash cur-point my-link" title="删除" @click="delUser(data)"></span>
           <span class="cur-point fa fa-check-square-o" @click="validateUser(data)" v-if="+data.IS_IDENTIFY === 1 && data.TYPE === 1 && data.IS_LM === 1"></span>
         </template>
         <template v-else>
           <span class="fa fa-search  cur-point my-link" title="查看状态" @click="$emit('changeOperation','detail',data)"></span>
           <span @click="$emit('changeOperation','checkDetail',data)"  v-if="+useRootStore().userInfo.ptjk_role === 0 && (+data.STATE===0 && +data.IS_IDENTIFY===1 && +data.TYPE===1 && +data.IS_SUPERIOR===1 && +data.IS_LM===0)" class="fa fa-edit  cur-point" title="初审" ></span>

         </template>
       </slot>
     </template>

   </common-sta-layout>
   <template v-if="isDataRootDialogIsShow">
     <data-root-dialog @successChange="successChange" :current-dialog-obj="currentDialogObj" v-model:dialog-visible="isDataRootDialogIsShow"/>
   </template>
 </div>
</template>

<script>
import {decode} from "js-base64";
import CommonStaLayout from "@/components/common/CommonStaLayout.vue";
import {nextTick, onMounted, ref, watch} from "vue";
import {useRootStore} from "@/stores/useStore";
import {
  changeUserManageSpaceVliadate,
  delUserManageSpaceUserSpace,
  delUserManageSpaceUserZw
} from "@/service/system-manage/user-manaeg";
import {UserInfo} from "@/unit/UserInfo";
import {handleMes, showConfirm} from "@/unit/element-ui/tip";
import {delRoleInfo} from "@/service/system-manage/root-manage";
import {deleteProcessTableHomeData} from "@/service/data-gather-watch/process-table";
import DataRootDialog from "@/view/other/c-views/system-manage/system-manage/user-manage/DataRootDialog.vue";
import {useActiveGetTableData, useDetailOrEdit} from "@/unit/use-method/usePagination";

export default {
  name: "UserManageHome",

  components: {DataRootDialog, CommonStaLayout},
  props:{
    parentTab:{

    }
  },
  setup(props,{emit}) {
    const {currentOpObj:currentDialogObj,operationType:dialogOperationType,changeOperation:changeDialogOperation} = useDetailOrEdit()
    function successChange(){
      isDataRootDialogIsShow.value = false
    }
    function openModel(data,systemType){
      isDataRootDialogIsShow.value = true
      changeDialogOperation('edit',{
        ...data,
        systemType:systemType
      })
    }
    const isDataRootDialogIsShow = ref(false)
    function delUser(data){
      showConfirm(() => {
        let url = currentActiveTab.value === 'zw'?delUserManageSpaceUserZw:delUserManageSpaceUserSpace
        url({
          a_code:data.USERID
        }).then(res => {
          handleMes(res,()=>{
            outRef.value.statContent[0]?.getTableListData()
          })
        })

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

    }
    const outRef = ref(null)
    onMounted(() => {
      nextTick(() => {
        useActiveGetTableData(outRef.value.statContent[0]?.getTableListData)
      })
        })
    function validateUser(data){
      showConfirm(() => {
        changeUserManageSpaceVliadate({
          "a_code": data.USERID,
          "a_type": 0,
          "appkey": new UserInfo().GetUserKeyCode()
        }).then(res => {
          handleMes(res,() => {
            outRef.value.statContent[0]?.getTableListData()
          },()=>{},'认证成功','认证失败')
        })
      },'是否确认该用户为认证用户？','系统提示',{
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })

    }
   const currentActiveTab = ref('')
    watch(currentActiveTab,val => {
      emit('update:parentTab',val)
    })
    return {
      currentActiveTab,
      decode,
      useRootStore,
      validateUser,
      outRef,
      delUser,
      openModel,
      isDataRootDialogIsShow,
      currentDialogObj,dialogOperationType,changeDialogOperation,
      successChange
    }
  }
}
</script>

<style scoped lang="scss">

</style>
