<template>
  <el-dialog
    :title="buttons.menuList || '菜单列表'"
    @close="close"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <div class="mod-menu">
      <el-table
        :data="dataList"
        v-loading="dataListLoading"
        border
        :height="tableHeight"
        style="width: 100%; ">
        <el-table-column
          prop="name"
          header-align="center"
          min-width="150"
          :label="buttons.name || '名称'">
        </el-table-column>
        <el-table-column
          prop="parentName"
          header-align="center"
          align="center"
          width="120"
          :label="buttons.parentName || '上级菜单'">
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          :label="buttons.icon || '图标'">
          <template slot-scope="scope">
            <icon-svg :name="scope.row.icon || ''"></icon-svg>
          </template>
        </el-table-column>
        <el-table-column
          prop="type"
          header-align="center"
          align="center"
          :label="buttons.type || '类型'">
          <template slot-scope="scope">
            <el-link v-if="scope.row.type === 0" type="success">{{ buttons.type1 || '目录' }}</el-link>
            <el-link v-else-if="scope.row.type === 1" size="small" type="success">{{ buttons.type2 || '菜单' }}
            </el-link>
            <el-link v-else-if="scope.row.type === 2" size="small" type="info">{{ buttons.type3 || '按钮' }}</el-link>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="150"
          :label="buttons.cz || '操作'">
          <template slot-scope="scope">
            <a v-if="isAuth('sys:oss:all') && scope.row.type === 1 " type="text" size="small"
               @click="helpFileList(scope.row.menuId)">{{ buttons.helpFileList || '帮助文档' }}</a>
          </template>
        </el-table-column>
      </el-table>

      <FileList ref="helpFileList" v-if="helpFileVisible"></FileList>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="visible = false">{{ buttons.close || '关闭' }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  searchFunctionButtonList,
} from "@/api/sysLanguage.js"
import FileList from '../common/file-list'
import {treeDataTranslate} from '@/utils'

export default {
  data() {
    return {
      // height: 450,
      dataForm: {},
      dataList: [],
      tableHeight: 0,
      visible: false,
      dataListLoading: false,
      addOrUpdateVisible: false,
      menuLanguageVisible: false,
      helpFileVisible: false,
      buttons: {
        menuList: '菜单列表',
        name: '名称',
        cz: '操作',
        upload: '上传',
        delete: '删除',
        fileDownload: '下载',
        deleteList: '批量删除',
        helpFileList: '帮助文档',
        parentName: '上级菜单',
        icon: '图标',
        type: '类型',
        type1: '目录',
        type2: '菜单',
        type3: '按钮',
        close: '关闭'
      },
    }
  },
  components: {
    FileList
  },
  activated() {
    this.getDataList()
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = (window.innerHeight * 0.65);
    })
  },
  methods: {
    // 获取button的词典
    getFunctionButtonList() {
      let queryButton = {
        functionId: this.$route.meta.menuId,
        tableId: '*',
        languageCode: this.$i18n.locale,
        objectType: 'button'
      }
      searchFunctionButtonList(queryButton).then(({data}) => {
        if (data.code == 0 && data.data) {
          this.buttons = data.data
        }
      })
    },
    init() {
      this.visible = true
      this.getDataList()
    },
    getDataList() {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/sys/menu/list/' + this.$i18n.locale),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({data}) => {
        this.dataList = data.filter(item => item.type === 1 && item.menuType === 'pc')
        this.dataListLoading = false
      })
    },
    // 帮助文档列表
    helpFileList(val) {
      let fileMappingDto = {
        fileId: '',
        fileType: '功能帮助文档',
        orderRef1: val,
        orderRef2: '*',
        orderRef3: '*',
      }
      this.helpFileVisible = true;
      this.$nextTick(() => {
        this.$refs.helpFileList.init(fileMappingDto)
      })
    },
    close() {
      this.dataList = []
    }
  },
  created() {
    this.getFunctionButtonList()
  }
}
</script>
