<template>
  <div id="menuManagement">
    <Breadcrumb separator=">" class="bread">
      <BreadcrumbItem>系统管理</BreadcrumbItem>
      <BreadcrumbItem>菜单管理</BreadcrumbItem>
    </Breadcrumb>
    <Tabs type="card" v-model="tabName">
      <TabPane label="平台菜单" name="platform">
        <div class="topBox">
          <div class="topItem">
            <span>菜单名称:</span>
            <Input type="text" placeholder="请输入菜单名称" v-model="platform.name" style="width: 200px"/>
          </div>
          <div class="topItem">
            <span>菜单编号:</span>
            <Input type="text" placeholder="请输入菜单编号" v-model="platform.code" style="width: 200px"/>
          </div>
          <div class="topItem">
            <span>菜单分类:</span>
            <Select v-model="platform.category" style="width:200px" placeholder="请选择菜单分类">
              <Option v-for="item in categoryList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="topItem">
            <span>菜单类型:</span>
            <Select v-model="platform.type" style="width:200px" placeholder="请选择菜单类型">
              <Option v-for="item in typeList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="topItem">
            <Button type="primary" icon="md-search" @click="platSearchBtn">查询</Button>
            <Button type="primary" ghost icon="ios-undo" @click="resetBtn1">重置</Button>
          </div>
        </div>
        <div class="buttonGroup">
          <ButtonGroup size="large" shape="circle">
            <Button type="primary" ghost icon="md-add" @click="addNewMenu">新增</Button>
          </ButtonGroup>
        </div>
        <div>
          <Table border :columns="platformColumns" :data="platformTable"></Table>
        </div>
        <div class="page">
          <Page :total="platform.pageTotal" placement="top" :current="platform.page" show-total show-elevator show-sizer @on-change="getPlatPages1" @on-page-size-change="getPlatPages2"/>
        </div>
      </TabPane>
      <!-- <TabPane label="合作伙伴菜单" name="partner" v-if="partMenuBtn">
        <div class="topBox">
          <div class="topItem">
            <span>菜单名称:</span>
            <Input type="text" placeholder="请输入菜单名称" v-model="partner.name" style="width: 200px"/>
          </div>
          <div class="topItem">
            <span>菜单编号:</span>
            <Input type="text" placeholder="请输入菜单编号" v-model="partner.code" style="width: 200px"/>
          </div>
          <div class="topItem">
            <span>菜单分类:</span>
            <Select v-model="partner.category" style="width:200px" placeholder="请选择菜单分类">
              <Option v-for="item in categoryList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="topItem">
            <span>菜单类型:</span>
            <Select v-model="partner.type" style="width:200px" placeholder="请选择菜单类型">
              <Option v-for="item in typeList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="topItem">
            <Button type="primary" icon="md-search" @click="partSearchBtn">查询</Button>
            <Button type="primary" ghost icon="ios-undo" @click="partResetBtn">重置</Button>
          </div>
        </div>
        <div class="buttonGroup">
          <ButtonGroup size="large" shape="circle">
            <Button type="primary" ghost icon="md-add" v-if="partMenuAddBtn" @click="addPartnerMenu">新增</Button>
          </ButtonGroup>
        </div>
        <div>
          <Table border :height="tableHeight" :columns="partnerColumns" :data="partnerTable"></Table>
        </div>
        <div class="page">
          <Page :total="partner.pageTotal" placement="top" :current="partner.page" show-total show-elevator show-sizer @on-change="getPartPages1" @on-page-size-change="getPartPages2"/>
        </div>
      </TabPane> -->
      <!-- <TabPane label="医院菜单管理" name="clinic" v-if="clinicMenuBtn">
         <div class="topBox">
          <div class="topItem">
            <span>菜单名称:</span>
            <Input type="text" placeholder="请输入菜单名称" v-model="clinic.name" style="width: 200px"/>
          </div>
          <div class="topItem">
            <span>菜单编号:</span>
            <Input type="text" placeholder="请输入菜单编号" v-model="clinic.code" style="width: 200px"/>
          </div>
          <div class="topItem">
            <span>菜单分类:</span>
            <Select v-model="clinic.category" style="width:200px" placeholder="请选择菜单分类">
              <Option v-for="item in categoryList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="topItem">
            <span>菜单类型:</span>
            <Select v-model="clinic.type" style="width:200px" placeholder="请选择菜单类型">
              <Option v-for="item in typeList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div class="topItem">
            <Button type="primary" icon="md-search" @click="clinicSearchBtn">查询</Button>
            <Button type="primary" ghost icon="ios-undo" @click="clinicResetBtn">重置</Button>
          </div>
        </div>
        <div class="buttonGroup">
          <ButtonGroup size="large" shape="circle">
            <Button type="primary" ghost icon="md-add" v-if="clinicMenuAddBtn" @click="addClinicMenu">新增</Button>
          </ButtonGroup>
        </div>
        <div>
          <Table border :height="tableHeight" :columns="clinicColumns" :data="clinicTable"></Table>
        </div>
        <div class="page">
          <Page :total="clinic.pageTotal" placement="top" :current="clinic.page" show-total show-elevator show-sizer @on-change="getClinicPages1" @on-page-size-change="getClinicPages2"/>
        </div>
      </TabPane> -->
    </Tabs>
    <!--弹出框-->
    <div class="addRole" v-show="showModel1">
      <div class="modelBox">
        <p class="modelTitle">
          <span>{{showTitle1}}</span>
          <span class="exit" @click="cancelAdd"><Icon type="md-close" /></span>
        </p>
        <div class="roleMsg">
          <div><span>菜单分类:</span>
            <Select v-model="plat.category" style="width:220px" placeholder="请选择菜单分类">
              <Option v-for="item in categoryList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
           <div><span>菜单类型:</span>
            <Select v-model="plat.type" style="width:220px" placeholder="请选择菜单类型">
              <Option v-for="item in typeList" :value="item.code" :key="item.code">{{ item.name }}</Option>
            </Select>
          </div>
          <div><span>菜单编码:</span>
            <Input type="text" v-model="plat.code" style="width: 220px;"/>
          </div>
          <div><span>菜单地址:</span>
            <Input type="text" v-model="plat.href" style="width: 220px;"/>
          </div>
          <div><span>菜单图标:</span>
            <Input type="text" v-model="plat.icon" style="width: 220px;"/>
          </div>
          <div><span>菜单名称:</span>
            <Input type="text" v-model="plat.name" style="width: 220px;"/>
          </div>
          <div><span>菜单排序:</span>
            <Input type="text" v-model="plat.orderNum" style="width: 220px;" placeholder="请输入整数"/>
          </div>
          <div><span>父级菜单:</span>
            <Input type="text" v-model="plat.parentName" disabled style="width: 220px;"/>
          </div>
          <div class="remark"><span>备注:</span><Input type="textarea" :rows="4" v-model="plat.remark"/></div>
        </div>
        <div class="buttons">
          <Button type="primary" ghost @click="cancelAdd">取消</Button>
          <Button type="primary" @click="confirmBtn">确定</Button>
        </div>
      </div>
    </div>
    <!--删除确认框-->
    <Modal v-model="delMsg" :closable="false" :mask-closable="false" width="400" scrollable>
      <p slot="header" style="height:40px;lineHeight:40px;backgroundColor:#ED4014;color:#fff;text-align:center">
        <span>删除</span>
      </p>
      <p>确定删除 <b>"{{delMsgName}}"</b> 这一条信息吗？</p>
      <div slot="footer">
        <Button type="error" ghost @click="platCancelDel">关闭</Button>
        <Button type="error" @click="sureDel">确定</Button>
      </div>
    </Modal>
  </div>
</template>
<script>
  import axios from './../../assets/js/axios';
  import { getTableHeight } from '../../tools/tools'
    export default {
        name: "menuManagement",
        data(){
          return{
            tableHeight:'',
            id:'',//页面id
            tabName:'',
            platMenuBtn:false,
            platMenuAddBtn:false,
            partMenuBtn:false,
            partMenuAddBtn:false,
            clinicMenuBtn:false,
            clinicMenuAddBtn:false,
            platform:{
              page:1,
              pageSize:10,
              pageTotal:0,
              name:'',
              type:'',
              code:'',
              category:'',
            },
            plat:{
              category:'',
              code:'',
              href:'',
              icon:'',
              name:'',
              orderNum:'',
              parentId:'',
              parentName:'',
              type:'',
              remark:''
            },
            categoryList:[],
            typeList:[],
            delMsg:false,
            delId:'',
            delMsgName:'',
            delBtn:'',
            showModel1:false,
            showTitle1:'',
            sureBtn:'',//确定按钮
            platformColumns: [{title: '菜单名称', key: 'name'},
              {title: '菜单编号', key: 'code'},
              {title: '菜单分类', key: 'category'},
              {title: '菜单类型', key: 'type'},
              {title: '菜单顺序', key: 'orderNum',sortable: true},
              {title: '菜单地址', key: 'href'},
              {title: '状态',key: 'action',align: 'center',width:100,
                render:(h, params) => {
                  return h('div', [
                    h('i-switch', { //数据库1是已处理，0是未处理
                      props: {
                        type: 'primary',
                        value: params.row.enabled==1?true:false,//控制开关的打开或关闭状态，官网文档属性是value
                      },
                      on: {
                        'on-change': (value) => {//触发事件是on-change,用双引号括起来，
                          //参数value是回调值，并没有使用到
                          this.switch1(params.row.id,params.row.enabled); //params.index是拿到table的行序列，可以取到对应的表格值
                        }
                      }
                    }, )])}
              },
              {title: '操作', key: 'action', width: 220,align: 'center',
                render: (h, params) => {
                  let _this=this;
                  let showPlatEditBtn=false;
                  let showPlatResBtn=false;
                  let showPlatRemoveBtn=false;
                  for(let i of _this.tableBtnBox){
                    if(i.code=="platformMenuEdit"){
                      showPlatEditBtn=true;
                    }
                    if(i.code=="platformMenuResource"){
                      showPlatResBtn=true;
                    }
                    if(i.code=="platformMenuRemove"){
                      showPlatRemoveBtn=true;
                    }
                  }
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px',
                        display:showPlatEditBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.showPlatEditor(params.row.id);
                        }
                      }
                    }, '编辑'),
                    h('Button', {
                      props: {
                        type: 'success',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px',
                        display:_this.platMenuAddBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.addNew(params.row.id,params.row.name);
                        }
                      }
                    }, '新增'),
                  //   h('Button', {
                  //   props: {
                  //     type: 'success',
                  //     size: 'small'
                  //   },
                  //   style: {
                  //     marginRight: '5px',
                  //     display:showPlatResBtn?'inline-block':'none'
                  //   },
                  //   on: {
                  //     click: () => {
                  //       this.platResource(params.row.id);
                  //     }
                  //   }
                  // }, '资源'),
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      style:{
                        display:showPlatRemoveBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.platRemove(params.row.id,params.row.name);
                        }
                      }
                    }, '删除'),
                  ]);
                }
              }
            ],
            platformTable: [],
            /*合作伙伴平台*/
            partner:{
              page:1,
              pageSize:10,
              pageTotal:0,
              name:'',
              type:'',
              code:'',
              category:'',
            },
            partnerColumns:[{title: '菜单名称', key: 'name'},
              {title: '菜单编号', key: 'code'},
              {title: '菜单分类', key: 'category'},
              {title: '菜单类型', key: 'type'},
              {title: '菜单顺序', key: 'orderNum',sortable: true},
              {title: '菜单地址', key: 'href'},
              {title: '状态',key: 'action',align: 'center',width:100,
                render:(h, params) => {
                  return h('div', [
                    h('i-switch', { //数据库1是已处理，0是未处理
                      props: {
                        type: 'primary',
                        value: params.row.enabled==1?true:false,//控制开关的打开或关闭状态，官网文档属性是value
                      },
                      on: {
                        'on-change': (value) => {//触发事件是on-change,用双引号括起来，
                          //参数value是回调值，并没有使用到
                          this.switch2(params.row.id,params.row.enabled); //params.index是拿到table的行序列，可以取到对应的表格值
                        }
                      }
                    }, )])}
              },
              {title: '操作', key: 'action', width: 220,align: 'center',
                render: (h, params) => {
                  let _this=this;
                  let showPartEditBtn=false;
                  let showPartResBtn=false;
                  let showPartRemoveBtn=false;
                  for(let i of _this.tableBtnBox){
                    if(i.code=="partMenuEdit"){showPartEditBtn=true;}
                    if(i.code=="partMenuResource"){showPartResBtn=true;}
                    if(i.code=="partMenuRemove"){showPartRemoveBtn=true;}
                  }
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px',
                        display:showPartEditBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.showPartnerEditor(params.row.id);
                        }
                      }
                    }, '编辑'),
                    h('Button', {
                      props: {
                        type: 'success',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px',
                        display:_this.partMenuAddBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.addPartner(params.row.id,params.row.name);
                        }
                      }
                    }, '新增'),
                    h('Button', {
                    props: {
                      type: 'success',
                      size: 'small'
                    },
                    style: {
                      marginRight: '5px',
                      display:showPartResBtn?'inline-block':'none'
                    },
                    on: {
                      click: () => {
                        this.partnerResource(params.row.id);
                      }
                    }
                  }, '资源'),
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      style:{
                        display:showPartRemoveBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.partnerRemove(params.row.id,params.row.name);
                        }
                      }
                    }, '删除'),
                  ]);
                }
              }
            ],
            partnerTable:[],
            /*医院菜单*/
            clinic:{
              page:1,
              pageSize:10,
              pageTotal:0,
              name:'',
              type:'',
              code:'',
              category:'',
            },
            clinicColumns:[{title: '菜单名称', key: 'name'},
              {title: '菜单编号', key: 'code'},
              {title: '菜单分类', key: 'category'},
              {title: '菜单类型', key: 'type'},
              {title: '菜单顺序', key: 'orderNum',sortable: true},
              {title: '菜单地址', key: 'href'},
              {title: '状态',key: 'action',align: 'center',width:100,
                render:(h, params) => {
                  return h('div', [
                    h('i-switch', { //数据库1是已处理，0是未处理
                      props: {
                        type: 'primary',
                        value: params.row.enabled==1?true:false,//控制开关的打开或关闭状态，官网文档属性是value
                      },
                      on: {
                        'on-change': (value) => {
                          this.switch3(params.row.id,params.row.enabled); 
                        }
                      }
                    }, )])}
              },
              {title: '操作', key: 'action', width: 220,align: 'center',
                render: (h, params) => {
                  let _this=this;
                  let showClinicEditBtn=false;
                  let showClinicResBtn=false;
                  let showClinicRemoveBtn=false;
                  for(let i of _this.tableBtnBox){
                    if(i.code=="clinicMenuEdit"){showClinicEditBtn=true;}
                    if(i.code=="clinicMenuResource"){showClinicResBtn=true;}
                    if(i.code=="clinicMenuRemove"){showClinicRemoveBtn=true;}
                  }
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px',
                        display:showClinicEditBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.showClinicEditor(params.row.id);
                        }
                      }
                    }, '编辑'),
                    h('Button', {
                      props: {
                        type: 'success',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px',
                        display:_this.clinicMenuAddBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.addClinic(params.row.id,params.row.name);
                        }
                      }
                    }, '新增'),
                    h('Button', {
                    props: {
                      type: 'success',
                      size: 'small'
                    },
                    style: {
                      marginRight: '5px',
                      display:showClinicResBtn?'inline-block':'none'
                    },
                    on: {
                      click: () => {
                        this.clinicResource(params.row.id);
                      }
                    }
                  }, '资源'),
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      style:{
                        display:showClinicRemoveBtn?'inline-block':'none'
                      },
                      on: {
                        click: () => {
                          this.clinicRemove(params.row.id,params.row.name);
                        }
                      }
                    }, '删除'),
                  ]);
                }
              }
            ],
            clinicTable:[],
            tableBtnBox:[],
            currentPage:'',
          }
        },
      created(){
         this.id=this.$route.params.id;
          this.currentPage=this.$route.params.current;
          let detailPage=parseInt(this.currentPage.split("_")[1]);
          if(this.currentPage!=1){
            this.tabName=this.currentPage.split('_')[0];
            if(this.tabName=="platform"){
              this.platform.page=detailPage;
            }else if(this.tabName=="partner"){
              this.partner.page=detailPage;
            }else if(this.tabName=="clinic"){
              this.clinic.page=detailPage;
            }
          }
        window.addEventListener('resize',this.getHeight)
        window.onbeforeunload = this.getHeight()
      },
      destroyed(){
        window.removeEventListener('resize', this.getHeight)
      },
      mounted(){
          this.getMenu();
          this.getButton();
          this.getPage1();
          // this.getPagePartner();
          // this.getPageClinic();
      },
      methods:{
        // getHeight () {
        //   this.tableHeight = getTableHeight(414)
        // },
        /*取出字典项*/
        getMenu(){
          let _this=this;
          _this.selectList=JSON.parse(localStorage.getItem('selectList'));
          let selectList=_this.selectList;
          for(let m of selectList){
            if(m.t=="category"){
              _this.categoryList=m.list;
            }
          }
          for(let m of selectList){
            if(m.t=="menu_type"){
              _this.typeList=m.list;
            }
          }
        },
        /*加载页面按钮*/
        getButton(){
          let msg=JSON.parse(sessionStorage.getItem('userMsg'));
          this.orgId=msg.orgId;
          this.tableBtnBox = JSON.parse(sessionStorage.getItem('nMArr'));
          for (let i of this.tableBtnBox) {
            if (i.code === 'platformMenuSearch') {this.platMenuBtn = true}
            if (i.code === 'partMenuSearch') {this.partMenuBtn = true}
            if (i.code === 'clinicMenuSearch') {this.clinicMenuBtn = true}
            if (i.code === 'platformMenuAdd') {this.platMenuAddBtn = true}
            if (i.code === 'partMenuAdd') {this.partMenuAddBtn = true}
            if (i.code === 'clinicMenuAdd') {this.clinicMenuAddBtn = true}
          }
        },
        /*平台*/
        getPage1(){
          let _this=this;
          axios.post('/platform-upms/menu/page',{
            category:_this.platform.category,
            code:_this.platform.code,
            current:_this.platform.page,
            name:_this.platform.name,
            size:_this.platform.pageSize,
            type:_this.platform.type
          }).then(res=>{
            if(res){
             // console.log(res);
              _this.platform.pageTotal=res.data.data.total;
              let temp=res.data.data.records;
              for(let i of temp){
                for(let j of _this.categoryList){
                  if(i.category==j.code){
                    i.category=j.name;
                  }
                }
                for(let j of _this.typeList){
                  if(i.type==j.code){
                    i.type=j.name;
                  }
                }
              }
              _this.platformTable=temp;
            }
          })
        },
        resetBtn1(){
          this.platform.name='';
          this.platform.type='';
          this.platform.code='';
          this.platform.category='';
          this.getPage1()
        },
        platSearchBtn(){
          this.platformTable=[];
          this.platform.page=1;
          this.getPage1();
        },
        /*页码改变时加载数据*/
        getPlatPages1(current){
          this.platform.page=current;
          this.getPage1();
        },
        /*每页显示多少条改变时加载数据*/
        getPlatPages2(size){
          this.platform.pageSize=size;
          this.getPage1();
        },
        switch1(id,en){
          let _this=this;
          let enabled=en==1?0:1;
          axios.post('/platform-upms/menu/enabled',{
            id:id,
            enabled:enabled
          }).then(res=>{
            if(res){
               _this.$Message.info('操作成功');
            }
          })
        },
        /*新增父类*/
        addNewMenu(){
          this.showModel1=true;
          this.showTitle1='新增菜单';
          this.sureBtn='platMenu';
          this.plat.parentId=0;
        },
        /*新增取消*/
        cancelAdd(){
          this.showModel1=false;
          this.removeMsg();
        },
        /*新增确定*/
        addNewMenuBtn(){
          let _this=this;
          if(_this.plat.category==''){
          _this.$Message.error('菜单类型不能为空');
          return false;
          }
          if(_this.plat.name==''){
            _this.$Message.error('菜单名称不能为空');
            return false;
          }
          if(_this.plat.type==''){
            _this.$Message.error('菜单类型不能为空');
            return false;
          }
          axios.post('/platform-upms/menu/add',{
            category:_this.plat.category,
            code:_this.plat.code,
            href:_this.plat.href,
            icon:_this.plat.icon,
            name:_this.plat.name,
            orderNum:_this.plat.orderNum,
            parentId:_this.plat.parentId,
            remark:_this.plat.remark,
            type:_this.plat.type
          }).then(res=>{
            if(res){
               _this.showModel1=false;
              _this.getPage1();
              _this.removeMsg();
              _this.$Message.info('新增成功');
            }
          })
        },
        /*新增子类*/
        addNew(id,name){
          this.plat.parentId=id;
          this.plat.parentName=name;
          this.showModel1=true;
          this.showTitle1='新增菜单';
          this.sureBtn='platMenu';
        },
        /*编辑*/
        showPlatEditor(id){
          let _this=this;
          _this.showModel1=true;
          _this.showTitle1='编辑菜单';
          _this.sureBtn='platMenuEdit';
          _this.plat.id=id;
          axios.post('/platform-upms/menu/get',{
            id:_this.plat.id
          }).then(res=>{
            if(res){
              let temp=res.data.data;
              _this.plat.category=temp.category+'',
              _this.plat.code=temp.code,
              _this.plat.href=temp.href,
              _this.plat.icon=temp.icon,
              _this.plat.name=temp.name,
              _this.plat.orderNum=temp.orderNum,
              _this.plat.parentId=temp.parentId,
              _this.plat.remark=temp.remark,
              _this.plat.type=temp.type+'',
              _this.plat.parentName=temp.parentName
            } 
          })
        },
        platEditBtn(){
          let _this=this;
          if(_this.plat.category==''){
          _this.$Message.error('菜单类型不能为空');
          return false;
          }
          if(_this.plat.name==''){
            _this.$Message.error('菜单名称不能为空');
            return false;
          }
          if(_this.plat.type==''){
            _this.$Message.error('菜单类型不能为空');
            return false;
          }
          axios.post('/platform-upms/menu/update',{
            category:_this.plat.category,
            code:_this.plat.code,
            href:_this.plat.href,
            icon:_this.plat.icon,
            name:_this.plat.name,
            orderNum:_this.plat.orderNum,
            remark:_this.plat.remark,
            type:_this.plat.type,
            id:_this.plat.id
          }).then(res=>{
            if(res){
               _this.showModel1=false;
              _this.getPage1();
              _this.removeMsg();
              _this.$Message.info('修改成功');
            }
          })
        },
        /*弹出框确定按钮**/
        confirmBtn(){
          if(this.sureBtn=='platMenu'){
            this.addNewMenuBtn();
          }else if(this.sureBtn=='platMenuEdit'){
            this.platEditBtn();
          }else if(this.sureBtn=='partnerMenu'){
            this.addPartnerMenuBtn();
          }else if(this.sureBtn=='partnerMenuEdit'){
            this.partnerEditBtn();
          }else if(this.sureBtn=='clinicMenu'){
            this.addClinicMenuBtn();
          }else if(this.sureBtn=='clinicMenuEdit'){
            this.clinicEditBtn();
          }

        },
        /*删除*/
        platRemove(id,name){
          this.delMsg=true;
          this.delId=id;
          this.delMsgName=name;
          this.delBtn='delPlatform';
        },
        platSureDel(){
          let _this=this;
          axios.post('/platform-upms/menu/delete',{
            id:_this.delId
          }).then(res=>{
            if(res){
               _this.delMsg=false;
              _this.delId='';
              _this.delMsgName='';
              _this.$Message.info('删除成功');
              _this.getPage1();
            }
          })
        },
        platCancelDel(){
          this.delMsg=false;
          this.delId='';
          this.delMsgName='';
        },
        sureDel(){
          if(this.delBtn=='delPlatform'){
            this.platSureDel();
          }else if(this.delBtn=='delPartner'){
            this.partnerSureDel();
          }else if(this.delBtn=='delClinic'){
            this.clinicSureDel();
          }
        },
        /*清除数据*/
        removeMsg(){
          this.plat.category='';
          this.plat.code='';
          this.plat.href='';
          this.plat.icon='';
          this.plat.name='';
          this.plat.orderNum='';
          this.plat.remark='';
          this.plat.type='';
          this.plat.parentId='';
          this.plat.parentName='';
        },
        /*合作伙伴菜单*/
        getPagePartner(){
          let _this=this;
          axios.post('/partner-upms/menu/page',{
             category:_this.partner.category,
             code:_this.partner.code,
             current:_this.partner.page,
             name: _this.partner.name,
             size:_this.partner.pageSize,
             type: _this.partner.type
          }).then(res=>{
            if(res){
              _this.partner.pageTotal=res.data.data.total;
              let temp=res.data.data.records;
              for(let i of temp){
                for(let j of _this.categoryList){
                  if(i.category==j.code){
                    i.category=j.name;
                  }
                }
                for(let j of _this.typeList){
                  if(i.type==j.code){
                    i.type=j.name;
                  }
                }
              }
              _this.partnerTable=temp;
            }
          })
        },
        getPartPages1(current){
          this.partner.page=current;
          this.getPagePartner();
        },
        getPartPages2(size){
          this.partner.pageSize=size;
          this.getPagePartner();
        },
        partSearchBtn(){//查询
          this.partnerTable=[];
          this.partner.page=1;
          this.getPagePartner();
        },
        partResetBtn(){//重置
          this.partner.name='';
          this.partner.type='';
          this.partner.code='';
          this.partner.category='';
        },
        switch2(id,en){
          let _this=this;
          let enabled=en==1?0:1;
          axios.post('/partner-upms/menu/enabled',{
            id:id,
            enabled:enabled
          }).then(res=>{
            if(res){
               _this.$Message.info('操作成功');
            }
          })
        },
        addPartnerMenu(){//新增父类
          this.showModel1=true;
          this.showTitle1='新增菜单';
          this.sureBtn='partnerMenu';
          this.plat.parentId=0;
        },
        addPartnerMenuBtn(){
          let _this=this;
           if(_this.plat.category==''){
          _this.$Message.error('菜单类型不能为空');
          return false;
          }
          if(_this.plat.name==''){
            _this.$Message.error('菜单名称不能为空');
            return false;
          }
          if(_this.plat.type==''){
            _this.$Message.error('菜单类型不能为空');
            return false;
          }
          axios.post('/partner-upms/menu/add',{
            category:_this.plat.category,
            code:_this.plat.code,
            href:_this.plat.href,
            icon:_this.plat.icon,
            name:_this.plat.name,
            orderNum:_this.plat.orderNum,
            parentId:_this.plat.parentId,
            remark:_this.plat.remark,
            type:_this.plat.type
          }).then(res=>{
            if(res){
               _this.showModel1=false;
              _this.getPagePartner();
              _this.removeMsg();
              _this.$Message.info('新增成功');
            }
          })
        },
        addPartner(id,name){//新增子类
          this.plat.parentId=id;
          this.plat.parentName=name;
          this.showModel1=true;
          this.showTitle1='新增菜单';
          this.sureBtn='partnerMenu';
        },
        showPartnerEditor(id){//编辑
          let _this=this;
          _this.showModel1=true;
          _this.showTitle1='编辑菜单';
          _this.sureBtn='partnerMenuEdit';
          _this.plat.id=id;
          axios.post('/partner-upms/menu/get',{
            id:_this.plat.id
          }).then(res=>{
            if(res){
              let temp=res.data.data;
              _this.plat.category=temp.category+'',
              _this.plat.code=temp.code,
              _this.plat.href=temp.href,
              _this.plat.icon=temp.icon,
              _this.plat.name=temp.name,
              _this.plat.orderNum=temp.orderNum,
              _this.plat.parentId=temp.parentId,
              _this.plat.remark=temp.remark,
              _this.plat.type=temp.type+'',
              _this.plat.parentName=temp.parentName
            }
          })
        },
        partnerEditBtn(){
          let _this=this;
            if(_this.plat.category==''){
          _this.$Message.error('菜单类型不能为空');
          return false;
          }
          if(_this.plat.name==''){
            _this.$Message.error('菜单名称不能为空');
            return false;
          }
          if(_this.plat.type==''){
            _this.$Message.error('菜单类型不能为空');
            return false;
          }
          axios.post('/partner-upms/menu/update',{
            category:_this.plat.category,
            code:_this.plat.code,
            href:_this.plat.href,
            icon:_this.plat.icon,
            name:_this.plat.name,
            orderNum:_this.plat.orderNum,
            remark:_this.plat.remark,
            type:_this.plat.type,
            id:_this.plat.id
          }).then(res=>{
            if(res){
               _this.showModel1=false;
              _this.getPagePartner();
              _this.removeMsg();
              _this.$Message.info('修改成功');
            } 
          })
        },
        partnerRemove(id,name){
          this.delMsg=true;
          this.delId=id;
          this.delMsgName=name;
          this.delBtn='delPartner';
        },
        partnerSureDel(){
          let _this=this;
          axios.post('/partner-upms/menu/delete',{
            id:_this.delId
          }).then(res=>{
            if(res){
               _this.delMsg=false;
              _this.delId='';
              _this.delMsgName='';
              _this.$Message.info('删除成功');
              _this.getPagePartner();
            }
          })
        },
        /*医院菜单 */
        getPageClinic(){
          let _this=this;
          axios.post('/clinic-upms/menu/page',{
             category:_this.clinic.category,
             code:_this.clinic.code,
             current:_this.clinic.page,
             name: _this.clinic.name,
             size:_this.clinic.pageSize,
             type: _this.clinic.type
          }).then(res=>{
            if(res){
               _this.clinic.pageTotal=res.data.data.total;
              let temp=res.data.data.records;
              for(let i of temp){
                for(let j of _this.categoryList){
                  if(i.category==j.code){
                    i.category=j.name;
                  }
                }
                for(let j of _this.typeList){
                  if(i.type==j.code){
                    i.type=j.name;
                  }
                }
              }
              _this.clinicTable=temp;
            }
          })
        },
        getClinicPages1(current){
          this.clinic.page=current;
          this.getPageClinic();
        },
        getClinicPages2(size){
          this.clinic.pageSize=size;
          this.getPageClinic();
        },
        clinicSearchBtn(){//查询
          this.clinicTable=[];
          this.clinic.page=1;
          this.getPageClinic();
        },
        clinicResetBtn(){//重置
          this.clinic.name='';
          this.clinic.type='';
          this.clinic.code='';
          this.clinic.category='';
        },
        addClinicMenu(){//新增父类
          this.showModel1=true;
          this.showTitle1='新增菜单';
          this.sureBtn='clinicMenu';
          this.plat.parentId=0;
        },
        addClinicMenuBtn(){
          let _this=this;
           if(_this.plat.category==''){
          _this.$Message.error('菜单类型不能为空');
          return false;
          }
          if(_this.plat.name==''){
            _this.$Message.error('菜单名称不能为空');
            return false;
          }
          if(_this.plat.type==''){
            _this.$Message.error('菜单类型不能为空');
            return false;
          }
          axios.post('/clinic-upms/menu/add',{
            category:_this.plat.category,
            code:_this.plat.code,
            href:_this.plat.href,
            icon:_this.plat.icon,
            name:_this.plat.name,
            orderNum:_this.plat.orderNum,
            parentId:_this.plat.parentId,
            remark:_this.plat.remark,
            type:_this.plat.type
          }).then(res=>{
            if(res){
               _this.showModel1=false;
              _this.getPageClinic();
              _this.removeMsg();
              _this.$Message.info('新增成功');
            }
          })
        },
        switch3(id,en){
          let _this=this;
          let enabled=en==1?0:1;
          axios.post('/clinic-upms/menu/enabled',{
            id:id,
            enabled:enabled
          }).then(res=>{
            if(res){
              _this.$Message.info('操作成功');
            }
          })
        },
        addClinic(id,name){
          this.plat.parentId=id;
          this.plat.parentName=name;
          this.showModel1=true;
          this.showTitle1='新增菜单';
          this.sureBtn='clinicMenu';
        },
        showClinicEditor(id){//编辑
          let _this=this;
          _this.showModel1=true;
          _this.showTitle1='编辑菜单';
          _this.sureBtn='clinicMenuEdit';
          _this.plat.id=id;
          axios.post('/clinic-upms/menu/get',{
            id:_this.plat.id
          }).then(res=>{
            if(res){
              let temp=res.data.data;
              _this.plat.category=temp.category+'',
              _this.plat.code=temp.code,
              _this.plat.href=temp.href,
              _this.plat.icon=temp.icon,
              _this.plat.name=temp.name,
              _this.plat.orderNum=temp.orderNum,
              _this.plat.parentId=temp.parentId,
              _this.plat.remark=temp.remark,
              _this.plat.type=temp.type+'',
              _this.plat.parentName=temp.parentName
            } 
          })
        },
        clinicEditBtn(){
          let _this=this;
            if(_this.plat.category==''){
          _this.$Message.error('菜单类型不能为空');
          return false;
          }
          if(_this.plat.name==''){
            _this.$Message.error('菜单名称不能为空');
            return false;
          }
          if(_this.plat.type==''){
            _this.$Message.error('菜单类型不能为空');
            return false;
          }
          axios.post('/clinic-upms/menu/update',{
            category:_this.plat.category,
            code:_this.plat.code,
            href:_this.plat.href,
            icon:_this.plat.icon,
            name:_this.plat.name,
            orderNum:_this.plat.orderNum,
            remark:_this.plat.remark,
            type:_this.plat.type,
            id:_this.plat.id
          }).then(res=>{
            if(res){
              _this.showModel1=false;
              _this.getPageClinic();
              _this.removeMsg();
              _this.$Message.info('修改成功');
            }
          })
        },
        clinicRemove(id,name){
          this.delMsg=true;
          this.delId=id;
          this.delMsgName=name;
          this.delBtn='delClinic';       
        },
        clinicSureDel(){
          let _this=this;
          axios.post('/clinic-upms/menu/delete',{
            id:_this.delId
          }).then(res=>{
            if(res){
               _this.delMsg=false;
              _this.delId='';
              _this.delMsgName='';
              _this.$Message.info('删除成功');
              _this.getPageClinic();
            }
          })
        },
        /*去资源*/
        platResource(platId){
          let menuName='platform_'+this.platform.page;
          this.$router.push({path:'/index/system/menuResource/'+this.id+'/'+platId+'/'+menuName});
        },
        partnerResource(parentId){
          let menuName='partner_'+this.partner.page;
          this.$router.push({path:'/index/system/menuResource/'+this.id+'/'+parentId+'/'+menuName});
        },
        clinicResource(clinicId){
          let menuName='clinic_'+this.clinic.page;
          this.$router.push({path:'/index/system/menuResource/'+this.id+'/'+clinicId+'/'+menuName});
        }
      }
    }
    
</script>

<style scoped>

div::-webkit-scrollbar {
  width: 0;
}
.ivu-table td{
  height:42px !important;
}
  #menuManagement{
    width: 100%;
    height: 100%;
    overflow: auto;
  }
  #menuManagement .bread{
    font-size: 13px;
    white-space: nowrap;
    margin-bottom: 20px;
  }
  #menuManagement .topBox{
    display: flex;
    flex-flow: row wrap;
    margin-bottom: 20px;
  }
  #menuManagement .topBox .topItem{
    width: 280px;
    margin-bottom: 10px;
  }
  #menuManagement .topBox .topItem:last-child{
    width: 170px;
  }
  #menuManagement .buttonGroup{
    padding: 0 0 20px 10px;
  }
  /*弹出框*/
  #menuManagement .addRole{
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    top:0;
    left:0;
    z-index: 999;
  }
  #menuManagement .modelBox{
    position: absolute;
    width: 680px;
    min-height: 300px;
    top:80px;
    left: 50%;
    background-color: #fff;
    margin-left: -340px;
    border-radius: 10px;
    padding-bottom: 20px;
  }
  #menuManagement .modelTitle{
    height: 60px;
    line-height: 60px;
    font-size: 16px;
    background-color: #00507e;
    color: #fff;
    border-radius: 10px 10px 0 0;
    text-align: center;
  }
  #menuManagement .exit{
    position: absolute;
    font-size: 20px;
    right: 20px;
    cursor: pointer;
  }
  #menuManagement .roleMsg{
    display: flex;
    flex-flow: row wrap;
    font-size: 14px;
    padding: 15px 25px;
    justify-content: space-between;
  }
  #menuManagement .roleMsg div{
    padding: 0 0 10px 0;
    margin-left: -3px;
  }
  #menuManagement .roleMsg span{
    display: inline-block;
    width: 80px;
    text-align: justify;
  }
  #menuManagement .roleMsg input{
    outline: none;
    border: none;
    width: 210px;
    height: 30px;
    padding-left: 5px;
    border: 1px solid #ccc;
    border-radius: 5px;
  }
  #menuManagement .roleMsg .remark{
    width: 630px;
    padding: 0;
  }
  #menuManagement .modelBox .buttons{
    text-align:center;
  }
  #menuManagement .modelBox .buttons button{
    margin: 10px;
  }
</style>
