<template>

  <common-sta-layout ref="outRef" @addOp="$emit('changeOperation','add')" v-model:parent-active-tab="parentActiveTab" :table-attrs="{'has-operation':!((+store.userInfo.ptjk_role !== 0) || store.isUserVisiter)}">
    <template #operation="{data}">
      <span class="fa fa-edit my-link cur-point" title="编辑" @click="$emit('changeOperation','edit',data)"></span>
      <span class="fa fa-trash cur-point" title="删除" @click="delUnit(data)"></span>
    </template>
  </common-sta-layout>

</template>

<script>
import CommonStaLayout from "@/components/common/CommonStaLayout.vue";
import {useRootStore} from "@/stores/useStore";
import {useRoute} from "vue-router";
import {onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, ref, watch} from "vue";
import {handleMes, showConfirm} from "@/unit/element-ui/tip";
import {delUserManageSpaceUserSpace, delUserManageSpaceUserZw} from "@/service/system-manage/user-manaeg";
import {delSpaceUserInfo, delUserInfoZw} from "@/service/system-manage/unit-manage/unit-maneg";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

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

    const outRef = ref(null)

    const parentActiveTab = ref('')
    // onBeforeUnmount(() =>{
    //   console.log('创建了')
    //   emit('getTabName',parentActiveTab.value)
    // })
    watch(parentActiveTab,(val) => {
      console.log('不活跃',parentActiveTab.value)
      emit('getTabName',parentActiveTab.value)
    })
    onActivated(() => {
      // console.log('不活跃',parentActiveTab.value)
      // emit('getTabName',parentActiveTab.value)
      outRef.value.statContent[0]?.getTableListData()
    })
    function delUnit(data) {
      showConfirm(() => {
        let url = parentActiveTab.value === 'zw'?delUserInfoZw:delSpaceUserInfo
        url(data.CODE).then(res => {
          handleMes(res,()=>{
            outRef.value.statContent[0]?.getTableListData()
          })
        })

      },'确定要删除吗','系统提示',{
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
    }
    const route = useRoute()
    const store = useRootStore()

    return {
      store,
      parentActiveTab,
      delUnit,
      outRef
    }
  }
}
</script>

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