<template>
  <div style="height: 5%;background-color: #499edf;"></div>
  <div style="height: 7%">
    <tools-page   :need-back="!isMenu" :title="titleName" @back="back('返回')" > </tools-page>
  </div>
  <div id="app" :class="{'auto':isMenu,'app-height':!isMenu}">
    <div class="row" :style="isMenu?'overflow-y: scroll;overflow-x: hidden;height:80vh':'overflow-y: scroll;overflow-x: hidden;'">
        <route v-ref:route> </route>
    </div>
    <tab-bar @select-item="onClickTabBarItem" v-show="isMenu">
    </tab-bar>
  </div>
  <modal v-if="showFile" :show.sync="showFile" v-ref:modal :backdrop="false" title="业务提醒">
    <header slot="modal-header" class="modal-header">
      <h4 class="modal-title">业务提醒</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="form-group" style="text-align: center">
        安检代办:{{result.safe[0].safenum}}条，其中预约单{{result.safeorder[0].safeyuyuenum}}条 <br/>
        维修代办:{{result.tel[0].telnum}}条，其中预约单{{result.telorder[0].telyuyuenum}}条<br/>
        报建代办:{{result.apply[0].applynum}}条，其中预约单{{result.applyorder[0].applyyuyuenum}}条<br/>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button"  @click="closeFile" style="background-color: limegreen;color: white">确定</button>
    </footer>
  </modal>
</template>

<script>

import {HttpResetClass} from "vue-client";
import Vue from 'vue'
export default {
  title: 'app',
  data: function () {
    return {
      item: 0,
      isMenu:true,
      beforeName:'主界面',
      titleName:'待办工作',
      backthis:'',
      safe:false,
      showFile:false,
      beforetabs:[],
      iftabbar:'',
      result:[]
    }
  },
  ready(){
    let zhi=this.$appdata.getSingleValue('是否开启代办提醒')
    if(zhi=='是'){
      console.log("99999",Vue.user)
      new HttpResetClass().load('post',`${this.$androidUtil.getProxyUrl()}/rs/logic/getModuleUpcoming`,{
        id:Vue.user.id,
        name:Vue.user.name,
        orgid:Vue.user.orgid
      }).then(res=>{
        console.log("888888===>"+JSON.stringify(res.data))
        this.result = res.data
        this.showFile=true
        // this.$showMessage(`你有${result.safe[0].safenum}条需要处理的安检待办业务，<br/>
        // ${result.safeorder[0].safeyuyuenum}条需要处理的安检预约业务，<br/>
        // ${result.tel[0].telnum}条需要处理的维修待办业务，<br/>
        // ${result.telorder[0].telyuyuenum}条需要处理的维修预约业务，<br/>
        // ${result.applyorder[0].applyyuyuenum}条需要处理的报建预约业务，<br/>
        // ${result.apply[0].applynum}条需要处理的报建待办业务`)
      })
    }
  },
  methods: {
    closeFile(){
      this.showFile=false
    },
    back (flag){
      if(this.safe && flag == '返回' ){
        this.$showMessage('此返回所录入内容将无法找回！', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            //this.safe = false 返回父页面后不能修改父级页面定义的 是否返回提示
            this.delback()
            this.backthis.$back()
            this.closeAndDelAudio()
          }
        })
      }else{
        this.delback()
        //this.safe = false 返回父页面后不能修改父级页面定义的 是否返回提示
        this.backthis.$back()
      }
    },
    delback(){
      // 先确认出 前一个组件的名字
      var title = this.beforeName
      var beforetitle = '主界面'
      var j = -1
      for(var i = 0;i<this.beforetabs.length;i++){
        if(this.beforetabs[i].titleName == title){
          beforetitle = this.beforetabs[i].beforeName
          this.backthis =this.beforetabs[i].backthis
          this.safe  = this.beforetabs[i].safe
          j = i
          break;
        }
      }
      this.beforetabs.splice(j + 1, 1)
      this.beforeName = beforetitle
      this.titleName = title
      // 判断是否 显示底层导航
      if(this.iftabbar ==  this.titleName){
        this.isMenu = true
      }
    },
    onClickTabBarItem(titlefg) {
      var param = titlefg.link
      if(titlefg.name == '退出系统'){
        this.$showMessage('即将返回登陆界面！', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            this.$androidUtil.setPreference('f_repairman_id', 'x')
            this.$androidUtil.setPreference('f_repairman_name', 'x')
            this.$back()
          }
        })
      }else{
        if(this.beforeName == titlefg.name){
          return
        }
        this.titleName = titlefg.name
        this.beforeName = titlefg.name
        let data = {
          sourcet: '竖屏'
        }
        // if(titlefg.name == '待办工单'){
        //   param = param+'V'
        // }
        this.$refs.route.init(param,data)
      }
    },
    closeAndDelAudio() {
      console.log("停止无限制录音")
      HostApp.startOrStopAudioClip("-----","停止录音")
    }
  },
  events: {
    'gotoson': function (prpdata) {
      // 事件回调内的 `this` 自动绑定到注册它的实例上
      // safe 返回事件是否进行判断后再返回
      // 每进入一次，beforetabs 数组添加  返回  删除
      this.backthis = prpdata._this
      this.safe = prpdata.safe
      this.isMenu = false
      // 记录本次跳转
      var beforedata = {
        beforeName: this.titleName,
        titleName: prpdata.title,
        backthis:prpdata._this,
        safe:prpdata.safe
      }
      this.beforetabs.push(beforedata)
      if( this.beforetabs.length == 1){
        this.iftabbar = beforedata.beforeName
      }
      // 写入跳转后 前后组件名字
      this.beforeName = this.titleName
      this.titleName = prpdata.title

      console.log('进入子组件，通知外层组件，我已经进入')
    },
    'confirm': function () {
      // 提交处理返回事件
      this.back('提交')
    },
    'backarrdel': function () {
      this.delback()
    },
    'gologin': function () {
      this.beforetabs = []
      this.$back()
    }
  }
}
</script>
<style scoped>
.app-height{
  height: 93%;
}
</style>
