<template>
  <div id="print1" v-show="true">
    <work-busy :is-busy="loading"></work-busy>
    <div id="print2">
      <style id="style1">
        #print2 td{
          height:28px;
          width: 100px;
          text-align: center;
        }
        #print2 table{
          margin: auto;
        }
        #print2 h1{
          text-align: center;
        }
        #print2 p{
          text-align: center;
        }
        .border-btn{
          border-bottom: #000000 solid 1px;
        }
      </style>
      <h1>{{loginorg}}</h1>
      <p>安检时间:{{userinfo.f_offsite_time}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      </p>
      <table border="1" cellspacing="0">
        <tr>
          <td style="width:15%"><b>用户编号</b></td>
          <td style="width:35%">{{userinfo.f_userinfo_code}}</td>
          <td style="width:15%"><b>用户姓名</b></td>
          <td colspan="2" style="width:45%">{{userinfo.f_user_name}}</td>
        </tr>
        <tr>
          <td><b>联系电话</b></td>
          <td colspan="4">{{userinfo.f_user_phone}}</td>
        </tr>
        <tr>
          <td><b>地址</b></td><td colspan="5">{{userinfo.f_address}}
        </tr>
        <tr align="left" v-if="userinfo.f_entry_status=='入户'">
          <td><b>安检信息</b></td>
          <td colspan="5" style="padding: 0px">
            <table border="0" cellspacing="0" width="100%"  style="margin: 0px">
              <tr v-for="devi in deviceconfig2" :key="devi.index">
                <td style="border-right:#000000 solid 1px;width: 20%!important;" :class="$index == devices.length-1?'':'border-btn'">
                  {{devi.checkname}}
                </td>
                <!--<td>{{devi.value[0].name}}</td>-->
                <td colspan="4" style="padding: 0px;width: 80%!important;">
                  <table border="0" cellspacing="0" width="100%" style="margin: 0px">
                    <tr v-for="deviinfo in devi.items" :key="deviinfo.index">
                      <td style="border-right:#000000 solid 1px;width: 70%!important" :class="($parent.$index == devices.length-1 && $index == devi.value.length-1)?'':'border-btn'">
                        {{deviinfo.lname}}
                      </td>
                      <td style="width: 30%!important" :class="($parent.$index == devices.length-1 && $index == devi.value.length-1)?'':'border-btn'">
                        <label>{{getDeviceValue(devi.index,deviinfo.lname)}}</label>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr style="height: 80%">
          <td><b>安检结果</b></td>
          <td colspan="5">
            {{f_defect_content}}
          </td>
        </tr>
        <tr>
          <td><b>用户签字</b></td><td colspan="2 "><img-self :src='userinfo.f_sign_path' alt="未签名"></img-self></td>
          <td><b>安检员</b></td><td colspan="3">{{data.f_checker_name}}</td>
        </tr>
      </table>
    </div>
  </div>
  <modal :show.sync="show" v-ref:modal :backdrop="isBack">
    <div slot="modal-header" class="modal-header">
      <span class="modal-title font">
        安检单打印
      </span>
    </div>
    <div slot="modal-body" class="modal-body">
      确定打印安检单？
    </div>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-cancel" @click="cancel()">取消</button>
      <print-element @click="getHidden" class="btn btn-success width-80" id="print1" styleid='style1' top='40' left='60' width='100%' height='100%' v-ref:printelement>打印</print-element>
    </div>
  </modal>
</template>

<script>

import co from 'co'
import { PagedList,HttpResetClass } from 'vue-client'
import * as Util from '../../Util'
import ObjConfig from '../../../utils/GerJsonObjectConfig'
import {jsonSort} from '../../../utils/LdapHelper'
import Vue from "vue";
let asyncReady = async function (self) {
  // 获取配置信息
  try {
    /*let res9 = await Vue.resetget(`/phone/rs/vue`, {data: {}}, {resolveMsg: null, rejectMsg: null})
    Vue.config = res9.data*/
    let res= await new HttpResetClass().load('post','rs/sql/tel_singleTable_OrderBy',{data: {
        items: 'f_dir',
        tablename: 't_organization',
        condition: `id  = '${self.data.f_filialeid}'`,
        orderitem: 'id'
      }})/*.then(res=>{*/
    //tag
    //tag)
    if (!res.data[0].f_dir){
      this.$showMessage("该公司无组织目录，无法获取配置文件，请联系管理员确认")
    }else{
      //this.f_dir=res.data[0].f_dir
      //try {
      let res1=await new HttpResetClass().load('GET',`/safecheck/rs/vue/DevicesConfig.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {},{resolveMsg: '获取居民配置项成功！', rejectMsg: '获取居民配置项出错！'})/*.then(res=>{*/
      //tag
      //this.safeConfig["民用配置项"]=Object.assign({},res.data)
      Vue.config.safecheck.DevicesConfig=res1.data
      /*})*/
      let res2=await new HttpResetClass().load('GET',`/safecheck/rs/vue/DevicesSetConfig.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {},{resolveMsg: '获取非居民配置项成功！', rejectMsg: '获取非居民配置项出错！'})/*.then(res=>{*/
      //tag
      //this.safeConfig["非民用配置项"]=Object.assign({},res.data)
      Vue.config.safecheck.DevicesSetConfig=res2.data
      /*}).then(res=> {
      })*/

      /*}catch (e) {
        this.$showMessage("获取配置文件失败"+e)
      }*/
    }
  } catch (error) {
    // 忽略704,文件找不到异常R
    if (error.status !== 704) {
      throw error
    }
  }
}
export default {
  title: '安检信息',
  data () {
    return {
      imgs:[],
      normalDevices:{},//设备信息
      device:[],//表具信息
      devices:[],//所有表具信息
      userinfo:[],
      deviceInfo:{},//具体表具信息
      deviceInfos:{},//每个表具的所有信息
      drowspan:0,
      erowspan:0,//设备信息个数
      hrowspan:0,//隐患数
      f_defect_content:'有隐患：', //安检结果
      equipmentmsgs:[],//所有设备信息
      Hinvestigations:[], //所有隐患信息
      Hinvestigation:{},
      defect:{},//隐患信息
      normal:{},
      loginorg:this.$login.f.orgs+'安检单',
      normalDevice:[],
      Hiddenchecks:[],
      hiddenvalues:[],
      HazardDevice:[],
      HazardDevices:{},
      printtime:'',
      print_id:'',
      planmeter:{},
      showAdd:true,
      defectCount:'',
      deviceconfig:{},
      deviceconfig2:[],
      configkbFee:{
        "燃气表":{
          "checkmust":true,
          "index":1,
          "items":{
            //"燃气表照片":{"index":1,"type":"picture","remark":"(拍摄清晰的表具编号、字轮数、剩余气量等)"},
            "基表编号":{"index":1,"type":"string","readonly":true},
            "气表型号":{"index":2,"type":"string","readonly":true},
            "气表品牌":{"index":3,"type":"string","readonly":true},
            "进气方向":{"index":4,"type":"string","readonly":true},
            "表箱号":{"index":5,"type":"string","readonly": true},
            "累购金额":{"index":6,"type":"number","readonly":true},
            "表底数":{"index":7,"type":"number","checkmust": false},
            "剩余金额":{"index":8,"type":"number","checkmust": false},
            "生产日期":{"index":9,"type":"date","checkmust": true}
          }
          // 注意，配置项的index必须与上面的固定配置保持'顺序'
        },
      },
      configkbGas:{
        "燃气表":{
          "checkmust":true,
          "index":1,
          "items":{
            //"燃气表照片":{"index":1,"type":"picture","remark":"(拍摄清晰的表具编号、字轮数、剩余气量等)"},
            "基表编号":{"index":1,"type":"string","readonly":true},
            "气表型号":{"index":2,"type":"string","readonly":true},
            "气表品牌":{"index":3,"type":"string","readonly":true},
            "进气方向":{"index":4,"type":"string","readonly":true},
            "表箱号":{"index":5,"type":"string","readonly": true},
            "累购气量":{"index":6,"type":"number","readonly":true},
            "表底数":{"index":7,"type":"number","checkmust": false},
            "剩余气量":{"index":8,"type":"number","checkmust": false},
            "生产日期":{"index":9,"type":"date","checkmust": true}
          }
          // 注意，配置项的index必须与上面的固定配置保持'顺序'
        },
      },
      configwlFee:{
        "燃气表":{
          "checkmust":true,
          "index":1,
          "items":{
            //"燃气表照片":{"index":1,"type":"picture","remark":"(拍摄清晰的表具编号、字轮数、剩余气量等)"},
            "基表编号":{"index":1,"type":"string","readonly":true},
            "气表型号":{"index":2,"type":"string","readonly":true},
            "气表品牌":{"index":3,"type":"string","readonly":true},
            "进气方向":{"index":4,"type":"string","readonly":true},
            "表箱号":{"index":5,"type":"string","readonly": true},
            "累购金额":{"index":6,"type":"number","readonly":true},
            "表底数":{"index":7,"type":"number","checkmust": false},
            "剩余金额":{"index":8,"type":"number","checkmust": false},
            "生产日期":{"index":9,"type":"date","checkmust": true}
          }
          // 注意，配置项的index必须与上面的固定配置保持'顺序'
        },
      },
      configwlGas:{
        "燃气表":{
          "checkmust":true,
          "index":1,
          "items":{
            //"燃气表照片":{"index":1,"type":"picture","remark":"(拍摄清晰的表具编号、字轮数、剩余气量等)"},
            "基表编号":{"index":1,"type":"string","readonly":true},
            "气表型号":{"index":2,"type":"string","readonly":true},
            "气表品牌":{"index":3,"type":"string","readonly":true},
            "进气方向":{"index":4,"type":"string","readonly":true},
            "表箱号":{"index":5,"type":"string","readonly": true},
            "累购气量":{"index":6,"type":"number","readonly":true},
            "表底数":{"index":7,"type":"number","checkmust": false},
            "剩余气量":{"index":8,"type":"number","checkmust": false},
            "生产日期":{"index":9,"type":"date","checkmust": true}
          }
          // 注意，配置项的index必须与上面的固定配置保持'顺序'
        },
      },
      configjb:{
        "燃气表":{
          "checkmust":true,
          "index":1,
          "items":{
            "基表编号":{"index":1,"type":"string","readonly":true},
            "气表型号":{"index":2,"type":"string","readonly":true},
            "气表品牌":{"index":3,"type":"string","readonly":true},
            "进气方向":{"index":4,"type":"string","readonly":true},
            "表箱号":{"index":5,"type":"string","readonly": true},
            "累购气量":{"index":6,"type":"number","readonly":true,"ishow":false},
            "表底数":{"index":7,"type":"number","checkmust": false},
            "剩余气量":{"index":8,"type":"number","checkmust": false,"ishow":false},
            "生产日期":{"index":9,"type":"date","checkmust": true}
          }
          // 注意，配置项的index必须与上面的固定配置保持'顺序'
        },
      },
      isBack:false,
      loading: true,
    }
  },
  props: ['data','show'],
  async ready () {
    //tag
    let res=await new HttpResetClass().load('POST','rs/sql/查询计划项表信息',{data:{f_userid:this.data.f_userinfoid}})
    this.planmeter=res.data[0]
    asyncReady(this).then(() => {
      // tag
      this.$resetpost('rs/path/getUserinfomation', {data:{condition:`id = '${this.data.id}'`}}).then((res)=>{
        //tag
        let d=true
        if(res.data.length>0){
          this.userinfo = res.data[0]
          for(let device in this.userinfo.f_devices){
            for(let item in this.userinfo.f_devices[device].f_items){
              if(this.userinfo.f_devices[device].f_items[item].f_is_defect &&( this.userinfo.f_devices[device].f_items[item].f_is_defect=='true' ||  this.userinfo.f_devices[device].f_items[item].f_is_defect==true)){
                d=false
                this.f_defect_content += `${this.userinfo.f_devices[device].f_items[item].f_item_name}:${this.getdefect(this.userinfo.f_devices[device].f_items[item].f_item_lists)}、`
              }
            }
          }
          if(d){
            this.f_defect_content='正常'
          }
          //tag
          //tag)
          if(this.userinfo.f_sign_path != ''){
            this.userinfo.f_sign_path = 'rs/image/file/' + this.userinfo.f_sign_path
          }
        }else{
          //tag
          this.$showMessage('未查询到该用户安检单信息')
          this.$parent.showcheckmsg = false
        }

        if (this.userinfo.f_check_type=='民用'){
          this.deviceconfig=Vue.config.safecheck.DevicesConfig
          // //tag)
        }else if (this.userinfo.f_check_type=='非民用'){
          this.deviceconfig=Vue.config.safecheck.DevicesSetConfig
          ////tag)
        }
        /* if (this.userinfo.f_collection_type=='按气量'){
           this.deviceconfig["燃气表"]=this.config["燃气表"]
           ////tag)
         }else if (this.userinfo.f_collection_type=='按金额'){
           this.deviceconfig["燃气表"]=this.config2["燃气表"]
           ////tag)
         }*/
        //tag+"-------------"+typeof this.deviceconfig)
        //tag)
        if(typeof this.deviceconfig == 'string'){
          this.deviceconfig=JSON.parse(this.deviceconfig)
        }
        if (this.planmeter.f_meter_classify=='机表'){
          let aaa=Object.assign({},this.configjb["燃气表"].items,this.deviceconfig["燃气表"].items)
          this.deviceconfig["燃气表"].items=aaa
          ////tag)
        }else if (this.planmeter.f_meter_classify=='金额卡表'){
          let aaa=Object.assign({},this.configkbFee["燃气表"].items,this.deviceconfig["燃气表"].items)
          this.deviceconfig["燃气表"].items=aaa
          ////tag)
        }else if (this.planmeter.f_meter_classify=='气量卡表'){
          let aaa=Object.assign({},this.configkbGas["燃气表"].items,this.deviceconfig["燃气表"].items)
          this.deviceconfig["燃气表"].items=aaa
          ////tag)
        }else if (this.planmeter.f_meter_classify=='物联网表'&&this.planmeter.f_collection_type=='按气量'){
          let aaa=Object.assign({},this.configwlGas["燃气表"].items,this.deviceconfig["燃气表"].items)
          this.deviceconfig["燃气表"].items=aaa
          ////tag)
        }else if (this.planmeter.f_meter_classify=='物联网表'&&this.planmeter.f_collection_type=='按金额'){
          let aaa=Object.assign({},this.configwlFee["燃气表"].items,this.deviceconfig["燃气表"].items)
          this.deviceconfig["燃气表"].items=aaa
          ////tag)
        }else {
          this.$showMessage("未获取到表型异常")
          return
        }

        // //tag)
        this.deviceconfig2=ObjConfig.getObjConfig(this.deviceconfig)
        ////tag)
        this.deviceconfig2[0].items=jsonSort(this.deviceconfig2[0].items,"index")
        ////tag)
        this.deviceconfig2[1].items=jsonSort(this.deviceconfig2[1].items,"index")
        ////tag)
        this.deviceconfig2=jsonSort(this.deviceconfig2,"index")
        ////tag)
        this.defectcontent()
      })
      setTimeout( () => {
        this.loading = false
      }, 1500)

    })

  },
  methods: {
    cancel(){
      this.$parent.showcheckmsg = false
    },
    getdefect(obj){
      //tag)
      let str=''
      for(let o=0;o<obj.length;o++){
        //tag
        if(o==obj.length-1){
          str += obj[o].f_item_value
        }else{
          str += obj[o].f_item_value+','
        }
        return str
      }
    },
    getDeviceValue(val1,val2){
      for (let j = 0; j <this.userinfo.f_devices.length ; j++) {
        for (let i = 0; i < this.userinfo.f_devices[j].f_items.length; i++) {
          if (this.userinfo.f_devices[j].f_items[i].f_item_name==val2){
            return this.userinfo.f_devices[j].f_items[i].f_item_lists[0].f_item_value
          }
        }
      }




    },
    defectcontent(){
      let val1=this.userinfo.f_devices[1].f_items
      let val2=this.userinfo.f_devices[0].f_items

      for (let i = 0; i < val1.length; i++) {
        if (val1[i].f_item_lists[0].f_is_defect=='true'){
          this.defectCount='有隐患'
          return
        }
      }
      for (let i = 0; i < val2.length; i++) {
        if (val2[i].f_item_lists[0].f_is_defect=='true'){
          this.defectCount='有隐患'
          return
        }
      }
      this.defectCount='正常'
      return '正常'
    },
    //获取当前时间
    getNowFormatDate() {
      var date = new Date(this.userinfo.f_check_date);
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var currentdate = date.getFullYear() +'年'+ month + '月' + strDate
        + "日" + date.getHours() + "时" + date.getMinutes()+'分'
      return currentdate;
    },
    // getId(){
    //   //tag
    // },
    //获取隐患信息
    getHidden(){
      setTimeout(()=> {
        //tag
        this.$parent.showcheckmsg = false
      }, 1000)
    },
  }
}
</script>
<style media="screen" scoped>
.divtext {
  min-width: 50px;
  max-width: 200px;
  border: 1px solid green;
  display: inline-block;
}
.bg-info{
  border-left: 5px solid #5989be;
}
.bg-cus-body {
  margin-left: 5px;
}

</style>
