<template>
  <div style="height: 100%;">
    <PageSingle
      ref="single"
      blank_spacing="48px"
      :is_tree="true"
      :is_check="true"
      :is_delete="true"
      :is_watch="true"
      :is_edit="true"
      :is_tool_bar_custom_01="true"
      text_tool_bar_custom_01="生成页面菜单"
      :is_tool_bar_custom_02="true"
      text_tool_bar_custom_02="配置操作权限"
      :is_tool_bar_custom_03="true"
      text_tool_bar_custom_03="调整菜单"
      :table_name="table_name"
      :filter_data="filter_data"
      @clickCustom01="clickCustom01"
      @clickCustom02="clickCustom02"
      @clickCustom03="clickCustom03"
    ></PageSingle>
    <!-- :ref="ref_tree" -->
    <DialogTreeModify
      ref="ref_tree_single"
      :show_dialog="show_dialog"
      :table_name="table_name"
      :filter_data="filter_data"
      @dialogConfig="dialogConfig"
      @dialogClose="dialogClose"
    ></DialogTreeModify>
    <DialogOperation :show_dialog="show_drawer" @dialogConfig="drawerConfig" @dialogClose="drawerClose"></DialogOperation>
  </div>
</template>
<script>
import system from '../../../../api/system.js';
import DialogOperation from './components/dialog-Operation.vue';
export default {
  name: 'Page-menu',
  props: {
    // 新建安扭是否可见
    // is_visbile_new: {
    //   type: Boolean,
    //   default: false
    // },
  },
  components: {
    DialogOperation
  },
  data() {
    return {
      show_dialog: false,
      table_name: 'sys_flame_menu',
      // filter_data: [{ field_name: 'app_id', field_value: 0 }, { field_name: 'p_uid', field_value: [0,24,26] }]
      filter_data: [],
      show_drawer: false,
      menus: []
    };
  },
  mounted() {
    let that = this;
    console.log('$router===', that.$router.options.routes);

    that.$router.options.routes[1].children.forEach(m => {
      that.menus.push({ path: m.path, menu_name: m.menu_name });
    });
  },
  created() {},
  methods: {
    // 自定义一
    clickCustom01() {
      let that = this;

      let commit_data = {
        data: []
      };
      that.menus.forEach(m => {
        commit_data.data.push({
          menu_name: m.menu_name,
          router: m.path.replace('/', '')
        });
      });
      console.log('aaaa=clickCustom01', commit_data);
      system.batchAdd(that.table_name, commit_data, res => {
        // console.log(res);
        if (res.result === true) {
          that.$message({
            type: 'success',
            message: '操作成功'
          });
        } else {
          that.$message({
            type: 'error',
            message: '操作失败'
          });
        }
      });
      // that.$message({
      //   type: 'info',
      //   message: '目前还没有实现改功能'
      // });
      // that.$emit('clickExport', true);
    },
    // 自定义操作2
    clickCustom02() {
      let that = this;
      that.show_drawer = true;
      // that.$message({
      //   type: 'info',
      //   message: '目前还没有实现改功能'
      // });
      // that.$emit('clickCustom02', true);
    },
    // 自定义操作3
    clickCustom03() {
      let that = this;
      that.show_dialog = true;
      // that.$message({
      //   type: 'info',
      //   message: '目前还没有实现改功能1111'
      // });
      // that.$emit('clickCustom03', true);
    },
    dialogClose() {
      let that = this;
      that.show_dialog = false;
    },
    dialogConfig(val) {
      let that = this;
      that.show_dialog = false;
      let treeData = val;
      console.log('treeData', treeData);
      let commit_data = { data: treeData };
      system.batchUpdateInstance(that.table_name, commit_data, res => {
        console.log('res', res);
        if (res.result === true) {
          // that.reloadFrame();
          that.$refs.single.reloadData(true);
          that.$message({
            type: 'success',
            message: '操作成功'
          });
        } else {
          that.$message({
            type: 'error',
            message: '操作失败'
          });
        }
      });
    },
    drawerClose() {
      let that = this;
      that.show_drawer = false;
    },
    drawerConfig() {
      let that = this;
      that.show_drawer = false;
    }
  }
};
</script>

<style lang="scss" scoped>
.sys-user {
}
</style>
