<template>
  <div class="warrper">
    <div class="pt32l24">
      <div class="gotoButton" @click="gotoCLick"><i class="gotoIcon"></i>返回</div>
      <div class="schoolpt24">
        <div class="sctitles">菜单管理</div>
        <div class="tableMenu">
          <div class="tableMenuli">菜单名称</div>
          <div class="tableMenuli">菜单类型</div>
          <div class="tableMenuli">可见角色</div>
          <div class="clear"></div>
        </div>
        <div class="menuTableBox">
          <div v-for="(item, i) in meuns" :key="i" class="menuTable">
            <div class="tableMenuSig">
              <div class="tableMenuli" @click="moreDownHandle(item)" v-if="item.more == false"><span v-if="item.url == null"><i class="tablesupIcon"></i></span><span v-else class="noIcon"></span>{{ item.title }}</div>
              <div class="tableMenuli" @click="moreDownHandle(item)" v-else><span v-if="item.url == null"><i class="tablesdownIcon"></i></span><span v-else class="noIcon"></span>{{ item.title }}</div>
              <div class="tableMenuli">{{ item.type }}</div>
              <div class="tableMenuli" v-if="item.role.length != 0"><span v-for="(roleItem, rid) in item.role" :key="rid"> {{ roleItem }} <em v-if="rid < item.role.length - 1">/</em> </span></div>
              <div class="tableMenuli" v-else>-</div>
              <div class="clear"></div>
            </div>
            <div v-if="item.more == true">
              <div v-for="(itemSub, idx) in item.children" :key="idx">
                <div class="tableMenuSigSub">
                  <div class="tableMenuSubli" @click="subDownHandle(itemSub)" v-if="itemSub.more == false"><span class="spanlis28"><span v-if="itemSub.url == null"><i class="tablesupIcon"></i></span><span v-else class="noIcon"></span>{{ itemSub.title }}</span></div>
                  <div class="tableMenuSubli" @click="subDownHandle(itemSub)" v-else><span class="spanlis28"><span v-if="itemSub.url == null"><i class="tablesdownIcon"></i></span><span v-else class="noIcon"></span>{{ itemSub.title }}</span></div>
                  <div class="tableMenuSubli">{{ itemSub.stype }}</div>
                  <div class="tableMenuSubli" v-if="itemSub.role.length != 0"><span v-for="(roleItemSub, rids) in itemSub.role" :key="rids"> {{ roleItemSub }} <em v-if="rids < itemSub.role.length - 1">/</em> </span></div>
                  <div class="tableMenuSubli" v-else>-</div>
                  <div class="clear"></div>
                </div>
                <div v-if="itemSub.more == true">
                  <div v-for="(itemSmall, index) in itemSub.children" :key="index">
                    <div class="tableMenuSigSubTwe">
                      <div class="tableMenuSubliTwe" ><span class="spanlis84">{{ itemSmall.title }}</span></div>
                      <div class="tableMenuSubliTwe">{{ itemSmall.stype }}</div>
                      <div class="tableMenuSubliTwe" v-if="itemSmall.role.length != 0"><span v-for="(roleItemSmall, ridss) in itemSmall.role" :key="ridss"> {{ roleItemSmall }} <em v-if="ridss < itemSmall.role.length - 1">/</em> </span></div>
                      <div class="tableMenuSubliTwe" v-else>-</div>
                      <div class="clear"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { permissionList } from '../../axios/api'
export default {
  name: 'menulist',
  data () {
    return {
      meuns: [
        {
          url: null,
          route: '',
          path: '',
          title: '基础信息采集（必选其一）',
          type: '主菜单',
          name: 'basicinfocoll',
          role: [],
          meun: false,
          more: false,
          children: [
            {
              url: 'schoolscale',
              route: 'schoolscale',
              path: 'schoolscale',
              name: 'admin:school',
              stype: '二级菜单',
              title: '1.1 学校基础信息采集量表',
              role: [],
              meun: false
            },
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:school-equipment',
              stype: '二级菜单',
              title: '1.2 学校设备信息采集量表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:monitor_equipment_collection',
                  stype: '三级菜单',
                  title: '1.2.1 监控设备采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:fql_equipment_collection',
                  stype: '三级菜单',
                  title: '1.2.2 防欺凌设备信息采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:emotion_equipment_collection',
                  stype: '三级菜单',
                  title: '1.2.3 情绪识别设备采集量表',
                  role: [],
                  meun: false
                }
              ]
            },
            {
              url: 'schoolscale',
              route: 'schoolscale',
              path: 'schoolscale',
              name: 'admin:school_people_info',
              stype: '二级菜单',
              title: '1.3 学校人员基础信息采集量表',
              role: [],
              meun: false
            },
            {
              url: 'schoolscale',
              route: 'schoolscale',
              path: 'schoolscale',
              name: 'admin:ql_committee_collection',
              stype: '二级菜单',
              title: '1.4 学生欺凌委员会信息采集量表',
              role: [],
              meun: false
            },
            {
              url: 'schoolscale',
              route: 'schoolscale',
              path: 'schoolscale',
              name: 'admin:regulations_system_collection',
              stype: '二级菜单',
              title: '1.5 学校规章制度采集量表',
              role: [],
              meun: false
            },
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:preventive-work-advance',
              stype: '二级菜单',
              title: '1.6 常态工作-事前预防工作统计表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:beforehand_prevention_collection',
                  stype: '三级菜单',
                  title: '1.6.1 日常管制刀具工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:fql_training_collection',
                  stype: '三级菜单',
                  title: '1.6.2 反欺凌相关培训工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:health_education_topic',
                  stype: '三级菜单',
                  title: '1.6.3 德育教育工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:legal_safety_education',
                  stype: '三级菜单',
                  title: '1.6.4 法治安全教育工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:safety_health_education',
                  stype: '三级菜单',
                  title: '1.6.5 生命安全健康教育工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:psychology_tutoring_education',
                  stype: '三级菜单',
                  title: '1.6.6 心理辅导教育工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:student_file_collection',
                  stype: '三级菜单',
                  title: '1.6.7 学生档案工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:activity_work_collection',
                  stype: '三级菜单',
                  title: '1.6.8 学生组织团体活动工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:jk_xj_collection',
                  stype: '三级菜单',
                  title: '1.6.9 监控室巡检工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:parents_communication_collection',
                  stype: '三级菜单',
                  title: '1.6.10 家长沟通工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:prevention_work_count',
                  stype: '三级菜单',
                  title: '1.6.11 学生促进学校欺凌防治工作采集量表',
                  role: [],
                  meun: false
                }
              ]
            },
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:discover-work-statistics',
              stype: '二级菜单',
              title: '1.7 常态工作-事中发现工作统计表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:feedback_frequency_work',
                  stype: '三级菜单',
                  title: '1.7.1 举报信箱工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:student_communication_work',
                  stype: '三级菜单',
                  title: '1.7.2 学生沟通工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:inspection_work_collection',
                  stype: '三级菜单',
                  title: '1.7.3 区域巡检工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:electronic_equipment_work',
                  stype: '三级菜单',
                  title: '1.7.4 校园反欺凌电子设备工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:action_evaluation_collection',
                  stype: '三级菜单',
                  title: '1.7.5 操行评价工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:stop_action_collection',
                  stype: '三级菜单',
                  title: '1.7.6 学生制止欺凌行为工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:equipment_inspection_work',
                  stype: '三级菜单',
                  title: '1.7.7 反欺凌设备日常巡检相关的工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:appearance_work_collection',
                  stype: '三级菜单',
                  title: '1.7.8 日常仪容仪检查工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:emotion_screen_collection',
                  stype: '三级菜单',
                  title: '1.7.9 学生异常情绪筛查预警工作采集量表',
                  role: [],
                  meun: false
                }
              ]
            },
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:handle-work-statistics',
              stype: '二级菜单',
              title: '1.8 常态工作-事后处理工作统计表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:conflict_log_work',
                  stype: '三级菜单',
                  title: '1.8.1 冲突记录工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:psychological_counseling_collection',
                  stype: '三级菜单',
                  title: '1.8.2 心理辅导工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:action_correction_collection',
                  stype: '三级菜单',
                  title: '1.8.3 行为矫正工作采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:gqt_adjustment_collection',
                  stype: '三级菜单',
                  title: '1.8.4 学生调节矛盾工作采集量表',
                  role: [],
                  meun: false
                }
              ]
            }
          ]
        },
        {
          url: null,
          route: '',
          path: '',
          type: '主菜单',
          title: '常态工作记录（必选其一）',
          name: 'normalwork',
          role: [],
          meun: false,
          more: false,
          children: [
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:record-preventive-behaviors',
              stype: '二级菜单',
              title: '2.1 常态工作-日常预防行为记录表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:dangerous_screening_collection',
                  stype: '三级菜单',
                  title: '2.1.1 管制刀具筛查工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:training_work_log',
                  stype: '三级菜单',
                  title: '2.1.2 反欺凌相关培训工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:dd_fz_xl_course',
                  stype: '三级菜单',
                  title: '2.1.3 德育教育工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:legal_system_education',
                  stype: '三级菜单',
                  title: '2.1.4 法治安全教育工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:life_safety_transfer',
                  stype: '三级菜单',
                  title: '2.1.5 生命安全健康教育工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:psychology_tutor_education',
                  stype: '三级菜单',
                  title: '2.1.6 心理辅导教育工作记录采集量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:student_file_log',
                  stype: '三级菜单',
                  title: '2.1.7 学生档案工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:group_activities_log',
                  stype: '三级菜单',
                  title: '2.1.8 团体活动工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:monitoring_room_log',
                  stype: '三级菜单',
                  title: '2.1.9 监控室日常工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:parents_communication_log',
                  stype: '三级菜单',
                  title: '2.1.10 家长沟通工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:activity_participate_check',
                  stype: '三级菜单',
                  title: '2.1.11 学生校园活动参与抽查表',
                  role: [],
                  meun: false
                }
              ]
            },
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:bullying-discovery-record',
              stype: '二级菜单',
              title: '2.2 常态工作-欺凌发现工作记录表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:reporting_mailbox_work',
                  stype: '三级菜单',
                  title: '2.2.1 举报信箱工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:student_communication_log',
                  stype: '三级菜单',
                  title: '2.2.2 学生沟通工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:inspection_area_log',
                  stype: '三级菜单',
                  title: '2.2.3 区域巡检工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:fql_electronic_log',
                  stype: '三级菜单',
                  title: '2.2.4 校园反欺凌电子设备工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:operation_evaluation_log',
                  stype: '三级菜单',
                  title: '2.2.5 操行评价工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:stop_fql_behavior',
                  stype: '三级菜单',
                  title: '2.2.6 学生参与制止欺凌行为抽查表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:equipment_inspection_record',
                  stype: '三级菜单',
                  title: '2.2.7 反欺凌设备日常巡检维护工作记录表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:fql_discovery_work',
                  stype: '三级菜单',
                  title: '2.2.8 日常仪容仪表检查工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:work_record_emotional',
                  stype: '三级菜单',
                  title: '2.2.9 情绪预警筛查工作记录量表',
                  role: [],
                  meun: false
                }
              ]
            },
            {
              url: null,
              route: '',
              path: '',
              name: 'admin:handle-work-records',
              stype: '二级菜单',
              title: '2.3 常态工作-事后处理工作记录表',
              role: [],
              meun: false,
              more: false,
              children: [
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:conflict_record_scale',
                  stype: '三级菜单',
                  title: '2.3.1 冲突记录工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:psychological_counseling_work',
                  stype: '三级菜单',
                  title: '2.3.2 心理辅导工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:behavior_correction_record',
                  stype: '三级菜单',
                  title: '2.3.3 行为矫正工作记录量表',
                  role: [],
                  meun: false
                },
                {
                  url: '',
                  route: '',
                  path: '',
                  name: 'admin:solve_conflicts_among',
                  stype: '三级菜单',
                  title: '2.3.4 学生解决同学冲突情况周查表',
                  role: [],
                  meun: false
                }
              ]
            }
          ]
        },
        {
          url: 'reportcter',
          route: 'reportcter',
          path: 'reportcter',
          type: '主菜单',
          title: '上报中心',
          name: 'reportcter',
          role: [],
          meun: false
        },
        {
          url: null,
          route: '',
          path: '',
          title: '权限管理',
          name: 'permissionMassage',
          type: '主菜单',
          role: [],
          meun: false,
          more: false,
          children: [
            {
              url: 'userlist',
              route: 'userlist',
              path: 'userlist',
              name: 'userlist',
              stype: '二级菜单',
              title: '用户管理',
              role: [],
              meun: false
            },
            {
              url: 'rolelist',
              route: 'rolelist',
              path: 'rolelist',
              name: 'rolelist',
              stype: '二级菜单',
              title: '角色管理',
              role: [],
              meun: false
            },
            {
              url: 'menulist',
              route: 'menulist',
              path: 'menulist',
              name: 'menulist',
              stype: '二级菜单',
              title: '菜单管理',
              role: [],
              meun: false
            }
          ]
        },
        {
          url: 'messagecent',
          route: 'messagecent',
          path: 'messagecent',
          title: '消息中心',
          type: '主菜单',
          name: 'messagecent',
          role: [],
          meun: false
        },
        {
          url: 'schoolInfo',
          route: 'schoolInfo',
          path: 'schoolInfo',
          type: '主菜单',
          title: '学校基本信息',
          name: 'schoolInfo',
          role: [],
          meun: false
        },
        {
          url: 'apipage',
          route: 'apipage',
          path: 'apipage',
          name: 'apipage',
          type: '主菜单',
          title: 'api文档',
          role: [],
          meun: false
        }
      ]
    }
  },
  created () {
    let that = this    
    if (navigator.onLine) {      
    } else {
      that.$messageOne({message: '网络异常，请检测网络是否链接！', type: 'error', duration: 3000})
      return
    }
    permissionList().then(res => {
      if (res.code == 10000) {
        let datas = res.data
        let array = []
        for (var i = 0; i < datas.length; i++) {
          let sarray = []
          let namRoles = datas[i].roles
          for (var j = 0; j < namRoles.length; j++) {
            sarray.push(namRoles[j].name)
          }
          let obj = {}
          obj.name = datas[i].name
          obj.roles = sarray
          array.push(obj)
        }
        console.log('array', array)
        let meunsArray = that.meuns
        for (var i = 0; i < meunsArray.length; i++) {
          let names = meunsArray[i].name
          let childNavs = meunsArray[i].children
          for (var j = 0; j < array.length; j++) {
            let arrNames = array[j].name
            if (names == arrNames) {
              meunsArray[i].role = array[j].roles
            }
          }
          if (childNavs != undefined) {
            for (var s = 0; s < childNavs.length; s++) {
              let childnams = childNavs[s].name
              let childres = childNavs[s].children
              for (var k = 0; k < array.length; k++) {
                let arrNames = array[k].name
                if (childnams == arrNames) {
                  childNavs[s].role = array[k].roles
                }
              }
              if (childres != undefined) {
                for (var n = 0; n < childres.length; n++) {
                  let childresNames = childres[n].name
                  for (var m = 0; m < array.length; m++) {
                    let arrNames = array[m].name
                    if (childresNames == arrNames) {
                      childres[n].role = array[m].roles
                    }
                  }
                }
              }
            }
          }
        }
        that.meuns = meunsArray
      } else if (res.code == 10002) {
        that.$router.push({name: 'Login'})
      } else {
        that.$messageOne({message: res.message, type: 'error', duration: 3000})
      }
    }).catch(error => {
      that.$messageOne({message: error, type: 'error', duration: 3000})
    })
  },
  methods: {
    gotoCLick () {
      this.$router.push({name: 'homes'})
    },
    moreDownHandle (obj) {
      if (obj.url == null) {
        obj.more = !obj.more
      }
    },
    subDownHandle (obj) {
      if (obj.url == null) {
        obj.more = !obj.more
      }
    }
  }
}
</script>
<style scoped>
.schoolpt24{padding:24px 0 300px;}
.schoolpt24 .sctitles{height: 32px;font-weight: bold;font-size: 24px;color: #161617;line-height: 32px;margin-bottom:24px;}
.tableMenu{height: 40px;background: #F7F7F7;border-radius: 2px;padding:0 16px;line-height:40px;}
.tableMenuli{width:32%;float:left;overflow:hidden;font-size: 14px;color: #252526;}
.tableMenuSig{background: #FFFFFF;border-bottom:1px solid #E6E6E6;border-radius: 2px;line-height:48px;padding:0 16px;font-size: 14px;color: #252526;cursor:pointer;}
.menuTableBox{height:800px;overflow:hidden;overflow-y:auto;}
.menuTable .tablesupIcon{background:url('../../assets/icon31.png') no-repeat 0 0/100%;width:20px;height:20px;display:inline-block;margin-right:8px;position:relative;top:4px;}
.menuTable .tablesdownIcon{background:url('../../assets/icon30.png') no-repeat 0 0/100%;width:20px;height:20px;display:inline-block;margin-right:8px;position:relative;top:4px;}
.menuTable .noIcon{width:20px;height:20px;display:inline-block;margin-right:8px;}
.tableMenuSigSub{background: #FFFFFF;border-bottom:1px solid #E6E6E6;border-radius: 2px;line-height:48px;padding:0 16px;font-size: 14px;color: #252526;cursor:pointer;}
.tableMenuSigSubTwe{background: #FFFFFF;border-bottom:1px solid #E6E6E6;border-radius: 2px;line-height:48px;padding:0 16px;font-size: 14px;color: #252526;cursor:pointer;}
.tableMenuSubli{width:32%;float:left;overflow:hidden;font-size: 14px;color: #252526;}
.tableMenuSubliTwe{width:32%;float:left;overflow:hidden;font-size: 14px;color: #252526;}
.spanlis28{padding-left:28px;}
.spanlis84{padding-left:84px;}
</style>
