<template>
  <div id="print1" v-show="true">
    <div id="print2">
      <style id="style1">
        #print2 td{
          height:32px;
          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 2px;
        }
      </style>
      <table border="1" cellspacing="0">
        <tr>
          <td  colspan="6"><h4><b>荣成港华燃气有限公司安检隐患派发整改单</b></h4></td>
        </tr>
        <tr>
          <td><b>发单人</b></td><td>{{userinfo.f_userinfo_code}}</td><td ><b>接单人</b></td><td >{{userinfo.f_user_name}}</td><td><b>审核人</b></td>
          <td>{{userinfo.f_user_phone}}</td>
        </tr>
        <tr>
          <td colspan="6"><b>是否需要其他部门协助完成:<input type="checkbox" style="margin-left: 10px;margin-right: 5px"/>是<input type="checkbox" style="margin-left: 10px;margin-right: 5px"/>否</b></td>
        </tr>
        <tr>
          <td><b>客户编号</b></td><td>{{userinfo.f_userinfo_code}}</td><td ><b>客户名称</b></td><td >{{userinfo.f_user_name}}</td><td><b>客户电话</b></td>
          <td>{{userinfo.f_user_phone}}</td>
        </tr>
        <tr>
          <td><b>客户地址</b></td>
          <td colspan="5">
            {{f_defect_content}}
          </td>
        </tr>
        <tr align="left" v-if="drowspan!=0">
          <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 devices" :key="devi.id">
                <td style="border-right:#000000 solid 2px;width: 20%!important;" :class="$index == devices.length-1?'':'border-btn'">
                  {{devi.f_device_type}}
                </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.value" :key="deviinfo.id">
                      <td style="border-right:#000000 solid 2px;width: 70%!important" :class="($parent.$index == devices.length-1 && $index == devi.value.length-1)?'':'border-btn'">
                        {{deviinfo.name}}
                      </td>
                      <td style="width: 30%!important" :class="($parent.$index == devices.length-1 && $index == devi.value.length-1)?'':'border-btn'">
                        <label>{{deviinfo.value}}</label>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr align="left" v-if="erowspan!=0">
          <td><b>用户设备信息</b></td>
         <td colspan="5" style="padding: 0px">
           <table border="0" cellspacing="0" width="100%"  style="margin: 0px">
             <tr v-for="equipmentmsg in equipmentmsgs">
               <td style="border-right:#000000 solid 2px;width: 20%!important;" :class="$index == equipmentmsgs.length-1?'':'border-btn'">
                 {{equipmentmsg.f_device_type}}
               </td>
               <td style="padding: 0px;width: 80%!important;">
                 <table border="0" cellspacing="0" width="100%" style="margin: 0px">
                   <tr v-for="equipment in equipmentmsg.value" :key="equipment.id">
                     <td style="border-right:#000000 solid 2px;width: 70%!important" :class="($parent.$index == equipmentmsgs.length-1 && $index == equipmentmsg.value.length-1)?'':'border-btn'">
                       {{equipment.name}}
                     </td>
                     <td style="width: 30%!important" :class="($parent.$index == equipmentmsgs.length-1 && $index == equipmentmsg.value.length-1)?'':'border-btn'">
                       <label>{{equipment.value}}</label>
                     </td>
                   </tr>
                 </table>
               </td>
             </tr>
           </table>
         </td>
        </tr>
        <tr align="left" v-if="hrowspan!=0">
          <td><b>用户设备隐患</b></td>
          <td colspan="5" style="padding: 0px">
            <table border="0" cellspacing="0" width="100%"  style="margin: 0px">
              <tr v-for="Hinvestigation in Hinvestigations">
                <td style="border-right:#000000 solid 2px;width: 20%!important;" :class="$index == Hinvestigations.length-1?'':'border-btn'">
                  {{Hinvestigation.f_device_type}}
                </td>
                <td style="padding: 0px;width: 80%!important;">
                  <table border="0" cellspacing="0" width="100%" style="margin: 0px">
                    <tr v-for="HazardDevice in Hinvestigation.value" :key="HazardDevice.id">
                      <td style="border-right:#000000 solid 2px;width: 70%!important" :class="($parent.$index == Hinvestigations.length-1 && $index == Hinvestigation.value.length-1)?'':'border-btn'">
                        {{HazardDevice.name}}
                      </td>
                      <td style="width: 30%!important" :class="($parent.$index == Hinvestigations.length-1 && $index == Hinvestigation.value.length-1)?'':'border-btn'">
                        <label>{{HazardDevice.value}}</label>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td  colspan="6"><b>整改后气密讨论结果:<input type="checkbox" style="margin-left: 10px;margin-right: 5px"/>合格<input type="checkbox" style="margin-left: 10px;margin-right: 5px"/>不合格</b></td>
        </tr>
        <!--<tr align="left" v-show="userinfo.f_check_type ==='民用'">-->
          <!--<td >隐患类别</td>-->
          <!--<td colspan="6">-->
            <!--<div style="margin: auto;width: 95%">-->
              <!--<div align="left" >-->
                <!--<label v-for="Hiddencheck in Hiddenchecks"><input type="checkbox" :checked="Hiddencheck.key" />{{Hiddencheck.value}}；</label>-->
              <!--</div>-->
            <!--</div>-->
          <!--</td>-->
        <!--</tr>-->
        <!--<tr align="left" v-show="userinfo.f_check_type ==='民用'">-->
          <!--<td >建议处理措施</td>-->
          <!--<td colspan="6">-->
            <!--<div style="margin: auto;width: 95%">-->
              <!--<div align="left" >-->
                <!--<label v-for="Hiddenvalue in hiddenvalues"><input type="checkbox" :checked="Hiddenvalue.key" />{{Hiddenvalue.value}}；</label>-->
              <!--</div>-->
            <!--</div>-->
          <!--</td>-->
        <!--</tr>-->
        <!--<tr>-->
          <!--<td >用户意见反馈</td>-->
          <!--<td colspan="6">-->
            <!--<div style="margin: auto;width: 95%">-->
              <!--<div align="left">-->
                <!--<label v-for="customermsg in customers" ><input type="checkbox" :checked="customermsg.key" />{{customermsg.value}}；</label>-->
                <!--<label>以上安检内容是否认真实施，请用户做出真是评价</label>-->
                <!--<label v-for="customermsg1 in customers1" ><input type="checkbox" :checked="customermsg1.key" />{{customermsg1.value}}</label>-->
                <!--<label>；安检人员工作内容及质量</label>-->
                <!--<label v-for="customermsg2 in customers2" > <input type="checkbox" :checked="customermsg2.key" />{{customermsg2.value}}</label>-->
              <!--</div>-->
            <!--</div>-->
          <!--</td>-->
        <!--</tr>-->

        <tr>
          <td><b>整改人</b></td><td colspan="2 "></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>
  <!--<div class="row auto">-->
    <!--<blockquote class="bg-info">-->
      <!--用户信息-->
    <!--</blockquote>-->
    <!--<div class="row bg-cus-body">-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">用户编号：</label>-->
          <!--<span class="form-control-static" >{{userinfo.f_userinfo_code}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">用户姓名：</label>-->
          <!--<span class="form-control-static" >{{userinfo.f_user_name}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">用户电话：</label>-->
          <!--<span class="form-control-static" >{{userinfo.f_user_phone}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label class="control-label">安检人员：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_checker}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">安检日期：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_offsite_time}}</span>-->
        <!--</div>-->
      <!--</div>-->
      <!--<blockquote>-->
        <!--用户地址-->
      <!--</blockquote>-->
      <!--<div class="row auto bg-cus-body">-->
        <!--<div class="col-sm-12" >-->
          <!--<label class="control-label">地址：</label>-->
          <!--<span class="form-control-static" >{{userinfo.f_address}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">街道：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_street}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">小区：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_residential_area}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">楼号：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_building}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="control-label">单元：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_unit}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="  control-label">楼层：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_floor}}</span>-->
        <!--</div>-->
        <!--<div class="col-sm-3" >-->
          <!--<label  class="  control-label">门牌号：</label>-->
          <!--<span class="form-control-static">{{userinfo.f_room}}</span>-->
        <!--</div>-->
    <!--</div>-->
    <!--<blockquote class="bg-info">-->
      <!--设备信息-->
    <!--</blockquote>-->
    <!--<div class="bg-cus-body">-->
      <!--<equipment-msg :data='data' v-if="data.f_check_type === '民用' "></equipment-msg>-->
      <!--<fequipment-msg :data='data' v-if="data.f_check_type === '非民用'"></fequipment-msg>-->
    <!--</div>-->
    <!--<blockquote class="bg-info">-->
      <!--隐患信息-->
    <!--</blockquote>-->
    <!--<div class="bg-cus-body">-->
      <!--<hidden-check :data='data' v-if="data.f_check_type === '民用' || data.f_check_type === null"></hidden-check>-->
      <!--<fhidden-check :data='data' v-if="data.f_check_type === '非民用'"></fhidden-check>-->
    <!--</div>-->
    <!--<blockquote class="bg-info">-->
      <!--用户意见-->
    <!--</blockquote>-->
    <!--<div class="bg-cus-body">-->
      <!--<user-opinion :data='data'v-if="data.f_check_type === '民用'"></user-opinion>-->
      <!--<fuser-opinion :data='data'v-if="data.f_check_type === '非民用'"></fuser-opinion>-->
    <!--</div>-->


    <!--<div class="row">-->
      <!--<div class="col-sm-11 text-right">-->
        <!-- <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>-->
    <!--</div>-->
  <!--</div>-->
</template>

<script>

import co from 'co'
import { PagedList } from 'vue-client'
import * as Util from '../Util'

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:{},
      normalDevice:[],
      Hiddenchecks:[],
      hiddenvalues:[],
      HazardDevice:[],
      HazardDevices:{},
      printtime:'',
      print_id:'',
      showAdd:true,
      company:'',
      isBack:false
    }
  },
  props: ['data','show'],
  ready () {
    // let value = f_fengongsi
    // let index = value.indexOf('.')
    // this.company = value.substring(index+1,value.length)
    /*this.$resetpost('rs/path/getUserinfomation', {data:{condition:`id = '${this.data.id}'`}}).then((res)=>{
      //tag
      if(res.data.length>0){
        this.userinfo = res.data[0]
        if(this.userinfo.f_sign_path != ''){
          this.userinfo.f_sign_path = 'rs/image/file/' + this.userinfo.f_sign_path
        }
        this.$resetpost('rs/sql/getCompany', {data:{f_filialeid:this.$login.f.orgid}}).then((res)=>{
          //tag
          if(res.data.length >0){
            this.company = res.data[0].value
          }else{
            this.$showMessage('公司名称未设置，请前往参数管理中的单值表中进行设置！')
            this.$parent.showcheckmsg = false
          }
        })
      }else{
        //tag
        this.$showMessage('未查询到该用户安检单信息')
        this.$parent.showcheckmsg = false
      }
    })*/
  },
  methods: {
    cancel(){
      this.$parent.showcheckmsg = false
    },
    gotoPage(val,data,self='tab'){
      //tag
      data.f_type = '回访'
      data.f_telvisit_type = '安检'
      this.$goto(val,{row:data},self)
    },
    //获取当前时间
    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(){
      //清空所有数据
      this.equipmentmsgs = []
      this.devices = []
      this.normalDevices = {}
      this.Hinvestigations = []
      this.device = []
      this.normalDevice = []
      //用户设备信息
      let normal = ''
      let deviceInfo
      let f_device_type
      for(let item in this.userinfo.f_devices){
        let device = this.userinfo.f_devices[item]
        f_device_type = device.f_device_type
        //判断当前设备是否已存在，已存在命名加1
        //tag
        if (this.equipmentmsgs.length == 0){
          if(this.Hinvestigations.length != 0){
            let m = 0
            for (let i in this.Hinvestigations){
              if(this.Hinvestigations[i].f_device_type.indexOf(f_device_type) != -1){
                m = m+1
              }
            }
            if(m>0){
              f_device_type = `${device.f_device_type}${m}`
            }
          }
        }else{
          let m = 0
          let n = 0
          for (let n in this.equipmentmsgs){
            //tag
            if(this.equipmentmsgs[n].f_device_type.indexOf(f_device_type) != -1){
              m = m+1
            }
          }
          for (let i in this.Hinvestigations){
            //tag
            if(this.Hinvestigations[i].f_device_type.indexOf(f_device_type) != -1){
              n = n+1
            }
          }
          if(m>=n && m!=0){
            f_device_type = `${device.f_device_type}${m}`
          }else{
            if( n!=0){
              f_device_type = `${device.f_device_type}${n}`
            }
          }
        }

        //取出除燃气表外正常设备信息
          for (let i in device.f_items){
            //tag
            //tag
            //tag
            //tag
            //tag
            //tag
            //tag
            if(device.f_items[i].f_item_value != '' && device.f_items[i].f_is_defect != 'true'){
              if(device.f_device_type == '燃气表'){
                this.$set('deviceInfo.name',device.f_items[i].f_item_name)
                this.$set('deviceInfo.value',device.f_items[i].f_item_value)
                //tag
                this.device.push(JSON.parse(JSON.stringify(this.deviceInfo)))
                // deviceInfo = deviceInfo + `,${f_device_type}${device.f_items[i].f_item_name}${device.f_items[i].f_item_value}`
              }else{
                this.$set('normal.name',device.f_items[i].f_item_name)
                this.$set('normal.value',device.f_items[i].f_item_value)
                //tag))
                this.normalDevice.push(JSON.parse(JSON.stringify(this.normal)))
              }
            }else if(device.f_items[i].f_item_value != '' && device.f_items[i].f_is_defect == 'true'){
              //隐患设备信息
              if(device.f_items[i].f_item_value != '' && device.f_items[i].f_is_defect == 'true'){
                if(device.f_device_type != '燃气表'){
                  this.$set('Hinvestigation.name',device.f_items[i].f_item_name)
                  this.$set('Hinvestigation.value',device.f_items[i].f_item_value)
                  //tag))
                  this.HazardDevice.push(JSON.parse(JSON.stringify(this.Hinvestigation)))
                }
              }
              //tag
            }
            //tag
          }
          if(this.device.length != 0){
            if(device.f_device_type == '燃气表'){
              //tag
              this.$set('deviceInfos.f_device_type',f_device_type)
              this.$set('deviceInfos.value',this.device)
              this.device = []
              this.devices.push(JSON.parse(JSON.stringify(this.deviceInfos)))
              //tag
              // this.devices.push(this.device)
            }
          }

          if(this.normalDevice.length != 0){
            if(device.f_device_type != '燃气表'){
              let values
              this.$set('normalDevices.f_device_type',f_device_type)
              this.$set('normalDevices.value',this.normalDevice)
              this.normalDevice = []
              //tag
              values = JSON.parse(JSON.stringify(this.normalDevices))
              this.equipmentmsgs.push(values)
            }
          }
        if(this.HazardDevice.length != 0){
          let values
          this.$set('HazardDevices.f_device_type',f_device_type)
          this.$set('HazardDevices.value',this.HazardDevice)
          this.HazardDevice = []
          //tag
          values = JSON.parse(JSON.stringify(this.HazardDevices))
          this.Hinvestigations.push(values)
        }
      }
      this.drowspan = this.devices.length
      this.erowspan = this.equipmentmsgs.length
      //设备隐患
      //tag
      let f_defect_content = JSON.parse(JSON.stringify(JSON.parse(this.userinfo.f_defect_content)))
      this.f_defect_content = f_defect_content.result
      // for (let defect of f_defect_content.data){
      //   for (let key in defect){
      //     this.$set('defect.f_defect_level',key)
      //     this.$set('defect.value',defect[key])
      //   }
      //   this.Hinvestigations.push(JSON.parse(JSON.stringify(this.defect)))
      // }
      this.hrowspan = this.Hinvestigations.length
      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>
