<template>
<div class="position-re">
  <div class="m-t">
    <el-tabs v-model="activeTab">
      <el-tab-pane label="模块管理" name="mk">
        <transition name="fade">

        </transition>

      </el-tab-pane>
    </el-tabs>
  </div>
  <div class="add" @click="$emit('changeOperation','add')" v-if="+useRootStore().userInfo.ptjk_role === 0">
    <span class="fa fa-plus"></span>
    <span class="n" >新增</span>
  </div>
   <div class="my-detail-main">
     <my-table
       :each-tr-height="40"
       :is-has-order="false"
       :has-operation="true"
       border
       operation-width="360px"
       row-key="id"

       :tree-props="{ children: 'children',hasChildren:'hasChildren'}"
       :headers="moduleHomeTableHeader"

       :table-data="tableData"

     >
      <template #operation="{data}" >
        <template v-if="data.type !== 'BT'">
          <el-button type="info" size="small" :icon="Document" @click="$emit('changeOperation','detail',data)">详情</el-button>
          <el-button type="info" size="small" :icon="Plus"  @click="$emit('changeOperation','add',data)">新增</el-button>
          <el-button type="info" size="small" :icon="Edit"  @click="$emit('changeOperation','edit',data)">修改</el-button>
          <el-button type="info" size="small" :icon="Delete" @click="delRoleD(data)">删除</el-button>
        </template>
      </template>
     </my-table>
   </div>
</div>
</template>

<script>
import CommonStaLayout from "@/components/common/CommonStaLayout.vue";
import {onBeforeMount, ref} from "vue";
import MyTable from "@/components/common/MyTable.vue";
import {moduleHomeTableHeader} from "@/data/all-table-header";
import {getModuleHomeTableData} from "@/service/system-manage/module-manage";
import {handleLeftMenu4} from "@/data/handleLayer";
import {Delete, Edit, Plus,Document} from "@element-plus/icons-vue";
import {useRootStore} from "@/stores/useStore";
import {handleMes, showConfirm} from "@/unit/element-ui/tip";
import {deleteProcessTableHomeData} from "@/service/data-gather-watch/process-table";
import {delRoleUser} from "@/service/system-manage/root-manage";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

export default {
  name: "ModuleManageHome",
  computed: {
    Edit() {
      return Edit
    },
    Delete() {
      return Delete
    },
    Plus() {
      return Plus
    },
    Document() {
      return Document
    },
  },
  components: {MyTable, CommonStaLayout},
  setup() {
    useActiveGetTableData(getTableList)
    function delRoleD(data){
      showConfirm(() => {
        delRoleUser(data.id).then(res => {
          handleMes(res,() => {
            getTableList()
          },()=>{})
        })

      },'确定要删除吗','系统提示',{
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
    }
    const activeTab = ref('mk')
    const allOrigin = ref([])
    const tabArr = [
      {name:''}
    ]
    function getTableList(){
      getModuleHomeTableData().then(res => {
        let data = res.msg[0].Rows
        allOrigin.value = data || []
        handleLeftMenu4(data,data)
        tableData.value = data.filter(i => +i.pid === 0)
      })
    }
    onBeforeMount(() => {
      getTableList()
    })
    const tableData = ref([])
    return {
      activeTab,
      tabArr,
      tableData,
      moduleHomeTableHeader,
      delRoleD,
      useRootStore
    }
  }
}
</script>

<style scoped lang="scss">
.add{
  .n{
    margin-left: 3px;
  }
  cursor: pointer;
  position: absolute;
  right: 30px;
  top: 20px;
  font-size: 14px;
}
.m-t{
  padding-top:15px;
  padding-left: 15px;
}
</style>
