<template>
  <div class="warrper">
    <div v-if="subNavShow == true" style="padding:24px 12px 24px 24px;">
      <div class="gotoButton pb24" style="padding-right:12px;" @click="gotoCLick"><i class="gotoIcon"></i>返回</div>
      <div class="gjhqTitle pb24" style="padding-right:12px;" ><span class="rf"><span class="titlesSml">完成度</span> {{ parseInt(wcdNum) }} %</span>基础信息采集</div>
      <div style="margin-right:12px;">
        <div class="basiWcd">
          <div class="basiWcdjdNums" :style="{width:parseInt(wcdNum)+'%'}"></div>
        </div>
      </div>
      <div class="basicinBox">
        <div class="ulliBox" v-for="(item, i) in basiDatas" :key="i">
          <div class="ulli"  v-if="item.meun == true">
            <div class="basicinLi">
              <div class="basicTile">{{ item.titles }}</div>
              <div class="basicInfo">
                <span v-if="item.wcd != null"><i class="iconInfo"></i>完整度 {{ item.wcd }} %</span>
                <span v-else>-</span>
                <span v-if="item.dbfk != null"><i class="iconInfo1"></i>督办反馈 {{ item.dbfk }}</span>
                <span v-else>-</span>
              </div>
              <div v-if="item.report_status == 2">
                <div class="basiButton" @click="tbClick(item,'')" v-if="item.if_insert == 1">开始填报</div>
                <div class="basiButton" @click="tbClick(item,'edit')" v-if="item.if_insert == 2">更新内容</div>
              </div>
              <div class="basiButton cur" v-else>更新内容</div>
            </div>
          </div>
        </div>
        <div class="clear"></div>
      </div>
    </div>
    <div v-else>
      <div :is="componentVal" @gotoBack="subNavBack"></div>
    </div>
  </div>
</template>
<script>
import schoolscale from '../schoolscale/schoolscale.vue'
import { adminLoginqx, adminScalelvl } from '../../axios/api'
import { adminreportcycle } from '../../axios/apiliangbiao'
export default {
  name: 'basicinfocoll',
  components: {
    schoolscale
  },
  data () {
    return {
      subNavShow: true,
      componentVal: 'schoolscale',
      quanxian: 'admin',
      wcdNum: 0,
      basiDatas: [
        {
          titles: '1.1 学校基础信息采集量表',
          wcd: 100,
          dbfk: 0,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:school',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.2 学校设备信息采集量表',
          wcd: 50,
          dbfk: 10,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:school-equipment',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.3 学校人员基础信息采集量表',
          wcd: 100,
          dbfk: 0,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:school_people_info',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.4 学生欺凌委员会信息采集量表',
          wcd: 50,
          dbfk: 10,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:ql_committee_collection',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.5 学校规章制度采集量表',
          wcd: 50,
          dbfk: 10,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:regulations_system_collection',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.6 常态工作-事前预防工作统计表',
          wcd: 50,
          dbfk: 10,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:preventive-work-advance',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.7 常态工作-事中发现工作统计表',
          wcd: 50,
          dbfk: 10,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:discover-work-statistics',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        },
        {
          titles: '1.8  常态工作-事后处理工作统计表',
          wcd: 50,
          dbfk: 10,
          url: 'schoolscale',
          showV: '1',
          name: 'admin:handle-work-statistics',
          role: [],
          meun: false,
          if_insert: 1,
          reportEdit: true
        }
      ],
      reportcode: ''
    }
  },
  created () {
    let that = this    
    if (navigator.onLine) {      
    } else {
      that.$messageOne({message: '网络异常，请检测网络是否链接！', type: 'error', duration: 3000})
      return false
    }
    adminreportcycle().then(res => {
      if (res.code == 10000) {
        if (res.report_code != null) {
          that.reportcode = res.report_code
        }
      }
    }).catch(error => {
      that.$messageOne({message: error, type: 'error', duration: 3000})
    })
    setTimeout(() => {
      adminScalelvl(1).then(res => {
        if (res.code == 10000) {
          let datas = res.data
          let len = datas.length
          let num = 0
          for (var i = 0; i < datas.length; i++) {
            let completeness = res.data[i].completeness
            that.basiDatas[i].titles = res.data[i].name
            that.basiDatas[i].id = res.data[i].id
            that.basiDatas[i].dbfk = res.data[i].feedbacks
            that.basiDatas[i].wcd = completeness.toFixed(0)
            that.basiDatas[i].if_insert = res.data[i].if_insert
            that.basiDatas[i].type = res.data[i].type
            that.basiDatas[i].report_status = res.data[i].report_status
            that.basiDatas[i].report_code = that.reportcode
            num += parseInt(completeness.toFixed(0))
          }
          that.wcdNum = num / len
        } else if (res.code == 10002) {
          that.$router.push({name: 'Login'})
        } else {
          that.$messageOne({message: res.message, type: 'error', duration: 3000})
        }
      }).catch(error => {
        console.log('error', error)
        that.$messageOne({message: error, type: 'error', duration: 3000})
      })
    }, 800) 
  },
  mounted () {
    let that = this    
    setTimeout(() => {
      adminLoginqx().then(res => {
        if (res.code == 10000) {
          if (res.role != null) {
            that.quanxian = res.role.id
          } else {
            that.quanxian = 0
          }
          if (res.system == 1) {
            let menulist = that.basiDatas
            for (var i = 0; i < menulist.length; i++) {
              menulist[i].meun = true
            }
          } else {
            let permissonListDatas = JSON.parse(localStorage.getItem('permissonListDatas'))
            let meunsArray = that.basiDatas
            for (var i = 0; i < meunsArray.length; i++) {
              let names = meunsArray[i].name
              for (var j = 0; j < permissonListDatas.length; j++) {
                let arrNames = permissonListDatas[j].name
                if (names == arrNames) {
                  meunsArray[i].role = permissonListDatas[j].roles
                }
              }
            }
            that.meuns = meunsArray            
            let menulist = that.basiDatas
            let qxVal = that.quanxian
            for (var i = 0; i < menulist.length; i++) {
              var qx = menulist[i].role
              for (var j = 0; j < qx.length; j++) {
                if (qxVal == qx[j]) {
                  menulist[i].meun = true
                }
              }
            }
          }
        } else {
          that.$messageOne({message: res.message, type: 'error', duration: 3000})
        }
      }).catch(error => {
        that.$messageOne({message: error, type: 'error', duration: 3000})
      })
    }, 1500)
  },
  methods: {
    gotoCLick () {
      this.$router.push({name: 'homes'})
    },
    tbClick (obj, txt) {
      if (obj.report_status == 2) {
        obj.dbfkshow = true
        obj.dbfj = 'dbfk'
        obj.edit = txt
        obj.report_code = this.reportcode
        localStorage.setItem('basicinfollDatas', JSON.stringify(obj))
        this.subNavShow = false
        this.componentVal = obj.url
      }
    },
    subNavBack () {
      this.subNavShow = true
      this.componentVal = ''
    }
  }
}
</script>
<style scoped>
.basicinBox{margin:12px 0;}
.basicinBox .ulli{width:25%;float:left;overflow:hidden;margin-bottom:20px;}
.basicinBox .basicinLi{background: #FFFFFF;border-radius: 2px;border: 1px solid #D9D9D9;margin-right:12px;padding:16px;height:120px;}
.basicinBox .basicinLi .basicTile{font-weight: bold;font-size: 20px;color: #161617;line-height: 28px;margin-bottom:16px;height:28px;overflow:hidden;}
.basicinBox .basicinLi .basicInfo{padding-bottom:16px;font-size: 14px;color: #595959;line-height: 20px;border-bottom:1px solid #E1E1E6;}
.basicinBox .basicinLi .basicInfo span{margin-right:24px;}
.basicinBox .basicinLi .basicInfo .iconInfo{background:url('../../assets/icon48.png') no-repeat 0 0/100%;width:20px;height:20px;display:inline-block;margin-right:4px;position:relative;top:5px;}
.basicinBox .basicinLi .basicInfo .iconInfo1{background:url('../../assets/icon49.png') no-repeat 0 0/100%;width:20px;height:20px;display:inline-block;margin-right:4px;position:relative;top:5px;}
.basiButton{padding-top:16px;cursor:pointer;font-size: 14px;color: #0071DB;line-height: 20px;text-align:right;}
.basiButton.cur{color:#A8ABB2}
.basiWcd{height: 8px;background: #E6E6E6;border-radius: 2px;overflow:hidden;width:100%;}
.basiWcd .basiWcdjdNums{height: 8px;background: #3384E2;overflow:hidden;}
</style>
