<style scoped id="printStyle">
.img {
  border: 1px solid #9773ed;
  width: auto;
  height: auto;
  float: left;
  text-align: center;
  margin: 6px;
}

img {
  margin: 6px;
}


.container {
  margin: 10px auto;
  width: 80%;
  height: auto;
}

div::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
}

div {
  -ms-overflow-style: none;
  overflow: -moz-scrollbars-none;
}

.divmask {
  pointer-events: none;
}

.app-header {
  border-radius: 50%;
  background: rgba(73, 158, 223, 0.4);
  color: #FFF;
  padding: 20px;
  text-align: center;
  font-size: 1.2em;
  z-index: 10;
  opacity: 0.5;
  bottom: 50px;
  margin-top: -20px;
  position: absolute;
  top: 10%;
  right: 2%;
  height: 8%;
}
</style>

<template>
  <div class="basic-main" style="height: 100%">
    <div class="page-header app-header auto" style="padding: 15px;margin-right: 10px;right: 0%;height: 7%">
      <div @click="back()">
        <img src="../../assets/back.png" style="margin: 0px"/>
      </div>
    </div>
    <work-busy :is-busy="loading"></work-busy>
    <div class="container-fluid" style="overflow: scroll">
      <div class="row">
        <div class="col-md-5" style="margin-right: 2%;margin-left: 2%;height: 100%;overflow: scroll">
          <div style="width: 100%;margin: auto">
            <table class="table table-striped table-bordered" style="margin-top: 40px"
                   v-show="paperdata.f_entry_status=='入户'">
              <thead>
              <tr>
                <th colspan="4" style="text-align: center">用户安检概况</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 17%">到达时间:</td>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 33%">{{ paperdata.f_onsite_time }}</td>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 17%">离开时间:</td>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 33%">{{ paperdata.f_offsite_time }}</td>
              </tr>
              <tr>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 17%">入户状态:</td>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 33%">{{ paperdata.f_entry_status }}</td>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 17%">燃气使用:</td>
                <td style="text-align: center;border: #E9E9E9 solid 1px;width: 33%">{{ paperdata.f_usegas }}</td>
              </tr>
              <tr>
                <td colspan="1" style="text-align: center;border: #E9E9E9 solid 1px;">备注:</td>
                <td colspan="3"
                    style="text-align: center;border: #E9E9E9 solid 1px;word-wrap:break-word;word-break:break-all;width:87%">
                  {{ paperdata.f_repair_approved_note }}
                </td>
              </tr>
              </tbody>
            </table>
            <table class="table table-striped table-bordered" style="margin-top: 35px"
                   v-show="paperdata.f_entry_status=='入户'">
              <thead>
              <tr>
                <th style="text-align: center">总体安检照片</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td style="margin: auto;text-align: center">
                  <div class="container" style="max-width: 550px;background: #FFFFFF">
                    <div class="img" v-for="img in paperdata.f_overall_imgs">
                      <img-self-plus :list="paperdata.f_overall_imgs " :src="img.f_overall_path" style="float: left"
                                     width="150"
                                     height="200"></img-self-plus>
                    </div>
                  </div>


                </td>

              </tr>
              </tbody>
            </table>
            <table class="table table-striped table-bordered" style="width: 100%"
                   v-show="paperdata.f_entry_status=='入户' && (paperdata.f_sign_path || f_user_path) ">
              <thead>
              <tr>
                <th style="text-align: center">用户签名照片</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td style="margin: auto;text-align: center" v-if="paperdata.f_sign_path">
                  <div class="container" style="max-width: 500px;background: #FFFFFF"  >
                    <div class="img" style="float: none">
                      <img-self-plus :src="'rs/image/file/'+paperdata.f_sign_path" width="200" height="200"></img-self-plus>
                    </div>
                  </div>
                </td>
                <td style="margin: auto;text-align: center" v-if="f_user_path">
                  <div class="container" style="max-width: 550px;background: #FFFFFF" >
                    <div class="img" style="float: none">
                      <img-self-plus :src="'rs/image/file/'+f_user_path"
                                     width="200"
                                     height="200"></img-self-plus>
                    </div>
                  </div>
                </td>
              </tr>
              </tbody>
            </table>
            <table class="table table-striped table-bordered"
                   v-show="paperdata.f_entry_status=='入户' && paperdata.f_defect_notified">
              <thead>
              <tr>
                <th style="text-align: center">安检通知书/隐患整改通知书</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td style="margin: auto;text-align: center">
                  <div class="container" style="max-width: 500px;background: #FFFFFF">
                    <div class="img" style="float: none">
                      <img-self-plus :src="paperdata.f_notified_path" width="486" height="300"></img-self-plus>
                    </div>
                  </div>
                </td>
              </tr>
              </tbody>
            </table>
            <table class="table table-striped table-bordered"
                   v-show="paperdata.f_entry_status=='入户'&& paperdata.f_video_path">
              <thead>
              <tr>
                <th style="text-align: center">安检视频</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td style="margin: auto;text-align: center">
                  <div class="container" style="max-width: 500px;background: #FFFFFF">
                    <video width="320" height="200" controls v-if="paperdata.f_video_path">
                      <source :src="paperdata.f_video_path" type="video/mp4">
                    </video>
                  </div>
                </td>
              </tr>
              </tbody>
            </table>
            <table class="table table-striped table-bordered"
                   v-show="item.f_recording1_path">
              <thead>
              <tr>
                <th style="text-align: center">录音文件</th>
              </tr>
              </thead>
              <tbody>
              <tr>
                <td style="margin: auto;text-align: center">
                  <div class="container" style="max-width: 500px;background: #FFFFFF">
                    <a class="button_spacing button_search-1"
                       :download="item.f_user_name+'-'+item.f_check_type+'-'+'录音文件.arm'"
                       :href="'rs/image/file/'+item.f_recording1_path">录音下载</a>
                  </div>
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div class style="width: 1%;height: 100%;background-color: #F1F8FF;float: left;"></div>
        <div class="col-md-6" style="height: 100%;overflow: scroll">
          <div style="width: 95%;margin-left: 5%">
            <table class="table table-striped table-bordered" v-for="config in deviceconfig2" style="margin-top: 35px">
              <thead >
              <tr>
                <th style="text-align: center">{{ config.f_device_type }}</th>
              </tr>
              </thead>
              <tr v-for="dev in config.f_items">
                <td>
                  <div class="row">
                    <div class="col-md-8" style="text-align: center;">
                      <label>
                        <button-link type="button" class="btn btn-link"
                                     :style="'color:black'">
                          {{ dev.f_item_name }}
                        </button-link>
                      </label>
                    </div>
                    <div class="col-md-4" style="text-align: center">
                      <label style="font-weight: normal"
                             v-if="dev.type!='picture'">{{
                          dev.f_item_lists[0].f_item_value
                        }}</label>
                      <label style="font-weight: normal" v-if="dev.type=='picture'">
                        <div v-if="dev.f_path">
                          <button-link style="color: black" type="button" class="btn btn-link"
                                       @click="showpath('rs/image/file/'+dev.f_path)">查看照片
                          </button-link>
                        </div>
                        <div v-else>无照片</div>
                      </label>
                    </div>
                  </div>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
  <modal :show.sync="imgshow" v-ref:modal backdrop="true">
    <header slot="modal-header" class="modal-header">
      {{ picturename }}
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="from-group">
        <div class="row">
          <div class="col-md-6">
            <img-self-plus v-if="showimg1" :src="showimg1" width="240" height="300"></img-self-plus>
          </div>
          <div class="col-md-6">
            <img-self-plus v-if="showimg2" :src="showimg2" width="240" height="300"></img-self-plus>
          </div>
          <div class="col-md-6" v-for="item in otherDarginShowImgs">
            <img-self-plus v-if="item.path" :src="item.path" width="240" height="300"></img-self-plus>
          </div>
        </div>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer" v-show="false">
      <button type="button" class="btn btn-success" @click='imgclose'>关闭</button>
    </footer>
  </modal>
  <modal :show.sync="imgshow2" v-ref:modal backdrop="true">
    <header slot="modal-header" class="modal-header">
      {{ paperdata.f_entry_status }}照片
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="from-group">
        <div class="row">
          <div class="col-md-6">
            <img-self-plus v-if="this.paperdata.f_entry_status=='到访不遇'&& this.paperdata.f_noanswer_path" :src="showimg3"
                           width="282"
                           height="400"></img-self-plus>
          </div>
          <div class="col-md-6">
            <img-self-plus v-if="this.paperdata.f_entry_status=='到访不遇'&& this.paperdata.f_noanswer1_path"
                           :src="showimg5" width="282"
                           height="400"></img-self-plus>
          </div>
          <div class="col-md-6">
            <img-self-plus v-if="this.paperdata.f_entry_status=='到访不遇'&& this.paperdata.f_noanswer2_path"
                           :src="showimg6" width="282"
                           height="400"></img-self-plus>
          </div>
          <div class="col-md-6">
            <img-self-plus v-if="this.paperdata.f_entry_status=='拒检' && this.paperdata.f_rejectcheck_path"
                           :src="showimg4" width="282"
                           height="400"></img-self-plus>
          </div>
          <div class="col-md-6">
            <img-self-plus v-if="this.paperdata.f_entry_status=='拒检' && this.paperdata.f_rejectcheck1_path"
                           :src="showimg7" width="282"
                           height="400"></img-self-plus>
          </div>
          <div class="col-md-6">
            <img-self-plus v-if="this.paperdata.f_entry_status=='拒检' && this.paperdata.f_rejectcheck2_path"
                           :src="showimg8" width="282"
                           height="400"></img-self-plus>
          </div>
        </div>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer" v-show="false">
      <button type="button" class="btn btn-success" @click='imgclose'>关闭</button>
    </footer>
  </modal>
  <modal :show.sync="showModel" :width="'50%'" :backdrop="false">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        安检审核备注
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div class="row">
        <div class="form-group col-sm-4">
          <label class="font_normal_body">审核备注:</label>
          <textarea v-model="message"></textarea>
        </div>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer" style="text-align: center">
      <button class="button_search" style="margin-right: 15px" @click="auditFailOK()">确定</button>
      <button class="button_search" style="margin-right: 15px" @click="auditFailCancel()">取消</button>
    </div>
  </modal>
</template>

<script>
// import PaperUserm from './PaperUserm'
// import PaperStatem from './PaperStatem'
// import Devicesm from './Devicesm'
// import PaperFeedbackm from './PaperFeedbackm'
import html2pdf from 'html2pdf.js'
import ObjConfig from '../../utils/GerJsonObjectConfig'
import RadioGroup from 'vue-client/src/vue-strap/src/radioGroup'
import Radio from 'vue-client/src/vue-strap/src/radioBtn'
import Vue from 'vue'
import * as Util from '../Util'
import {jsonSort} from '../../utils/LdapHelper'
import {HttpResetClass} from "vue-client";

let asyncReady = async function (self) {
  // 获取配置信息
  try {
    let res = await new HttpResetClass().load('post', 'rs/sql/safe_singleTable_OrderBy', {
      data: {
        items: 'f_dir',
        tablename: 't_organization',
        condition: `id  = '${self.item.f_filialeid}'`,
        orderitem: 'id'
      }
    })/*.then(res=>{*/
    //tag
    //tag)
    console.log(res)
    if (!res.data[0].f_dir) {
      self.$showMessage("该公司无组织目录，无法获取配置文件，请联系管理员确认")
    } else {
      //this.f_dir=res.data[0].f_dir
      let url = self.newConfig == '是' ? '/safecheck/rs/safe_vue' : '/safecheck/rs/vue'
      try {
        let res1 = await new HttpResetClass().load('GET', `${url}/DevicesConfig.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {}, {
          resolveMsg: '获取居民配置项成功！',
          rejectMsg: '获取居民配置项出错！'
        })/*.then(res=>{*/
        //tag
        //this.safeConfig["民用配置项"]=Object.assign({},res.data)
        if (!Vue.config.safecheck) {
          Vue.config = {safecheck: {}}
        }
        Vue.config.safecheck.DevicesConfig = res1.data
        console.log(Vue.config.safecheck.DevicesConfig)
        /*})*/
        let res2 = await new HttpResetClass().load('GET', `${url}/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 = {}
      } catch (e) {
        self.$showMessage("获取配置文件失败" + e)
        self.loading = false
      }
    }
    if (self.data.f_recheck_id) {
      let res3 = await new HttpResetClass().load('post', 'rs/sql/safe_singleTable_OrderBy', {
        data: {
          items: '*',
          tablename: 't_check_paper',
          condition: `id  = '${self.data.f_recheck_id}'`,
          orderitem: 'id'
        }
      })
      self.lastCheckData = res3.data[0]
    }
  } catch (error) {
    // 忽略704,文件找不到异常R
    if (error.status !== 704) {
      throw error
    }
    this.loading = false
  }
}
export default {
  title: '安检单',
  props: ['f_plan_id', 'item', 'role'],
  data() {
    return {
      f_user_path:'',
      message: '',
      showButton: false,
      showModel: false,
      data: {
        f_devices: [],
        f_defect_content: ''
      },
      showPdfDownload: this.$appdata.getSingleValue('安检结果pdf下载') ? this.$appdata.getSingleValue('安检结果pdf下载') : false,
      lastCheckData: {},
      paperdata: {},
      picturename: '隐患照片',
      defectDevice: {},
      hasDevice: false,
      deviceCollect: {},
      deviceCollects: [],
      isshow: true,
      ajresult: '',
      loading: true,
      imgshow: false,
      imgshow2: false,
      isUpload: false,
      livedispose: '',
      showimg1: '',
      showimg2: '',
      showimg3: '',
      showimg4: '',
      showimg5: '',
      showimg6: '',
      showimg7: '',
      showimg8: '',
      hiddenDangerImgNumber: 0, //配置项中隐患照片数
      otherDarginShowImgs: [],//其他隐患图片
      startClick: false, //开始安检按钮是否可点击
      isStrat: false, //是否开始安检
      checkResult: {},//查询结果
      newcheckResult: {},
      timer: null,
      showModal: false,
      pic_to_be_viewed: '',
      showBack: true,
      devices: [],
      devicesAll: [],
      configAJ: [],
      configRQ: [],
      deviceconfig: {},
      newConfig: '',
      deviceconfig2: [],
      f_devices: [],
      config: {
        "燃气表": {
          "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": "number", "isshow": false, "readonly": true},
            "上期表读数": {"index": 6, "type": "number", "readonly": true, isshow: false},
            "累购气量": {"index": 7, "type": "number", "readonly": true},
            "已用气量": {"index": 8, "type": "number", "checkmust": false},//基表数
            "剩余气量": {"index": 9, "type": "number", "checkmust": false},//累购-已用
            //显示屏数  --实际剩余气量
            "气量异常差值": {"index": 10, "type": "number", "readonly": true},
            "表箱号": {"index": 11, "type": "string", "readonly": true},
            "燃气表照片": {"index": 12, "type": "picture", "checkmust": false},
          }
          // 注意，配置项的index必须与上面的固定配置保持'顺序'
        }
      },
      //金额
      config2: {
        "燃气表": {
          "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": "number", "isshow": false, "readonly": true},
            "上期表读数": {"index": 6, "type": "number", "readonly": true, isshow: false},
            "累购金额": {"index": 7, "type": "number", "readonly": true},
            "已用金额": {"index": 8, "type": "number", "checkmust": false},
            //显示屏数  --实际剩余气量
            "剩余金额": {"index": 9, "type": "number", "checkmust": false},
            "金额异常差值": {"index": 10, "type": "number", "readonly": true},
            "表箱号": {"index": 11, "type": "string", "readonly": true},
            "燃气表照片": {"index": 12, "type": "picture", "checkmust": false},
          }
        }
      },
    }
  },
  components: {
    RadioGroup,
    Radio,
  },
  computed: {
    isRecodrDownloadBtn() {
      // 投诉单下派还是处理
      let res = this.$appdata.getSingleValue('无限制录音');
      if (res == 'true') {
        return true;
      } else {
        return false;
      }
    },
    selector: {
      get() {
        return 'paper-state'
      },
      set(val) {
        if (this.isStrat) {
          this.$goto(val, {userinfo: this.data}, 'paper-router')
        } else {
          this.$showMessage('未开始安检！')
        }
      }
    },
    actionEnabled: {
      get() {
        return this.role == 'inspect'
      }
    }
  },
  methods: {
    exportToPDF() {
      const element = document.getElementById('toPdf') // 替换为您要导出的页面元素的ID
      html2pdf(element)
    },

    showAudit() {
      var audit = this.$appdata.getSingleValue('安检审核');
      if (audit == '是' && (this.item.f_approved == '未审核' || !this.item.f_approved)) {
        this.showButton = true
      }
    },
    //安检审核成功
    auditSuccesss() {
      this.loading = true;
      var reqdata = {
        audit_result: '通过',
        operator: "success",
        audit_time: Util.getNowDate(),
        user_name: this.$login.f.name,
        id: this.item.id,
        f_check_item_id: this.item.f_check_item_id
      }
      new HttpResetClass().load('POST', '/rs/logic/updateAafeAudit', {data: reqdata}, {
        resolveMsg: '安检审核成功！',
        rejectMsg: '安检审核出错！'
      }).then((res) => {
        if (res.data.code == 200) {
          this.loading = false;
          this.$back()
        }
      })
    },
    auditFail() {
      this.showModel = true;
    },
    auditFailOK() {

      this.loading = true;
      var reqdata = {
        message: this.message,
        audit_result: '不通过',
        operator: "fail",
        audit_time: Util.getNowDate(),
        user_name: this.$login.f.name,
        id: this.item.id,
        f_check_item_id: this.item.f_check_item_id
      }
      new HttpResetClass().load('POST', '/rs/logic/updateAafeAudit', {data: reqdata}, {
        resolveMsg: '安检审核成功！',
        rejectMsg: '安检审核出错！'
      }).then((res) => {
        if (res.data.code == 200) {
          this.loading = false;
          this.message = '';
          this.showModel = false;
          this.$back()
        }
      })
    },
    auditFailCancel() {
      this.showModel = false;
      this.message = '';
    },

    devicesCollect() {
      //tag
      //tag)
      //tag)
      //tag
      this.deviceCollects = []
      let checkResult = '正常'
      this.result = '正常'
      let codata = JSON.parse(JSON.stringify(this.data))
      //tag)
      for (let device in this.data) {
        let f_device_type
        if (device.startsWith("device")) {
          for (let item in this.data[device]) {
            if (this.data[device].length > 1) {
              let j = Number.parseInt(item) + 1
              f_device_type = `${this.data[device][item].f_device_type}${j}`
            } else {
              f_device_type = this.data[device][item].f_device_type
            }
            // //tag
            let deviceelse = []
            let deviceInfos = []
            for (let i in this.data[device][item].f_items) {
              let defects = ''

              let items = this.data[device][item].f_items[i]


              if ((items.type === 'selector' || items.type === 'radio' || items.type === 'checkbox' || items.type === 'picture') && items.f_item_value != null && items.f_item_value instanceof Array) {
                for (let i in items.f_item_value) {
                  let f_item_value = items.f_item_value[i]

                  //tag)
                  //tag)
                  //tag)
                  //tag)

                  if (!this.config[this.data[device][item].f_device_type].items[items.f_item_name] && (items.isdefect && (items.isdefect == 'true' || items.isdefect == true))) {
                    continue
                  }
                  /*if(items.f_is_defect != true && items.f_is_defect != 'true'){
                    continue
                  }*/
                  if (items.f_is_defect == 'true' || items.f_is_defect == true) {
                    checkResult = '有隐患'
                    this.result = '有隐患'
                    defects = `${defects}:${items.f_item_value}/`
                  }
                  /*let options = this.config[this.data[device][item].f_device_type].items[items.f_item_name].options
                  for (let option in options) {
                    if (options[option].data == f_item_value) {
                      if (options[option].isdefect == 'true' || options[option].isdefect == true) {
                        checkResult = '有隐患'
                        this.result = '有隐患'
                        defects = `${defects}:${options[option].data}/`
                        // let level = options[option].level
                      }
                    }
                  }*/
                  //tag)
                }
                if (defects != '') {
                  console.log('有隐患items', items)
                  deviceInfos.push(`${items.f_item_name}${defects.substring(0, defects.length - 1)}${items.f_else ? items.f_else : ''}`)
                }
              } else if ((items.type === 'string' || items.type === 'number') && items.f_is_defect && items.f_item_value[0]) {
                checkResult = '有隐患'
                this.result = '有隐患'
                deviceInfos.push(`${items.f_item_name}:${items.f_item_value[0]}`)

              } else if (items.f_item_name == '金额异常差值') {
                var deviation = this.$appdata.getSingleValue('金额异常差值允许误差')
                //tag
                if (parseFloat(items.f_item_value[0]).toString() != "NaN" && parseFloat(deviation).toString() != "NaN") {
                  if (parseFloat(items.f_item_value[0]) > parseFloat(deviation) || parseFloat(items.f_item_value[0]) < parseFloat(deviation) * -1) {
                    checkResult = '有隐患'
                    this.result = '有隐患'
                    deviceInfos.push(`${items.f_item_name}:${items.f_item_value[0]}`)
                  }
                }
              } else if (items.f_item_name == '气量异常差值') {
                var deviation = this.$appdata.getSingleValue('气量异常差值允许误差')
                //tag
                if (parseFloat(items.f_item_value[0]).toString() != "NaN" && parseFloat(deviation).toString() != "NaN") {
                  if (parseFloat(items.f_item_value[0]) > parseFloat(deviation) || parseFloat(items.f_item_value[0]) < parseFloat(deviation) * -1) {
                    checkResult = '有隐患'
                    this.result = '有隐患'
                    deviceInfos.push(`${items.f_item_name}:${items.f_item_value[0]}`)
                  }
                }
              }
              if (!this.config[this.data[device][item].f_device_type].items[items.f_item_name]) {
                // console.log('this.config[this.data[device][item].f_device_type]', this.config[this.data[device][item].f_device_type])
                // console.log('this.deviceconfig2', this.deviceconfig2)
                for (let dev in this.deviceconfig2) {
                  if (this.deviceconfig2[dev].checkname == this.data[device][item].f_device_type) {
                    this.deviceconfig2[dev].items.push({
                      lname: items.f_item_name
                    })
                  }
                }
              }
              //tag)
              //tag
              //tag
              if (items.type === 'selector') {
                items.selected = []
              } else if (items.type === 'inputSelector') {
                items.selected = ''
              }
            }


            //tag
            this.$set('deviceCollect.name', f_device_type)
            this.$set('deviceCollect.value', checkResult)
            this.$set('deviceCollect.devices', deviceInfos)
            this.$set('deviceCollect.else', deviceelse)
            console.log('deviceCollect.devices', this.deviceCollect.devices)
            console.log('deviceCollect.else', this.deviceCollect.else)
            //tag)
            if (this.deviceCollect.name) {
              //tag
              this.deviceCollects.push(JSON.parse(JSON.stringify(this.deviceCollect)))
            }

            checkResult = '正常'
            this.deviceCollect = {}
          }
        }
      }
      if (this.deviceCollects.length > 0) {
        this.hasDevice = true
      }
      this.ajresult = JSON.parse(this.data.f_defect_content).result
      this.showimg3 = this.data.f_noanswer_path
      this.showimg5 = this.data.f_noanswer1_path
      this.showimg6 = this.data.f_noanswer2_path
      this.showimg4 = this.data.f_rejectcheck_path
      this.showimg7 = this.data.f_rejectcheck1_path
      this.showimg8 = this.data.f_rejectcheck2_path
      this.paperdata = this.data
      this.f_user_path = this.paperdata.f_user_pictures ? JSON.parse(this.paperdata.f_user_pictures)[0].f_user_path : ''
      this.loading = false
    },
    imgclose() {
      this.imgshow = false
    },
    putDevices() {
      ////tag
      this.$set('data.approve', "true")
      this.$set('data.writeback', "false")
      if (Vue.config.safecheck.ApproveConfig != undefined) {
        if (Vue.config.safecheck.ApproveConfig.approve != undefined) {
          this.$set('data.approve', Vue.config.safecheck.ApproveConfig.approve)
        }
        if (Vue.config.safecheck.ApproveConfig.writeback != undefined) {
          this.$set('data.writeback', Vue.config.safecheck.ApproveConfig.writeback)
        }
        if (Vue.config.safecheck.ApproveConfig.livedispose != undefined) {
          this.livedispose = Vue.config.safecheck.ApproveConfig.livedispose
        }
        if (Vue.config.safecheck.ApproveConfig.hiddendanger != undefined) {
          if (parseInt(Vue.config.safecheck.ApproveConfig.hiddendanger) >= 3) {
            this.hiddenDangerImgNumber = 3
          } else {
            this.hiddenDangerImgNumber = parseInt(Vue.config.safecheck.ApproveConfig.hiddendanger)
          }
        }
      }
      //tag

      //tag)
      if (!this.item.f_safecheck_type) {
        this.config = this.extend(this.config, Vue.config.safecheck[Vue.config.safecheck.SafecheckType['年度普检'][this.item.f_check_type]])
      } else {
        if (Vue.config.safecheck.DevicesConfig != undefined)
          this.config = this.extend(this.config, Vue.config.safecheck[Vue.config.safecheck.SafecheckType[this.item.f_safecheck_type][this.item.f_check_type]])
      }
      //遍历安检项配置
      for (let i in this.config) {
        //取得安检项索引值
        let n = this.config[i].index
        this.devices[n - 1] = {device: i, n: n, checkmust: this.config[i].checkmust}
        this.$set('data.' + 'device' + n, [])
        let items = []
        for (let it in this.config[i].items) {
          //赋值下拉选项
          if (this.config[i].items[it].type == 'selector') {
            for (let op in this.config[i].items[it].options)
              if (this.config[i].items[it].options[op].isdefault == true) {
                items.push({
                  f_defect_level: this.config[i].items[it].options[op].level,
                  f_is_defect: this.config[i].items[it].options[op].isdefect,
                  f_item_name: it,
                  f_item_value: this.config[i].items[it].options[op].data,
                  f_path: "",
                  type: "selector"
                })
              }
          }
        }
        n = n + 1
      }

    },
    showpath(val1, val2) {
      //tag
      //tag
      if (val1) {
        this.showimg1 = val1
        this.picturename = val2
        this.imgshow = true
      }
    },
    showpicture(val1, val2) {
      //tag
      if (val2 == '气量异常差值' || val2 == '金额异常差值') {
        return
      }
      for (let i = 0; i < this.devicesAll.length; i++) {
        for (let j = 0; j < this.devicesAll[i].length; j++) {
          if (this.devicesAll[i][j].f_device_type == val1) {
            for (let k = 0; k < this.devicesAll[i][j].f_items.length; k++) {
              if (this.devicesAll[i][j].f_items[k].f_item_name == val2) {
                if (!this.devicesAll[i][j].f_items[k].f_is_defect) {
                  return false
                } else {
                  this.showimg1 = this.devicesAll[i][j].f_items[k].f_path
                  this.showimg2 = this.devicesAll[i][j].f_items[k].f_second_path
                  this.otherDarginShowImgs = []
                  for (let l = 0; l < this.hiddenDangerImgNumber; l++) {
                    let img = {path: ''}
                    if (this.devicesAll[i][j].f_items[k]['f_p' + (l + 1) + '_path']) {
                      img.path = this.devicesAll[i][j].f_items[k]['f_p' + (l + 1) + '_path'] + '?' + Math.random()
                      this.otherDarginShowImgs.push(img)
                    }
                  }
                  this.picturename = '隐患照片'
                  this.imgshow = true
                  return true
                }
              }
            }

          }
        }
      }
    },
    isred(val1, val2) {
      //tag
      if (val2 == '气量异常差值' || val2 == '金额异常差值') {
        return
      }
      for (let i = 0; i < this.devicesAll.length; i++) {
        for (let j = 0; j < this.devicesAll[i].length; j++) {
          if (this.devicesAll[i][j].f_device_type == val1) {
            for (let k = 0; k < this.devicesAll[i][j].f_items.length; k++) {
              if (this.devicesAll[i][j].f_items[k].f_item_name == val2) {
                if (!this.devicesAll[i][j].f_items[k].f_is_defect) {
                  return false
                } else {
                  return true
                }
              }
            }

          }
        }
      }
    },
    showpicture2() {
      this.imgshow2 = true
    },
    getDeviceValue(val1, val2) {
      let aa = ''
      for (let i = 0; i < this.devicesAll.length; i++) {
        for (let j = 0; j < this.devicesAll[i].length; j++) {
          if (this.devicesAll[i][j].f_device_type == val1) {
            for (let k = 0; k < this.devicesAll[i][j].f_items.length; k++) {
              if (this.devicesAll[i][j].f_items[k].f_item_name == val2) {
                if (this.devicesAll[i][j].f_items[k].f_item_lists[0]) {
                  for (let l = 0; l < this.devicesAll[i][j].f_items[k].f_item_lists.length; l++) {
                    let val = this.devicesAll[i][j].f_items[k].f_item_lists[l].f_item_value
                    aa += (val === null ? '空' : val) + ' '
                  }
                  return aa
                }
              }
            }

          }
        }
      }

    },
    getDevicePath(val1, val2) {
      for (let i = 0; i < this.devicesAll.length; i++) {
        for (let j = 0; j < this.devicesAll[i].length; j++) {
          if (this.devicesAll[i][j].f_device_type == val1) {
            for (let k = 0; k < this.devicesAll[i][j].f_items.length; k++) {
              if (this.devicesAll[i][j].f_items[k].f_item_name == val2) {
                return this.devicesAll[i][j].f_items[k].f_path
              }
            }

          }
        }
      }

    },
    getDeviceAll() {
      let keyall = Object.keys(this.data)
      for (let i = 0; i < keyall.length; i++) {
        //tag)
        if ((keyall[i].startsWith('f_devices') || keyall[i].startsWith('devices')) && keyall[i] != 'deviceundefined') {
          this.devicesAll.push(this.data[keyall[i]])
          //tag
        }
      }
      //tag
      //tag)
      this.devicesCollect()

    },

    back() {
      if (this.role == 'inspect') {
        if (!this.isStrat) {
          this.$back()
          return
        } else {
          this.savePaper(true).then(() => {
            this.$back()
            this.isStrat = false
          })
        }
      } else {
        this.$back()
      }
    },
    checkIsStart() {
      alert('asdad')
      return
    },

    viewPic(fileName) {
      //tag
      if (this.role == 'view') {
        if (!fileName.endsWith('nopic.png')) {
          this.pic_to_be_viewed = fileName
          this.showModal = true
        }
      } else {
        HostApp.viewPic(fileName)
      }
    },
    tick() {
      this.timer = null
      this.data.f_offsite_time = Util.toStandardTimeString()
      this.timer = window.setTimeout(this.tick, 1000)
    },
    getRepairState() {
      let repaired = true
      this.data.f_defects.forEach((defect) => {
        repaired = repaired & (defect.f_ratification == '已处理')
      })
      return repaired
    },
    verifyRepairDefects() {
      this.data.f_repair_date = Util.toStandardTimeString()
      this.data.f_repaired = this.getRepairState() ? '已修' : '在修'
    },
    genuineSave(saveOnly) {
      HostApp.__this__.save(saveOnly)
      if (!saveOnly)
        HostApp.__this__.disableTimer()
      HostApp.__callback__ = null
      HostApp.__this__ = null
    },
    setUrgency() {
      this.data.f_defect_urgency = 'Z'
      let that = this
      this.data.f_defects.forEach(function (defect) {
        if (that.data.f_defect_urgency > defect.f_defect_level.charAt(0))
          that.data.f_defect_urgency = defect.f_defect_level.charAt(0)
      })
      if (this.data.f_defect_urgency == 'Z')
        this.data.f_defect_urgency = null
    },
    disableTimer() {
      if (this.timer) {
        window.clearTimeout(this.timer)
        this.timer = null
      }
    },
    loaded(paper) {
      if (!paper.hasOwnProperty('id')) {
        this.$showMessage("该安检单在手机上已经不存在，可能是卸载过程序。可以进入重新安检，或返回安检计划。")
        this.init()
      } else {
        Util.booleanFilter(paper)
        HostApp.__this__.$set('data', paper)
        HostApp.__this__.$goto('paper-state', {}, 'paper-router')
        // 如果打回重检则重新计时
        //tag
        if (HostApp.__this__.role == 'inspect'
          && HostApp.__this__.data.f_approved
          && HostApp.__this__.data.f_approved == '打回') {
          //tag
          HostApp.__this__.data.f_onsite_time = Util.toStandardTimeString()
          HostApp.__this__.tick()
        }
      }
      HostApp.__callback__ = null
      HostApp.__this__ = null
    },
    S4() {
      return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    },
    init() {
      this.data.f_noplan_item_id = this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4()
      this.data.ename = Vue.user.ename
      this.data.f_outlets = Vue.user.f_parentname
      this.data.f_meetunit = Vue.user.orgpathnames
      this.data.orgpathstr = Vue.user.orgpathstr
      this.data.f_check_item_id = this.item.id
      this.data.f_check_plan_id = this.f_plan_id
      this.data.f_checker_id = Vue.user.id
      this.data.f_checker_name = Vue.user.name
      this.data.f_check_type = this.item.f_user_type
      this.data.f_subcompany = this.item.f_subcompany
      this.data.f_approved = this.item.f_approved
      this.data.f_repair_approved = this.item.f_repair_approved
      this.data.f_no_checkplan = this.item.f_no_checkplan
      this.data.f_approved = this.item.f_approved
      this.data.f_filialeid = this.item.f_filialeid
      this.data.f_orgstr = this.item.f_orgstr
      this.data.version = this.item.version
      this.$set('data.f_meters', this.item.f_plan_meters)
      this.$set('data.f_userinfo_code', this.item.f_userinfo_code)
      // 安检状态
      this.$set('data.f_entry_status', '入户')
      this.$set('data.f_usegas', '已使用')
      this.$set('data.f_state', this.item.f_state)
      // 用户信息
      this.$set('data.f_user_name', this.item.f_user_name)
      this.$set('data.f_user_phone', this.item.f_user_phone)
      this.$set('data.f_userinfoid', this.item.f_userinfoid)
      this.$set('data.f_address', this.item.f_address)
      this.$set('data.f_card_id', this.item.f_card_id)
      this.$set('data.f_area', this.item.f_area)
      this.$set('data.f_street', this.item.f_street)
      this.$set('data.f_room', this.item.f_room)
      this.$set('data.f_building', this.item.f_building)
      this.$set('data.f_unit', this.item.f_unit)
      this.$set('data.f_floor', this.item.f_floor)
      this.$set('data.f_residential_area', this.item.f_residential_area)
      this.$set('data.f_idnumber', this.item.f_idnumber)
      this.$set('data.f_comments', this.item.f_comments)
      this.$set('data.f_userproperties', this.item.f_userproperties)
      // 处置方式
      this.$set('data.f_no_gas_device', false)
      this.$set('data.f_close_valve', false)
      this.$set('data.f_unload_battery', false)
      if (this.data.f_check_item_id == '' && this.item.f_no_checkplan == '无计划安检') {
        this.data.f_check_item_id = this.data.f_noplan_item_id
      }

      //房屋结构
      // this.$set('data.f_room_style', '多层')
      //供暖方式
      //  this.$set('data.f_heating_style', '热力公司集中供暖')
      if (this.item.f_plan_meters) {
        for (let de in this.devices) {
          this.$set('data.device' + this.devices[de].n, [])
          for (let i = 0; i < this.item.f_plan_meters.length; i++) {
            if (this.item.f_plan_meters[i].f_meter_type) {
              if (this.devices[de].device == "燃气表" && this.item.f_plan_meters[i].f_meter_type.indexOf('机表') > 0) {
                delete this.config['燃气表']['items']['累计购气量']
                this.data['device' + this.devices[de].n].push({
                  f_device_type: "燃气表",
                  f_items: [{
                    f_defect_level: null,
                    f_device_id: "",
                    f_is_defect: "",
                    f_item_name: "表品牌",
                    f_item_value: this.item.f_plan_meters[i].f_aliasname,
                    f_path: "",
                    type: "string"
                  },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "位置",
                      f_item_value: this.item.f_plan_meters[i].f_weizhi,
                      f_path: "",
                      type: "selector"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表号",
                      f_item_value: this.item.f_plan_meters[i].f_meter_no,
                      f_path: "",
                      type: "number"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表封号",
                      f_item_value: this.item.f_plan_meters[i].f_metertitles,
                      f_path: "",
                      type: "number"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表型号",
                      f_item_value: this.item.f_plan_meters[i].f_diaphgram_size,
                      f_path: "",
                      type: "selector"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表底数",
                      f_item_value: this.item.f_plan_meters[i].f_prior_reading,
                      f_path: "",
                      type: "number"
                    }
                  ]
                })
              } else if (this.devices[de].device == "燃气表") {
                delete this.config['燃气表']['items']['表底数']
                this.data['device' + this.devices[de].n].push({
                  f_device_type: "燃气表",
                  f_items: [{
                    f_defect_level: null,
                    f_device_id: "",
                    f_is_defect: "",
                    f_item_name: "表品牌",
                    f_item_value: this.item.f_plan_meters[i].f_aliasname,
                    f_path: "",
                    type: "string"
                  },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "位置",
                      f_item_value: this.item.f_plan_meters[i].f_weizhi,
                      f_path: "",
                      type: "selector"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表号",
                      f_item_value: this.item.f_plan_meters[i].f_meter_no,
                      f_path: "",
                      type: "number"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表封号",
                      f_item_value: this.item.f_plan_meters[i].f_metertitles,
                      f_path: "",
                      type: "number"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "表型号",
                      f_item_value: this.item.f_plan_meters[i].f_diaphgram_size,
                      f_path: "",
                      type: "selector"
                    },
                    {
                      f_defect_level: null,
                      f_device_id: "",
                      f_is_defect: "",
                      f_item_name: "累计购气量",
                      f_item_value: this.item.f_plan_meters[i].f_prior_reading,
                      f_path: "",
                      type: "number"
                    }
                  ]
                })
              }
            }
          }
        }
      }

      this.$goto('paper-state', {}, 'paper-router')
    },
    extend(initalObj, finalObj) {
      var obj = finalObj || {};
      for (var i in initalObj) {
        var prop = initalObj[i];

        // 避免相互引用对象导致死循环，如initalObj.a = initalObj的情况
        if (prop === obj) {
          continue;
        }

        if (typeof prop === 'object') {
          if (obj[i]) {
            this.extend(obj[i], prop)
          } else {
            obj[i] = prop;
          }
        }
      }
      return obj;
    },
    //获取当前时间
    getNowFormatDate() {
      var date = new Date();
      var seperator1 = "-";
      var seperator2 = ":";
      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() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
      return currentdate;
    }
  },
  ready() {
    setTimeout(() => {
      this.loading = false;
    }, 3000)
    this.$resetpost(`rs/path/getUserinfomation`, {data: {condition: `id = '${this.item.id}'`}}).then((respanse) => {
      //tag
      this.paperdata = respanse.data[0]
      this.paperdata.f_overall_imgs.forEach(item=>{
        item.f_overall_path = 'rs/image/file/'+item.f_overall_path
      })
      this.deviceconfig2 = Object.assign(this.data, respanse.data[0].f_devices)
    })


  },
  watch: {
    //   'isUpload'(val){
    //     //tag
    //   }
  },
  destroyed() {
    //tag
    this.disableTimer()
  }
}

</script>
<style scoped>
.table-striped thead tr th {
  background-color: rgb(223, 237, 251);
  padding: 10px;
  border-left: solid 0px #dae4f2;
  border-top: solid 1px #dae4f2;
  border-right: none;
  border-bottom: none;
  text-align: center;
  color: black;
}
</style>
