<template>
  <div style="height: 100%;">
    <PageSingle
      blank_spacing="48px"
      :is_check="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="追加操作权限"
      :is_tool_bar_custom_04="true"
      text_tool_bar_custom_04="设置数据权限"
      :table_name="table_name"
      :filter_data="filter_data"
      @handleCurrentChangeRow="handleCurrentChangeRow"
      @clickCustom01="clickCustom01"
      @clickCustom02="clickCustom02"
      @clickCustom03="clickCustom03"
    ></PageSingle>
    <DialogDoubleTree
      :show_dialog="is_double_add_show"
      title="减少功能菜单"
      table_name="sys_flame_menu"
      ref="ref_add_dialog"
      @dialogClose="dialogAddDoubleClose"
      @dialogConfig="dialogAddDoubleConfig"
    ></DialogDoubleTree>
    <DialogDoubleTree
      :show_dialog="is_double_sub_show"
      title="追加功能菜单"
      table_name="sys_flame_menu"
      ref="ref_sub_dialog"
      @dialogClose="dialogSubDoubleClose"
      @dialogConfig="dialogSubDoubleConfig"
    ></DialogDoubleTree>
  </div>
</template>

<script>
import _ from 'lodash';
import system from '../../../../api/system.js';
export default {
  name: 'Page-sys_user',
  props: {
    // 新建安扭是否可见
    // is_visbile_new: {
    //   type: Boolean,
    //   default: false
    // },
  },
  components: {},
  data() {
    return {
      table_name: 'sys_flame_user',
      filter_data: [],
      is_double_add_show: false,
      is_double_sub_show: false,
      current_row: null,
      current_user_id: '0'
    };
  },
  created() {
    let that = this;
    let routes = this.$router.options.routes;
    console.log('rountes:=====', routes);
  },
  methods: {
    handleCurrentChangeRow(row) {
      let that = this;
      that.current_row = row;
      that.current_user_id = '' + row.flame_id;
    },
    // 自定义一
    clickCustom01() {
      let that = this;
      let commit_data = {
        user_id: that.current_row['flame_id'],
        operation_type: 'add'
      };
      system.call_method('sys_flame_menu', 'getUserMenu', commit_data, res => {
        if (res.result === true) {
          that.is_double_add_show = true;
          that.$refs.ref_add_dialog.setRightData(res.items);
        } else {
          that.$message({
            type: 'error',
            message: '操作失败'
          });
        }
      });
      // that.$emit('clickExport', true);
    },
    dialogAddDoubleClose() {
      let that = this;
      that.is_double_add_show = false;
    },
    dialogAddDoubleConfig(data) {
      let that = this;
      console.log('current_user_id', that.current_user_id, that.current_row['flame_id']);
      let commit_data = {
        user_id: that.current_row['flame_id'],
        menus: _.union(_.map(data, 'flame_id'))
      };
      // 写入
      console.log('confirmDialog---=data', commit_data);
      system.call_method('sys_flame_user_ship_menu', 'AddMenu', commit_data, res => {
        if (res.result === true) {
          that.is_double_add_show = false;
        }
      });
    },
    clickCustom02() {
      let that = this;
      let commit_data = {
        user_id: that.current_row['flame_id'],
        operation_type: 'sub'
      };
      system.call_method('sys_flame_menu', 'getUserMenu', commit_data, res => {
        if (res.result === true) {
          that.is_double_sub_show = true;
          that.$refs.ref_sub_dialog.setRightData(res.items);
        } else {
          that.$message({
            type: 'error',
            message: '操作失败'
          });
        }
      });
    },
    dialogSubDoubleClose() {
      let that = this;
      that.is_double_sub_show = false;
    },
    dialogSubDoubleConfig(data) {
      let that = this;
      console.log('current_user_id', that.current_user_id, that.current_row['flame_id']);
      let commit_data = {
        user_id: that.current_row['flame_id'],
        menus: _.union(_.map(data, 'flame_id'))
      };
      // 写入
      console.log('confirmDialog---=data', commit_data);
      system.call_method('sys_flame_user_ship_menu', 'subMenu', commit_data, res => {
        if (res.result === true) {
          that.is_double_sub_show = false;
        }
      });
    },
    clickCustom03() {
      let that = this;
    }
  }
};
</script>

<style lang="scss" scoped></style>
