<style>
  .divmask {
    /*pointer-events: none;*/
  }
</style>

<template>
  <div class="auto">
    <!--<a href="#" class="btn btn-primary" @click="$back('items')">&lt;&lt;</a>-->
    <!--<a href="#" v-show="actionEnabled" class="btn btn-primary" @click="savePaper(true)" v-if="item.f_upload_state != '已传'">保存</a>-->
    <!--<a id="upload" href="# " v-show="actionEnabled" class="btn btn-primary" @click="uploadPaper" v-if="item.f_upload_state != '已传'">上传</a>-->
      <radio-group :value.sync="selector" type="info" buttons="false" style="width: 100%">
        <radio value="paper-state" style="width: 25%">安检概况</radio>
        <radio value="paper-user" style="width: 25%">用户信息</radio>
        <radio value="devices" style="width: 25%">安检选项</radio>
        <radio value="paper-feedback" style="width: 25%">拍照上传</radio>
      </radio-group>
    <route :comp="{name: 'void-page'}"   name="paper-router"></route>
    <modal :show.sync="showModal">
      <div slot="modal-header" class="modal-header">
        <h4 class="modal-title">
          照片浏览
        </h4>
      </div>
      <div slot="modal-body" class="modal-body">
        <img :src="pic_to_be_viewed" width="420" height="560">
      </div>
      <div slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-default" @click="showModal = false">确认</button>
      </div>
    </modal>
    <!--<back-page :need-back='true'  @flag="back()" v-show="showBack"></back-page>-->
  </div>
  <!--<work-busy :is-busy="isUpload"></work-busy>-->
  <!--<modal :show.sync="isUpload">-->
    <!--<div slot="modal-header" class="modal-header">-->
      <!--<h4 class="modal-title">-->
        <!--提示-->
      <!--</h4>-->
    <!--</div>-->
    <!--<div slot="modal-body" class="modal-body">-->
      <!--正在工作，请等待。。。。。-->
    <!--</div>-->
    <!--<div slot="modal-footer" class="modal-footer">-->
      <!--&lt;!&ndash;<button type="button" class="btn btn-default" @click="showModal = false">确认</button>&ndash;&gt;-->
    <!--</div>-->
  <!--</modal>-->
</template>

<script>
  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 co from 'co'

  let getRepairParam = function * (self){
    console.log('self.meading===>'+self.meading)
    let data = {
      model: self.model, loginUser: {
        name: Vue.user.name,
        ename: Vue.user.ename
      }, user: self.user, callObj: self.callObj
    }
    if(self.meading == '转维修员'){
      data.toRepair = '一级派单'
    }
    data.model.f_attendant = data.loginUser.name
    console.log('===================')
    console.log(data)
    let res
    let errString = self.errorVerify()
    if(errString){
      console.log(errString)
      if (Vue.android)
        self.undo()
      self.$showMessage(errString)
      return
    } else {
      if(self.role == 'inspect'){
        console.log("转维修数据1：==》"+JSON.stringify(data))
        let checkResult = '正常'
        let options = [{"data": "已处理"},{"data": "未处理"}]
        let value = ''
        let codata = JSON.parse(JSON.stringify(self.data))
        for(let device in codata){
          console.log('转维修codata[device]'+JSON.stringify(codata[device]))
          let f_device_type
          if(device.startsWith("device")){
            for(let item in codata[device]) {
              if(codata[device].length > 1 ){
                let j = Number.parseInt(item)+1
                f_device_type = `${codata[device][item].f_device_type}${j}`
              }else{
                f_device_type = codata[device][item].f_device_type
              }
              // console.log('codata[device][item]=>',codata[device][item])
              let details = []
              for(let i in codata[device][item].f_items){
                let items = codata[device][item].f_items[i]
                console.log('items==>'+JSON.stringify(items))
                if(items.f_is_defect == true || items.f_is_defect == 'true'){
                  checkResult = '有隐患'
                  console.log('类型----',f_device_type)
                  // let res = yield self.$resetpost(`${self.Url}/api/af-safecheck/sql/getDeviceItem`,{data:{f_device_id:codata[device][item].f_device_id,f_item_name:items.f_item_name}})
                  // console.log('获取安检设备信息结果=》'+JSON.stringify(res))
                  self.$set('detail.f_defect_id', items.id)
                  self.$set('detail.f_project',`${items.f_item_name}：${items.f_item_value}`)
                  self.$set('detail.type',items.type)
                  self.$set('detail.options',options)
                  details.push(JSON.parse(JSON.stringify(self.detail)))
                }
                if(items.type == 'selector'){
                  items.selected = ''
                }
                self.detail = {}
              }
              console.log('details',details)
              self.$set('defectDevice.f_type',f_device_type)
              self.$set('defectDevice.details',details)
              if(self.defectDevice.details.length >0 ){
                self.repairitems.push(JSON.parse(JSON.stringify(self.defectDevice)))
              }
              self.defectDevice = {}
              console.log('repairitems===>'+self.repairitems)
            }
          }
        }
        self.$set('model.f_repairitems.data',self.repairitems)

        console.log("转维修数据2：==》"+JSON.stringify(data))
        HostApp.__this__ = self
        self.logicWithHint('safecheckToRepair',{data:data,f_paper_id:self.data.f_paper_id},'javascript:HostApp.__this__.safecheckToRepairCallBack()',1)

        // console.log('res==========')
        // console.log(res.code)
        // console.log(res.data)
        // if(res.code == 200){
        //   self.isSafeCheckToRepair = true
        //   // self.undo()
        //   // self.$set('paper.f_SafeToRepair_id',res.data.f_service_id)
        //   // console.log('更新维修单id')
        //   // self.$resetpost(`${self.Url}/api/af-safecheck/logic/updatePaperRepair`,{data:{f_paper_id:self.data.f_paper_id,f_SafeToRepair_id:res.data.f_service_id}}).then((ret)=>{
        //   //   console.log('ret==>'+ret)
        //   //   if(ret.data.code ==200){
        //   console.log('维修单id修改成功')
        //   self.$showMessage('上传并转维修成功！')
        //   self.$back()
        //     // }else{
        //     //   self.$showMessage('安检转维修失败！')
        //     // }
        //   // }).catch(v=>{
        //   //   console.log('v=>'+JSON.stringify(v))
        //   //   self.$showMessage('安检转维修失败！')
        //   // })
        // }else{
        //   self.$showMessage('安检转维修失败！')
        // }
      }
    }
  }



  export default {
    title: '安检单',
    props: ['f_plan_id', 'item', 'role'],
    data() {
      return {
        data: {
          f_devices: [],
          f_defect_content:''
        },
        isUpload:false,
        onlySave:true, //判断保存还是保存并上传
        livedispose:'',
        startClick:false, //开始安检按钮是否可点击
        isStrat: false, //是否开始安检
        checkResult:{},//查询结果
        newcheckResult:{},
        timer: null,
        showModal: false,
        pic_to_be_viewed: '',
        showBack:true,
        devices: [],
        f_devices : [],
        isToRepair:false,
        clickBack:true, //是否点击返回按钮
        isSafeCheckToRepair:false,//是否转维修
        Url:this.$androidUtil.getProxyUrl(),
        detail:{},
        defectDevice:{},
        user:{},
        model: {  //转维修数据
          // 一次派单
          serviceacitivity: [{
            f_service_acitivity_type: '派单'
          }],
          f_source:'安检',
          f_service_id: '',
          f_contact_phone: '',
          f_meetunit: '',
          f_phone: '',
          f_user_name: '',
          f_address: '',
          f_repair_date: Util.toStandardTimeString(),
          f_card_id: '',
          // f_department: '', 站点选择
          f_reciever:'',
          f_remarks: '',
          f_user_type: '',
          f_area: '',
          f_unit_name:'',
          f_street: '',
          f_residential_area: '',
          f_building: '',
          f_unit: '',
          f_floor: '',
          f_room: '',
          aState: null,
          f_repairtype: '',
          f_repairitems:{},
        },
        repairitems:[],
        meading:'转站点',
        config: {
          "燃气表":{
            "checkmust":true,
            "items":{
              "燃气表照片":{"index":1,"type":"picture"},
              "表品牌":{"index":2,"type":"string","readonly":false},
              "表号":{"index":3,"type":"string","readonly":true},
              "表封号":{"index":4,"type":"number","readonly":false},
              "表型号":{"index":5,"type":"string","readonly":false},
              "位置":{"index":6,"type":"string","readonly":false},
              "表底数":{"index":7,"type":"number","readonly":false},
              "累购气量":{"index":8,"type":"number","readonly":true},
              "累购金额":{"index":8,"type":"number","readonly":true},
              "左右表":{"index":9,"type":"string","readonly":false}
            }
          }
        }
      }
    },
    components: {
      RadioGroup,
      Radio
    },
    computed: {
      selector: {
        get() {
          return 'paper-state'
        },
        set(val) {
          console.log('当前的this.data.f_entry_status==》'+this.data.f_entry_status)
          if(this.data.f_entry_status == '入户'){
            if(this.isStrat){
              var pardate = {
                _this:this,
                tittle:'安检详情',
                safe:true
              }
              // this.$dispatch('gotoson',pardate)
              this.$goto(val, {userinfo:this.data}, 'paper-router')
            }else{
              this.$showMessage('未开始安检！')
            }
          }else{
            var pardate = {
              _this:this,
              tittle:'安检详情',
              safe:true
            }
            // this.$dispatch('gotoson',pardate)
            this.$goto(val, {userinfo:this.data}, 'paper-router')
          }
        }
      },
      actionEnabled: {
        get() {
          return this.role == 'inspect'
        }
      }
    },
    methods: {
      back(){
        if (this.role == 'inspect') {
          if(!this.isStrat){
            this.$back()
            return
          }else{
            this.clickBack = true
            this.save()
          }
        }else{
          this.$back()
        }
      },
      checkIsStart(){
        alert('asdad')
        return
      },
      viewPic(fileName) {
        console.log('view pic: ' + fileName)
        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() ? '已修' : '在修'
      },
      // async savePaper(saveOnly) {
      //   console.log('savePaper-->isUpload'+this.isUpload)
      //   console.log('保存')
      //   if(this.role == 'repair') {
      //     let errorMsg = this.verifyRepairDefects()
      //     if(errorMsg) {
      //       this.$showMessage(errorMsg)
      //       return false
      //     }
      //     this.save()
      //   } else {
      //     //保存时做校验
      //
      //     if(saveOnly){
      //       let errString = this.errorVerify()
      //       if (errString) {
      //         this.data.f_complete = '未完成'
      //         this.disableTimer()
      //         this.save()
      //       } else {
      //         console.log('赋值前',this.data)
      //         if(!this.data.f_offsite_time){
      //           this.$set('data.f_offsite_time', Util.toStandardTimeString())
      //         }
      //         console.log('赋值后',this.data)
      //         this.data.f_complete = '已完成'
      //         this.disableTimer()
      //         this.save()
      //       }}}
      //   //   }else {
      //   //     let errString = this.errorVerify()
      //   //     console.log('errString-->isUpload'+this.isUpload)
      //   //     if (errString) {
      //   //       console.log(errString)
      //   //       console.log('Vue.android',Vue.android)
      //   //       console.log('this.isUpload',this.isUpload)
      //   //       if (Vue.android){
      //   //         // if(this.isUpload){
      //   //         //   this.isUpload = false
      //   //         // }
      //   //         this.$showMessage(errString)
      //   //       }
      //   //       return
      //   //     } else {
      //   //       if(!this.data.f_offsite_time){
      //   //         this.$set('data.f_offsite_time', Util.toStandardTimeString())
      //   //       }
      //   //       console.log('赋值后',this.data)
      //   //       this.data.f_complete = '已完成'
      //   //       this.disableTimer()
      //   //       return this.uploadCheckPaper()
      //   //     }
      //   //   }
      //   // }
      // },
      genuineSave(saveOnly) {
        HostApp.__this__.save(saveOnly)
        if(!saveOnly)
          HostApp.__this__.disableTimer()
        HostApp.__callback__ = null
        HostApp.__this__ = null
      },
      // uploadPaper() {
      //   // this.isUpload = true
      //   console.log('uploadPaper-->isUpload'+this.isUpload)
      //   this.savePaper(false).then((res) => {
      //     console.log(`res=${res}`)
      //     // console.log(`改变前this.isUpload=${this.isUpload}`)
      //     // this.isUpload = false
      //     // console.log(`改变后this.isUpload=${this.isUpload}`)
      //     if(res != true){
      //       console.log('失败')
      //       return
      //     }else{
      //       this.$back()
      //     }
      //   })
      // },
      errorVerify() {
        let hasError = this.verifyState()
        if(hasError)
          return hasError

        if(this.data.f_entry_status != '入户')
          return null
        hasError = this.verifyUser()
        if(hasError)
          return hasError
        hasError = this.verifyDevices()
        if(hasError)
          return hasError
        hasError = this.verifyFeedback()
        if(hasError)
          return hasError
      },
      verifyState() {
        if(Vue.android && this.data.f_entry_status == '未使用天然气' && this.data.f_nongasuser_path == Vue.nopic)
          return '未使用天然气则必须拍照'
        if(Vue.android && this.data.f_entry_status == '到访不遇' && this.data.f_noanswer_path == Vue.nopic)
          return  '到访不遇必须拍照'
      },
      verifyUser() {
        let prefix = '用户基本信息：'
        if(Util.required(this.data.f_user_name))
          return prefix + '用户名必须输入'
        if(Util.required(this.data.f_user_phone))
          return prefix + '用户电话必须输入'
        // if(Util.required(this.data.f_residential_area))
        //   return prefix + '小区名称必须输入'
        if(Util.required(this.data.f_address))
          return prefix + '地址必须输入'
      },
  verifyDevices() {
    for (let dev in this.config) {
      if (this.config[dev].checkmust == true) {
      let error = true
      for(let device in this.data) {
        if (device.startsWith("device")) {
            for (let item in this.data[device]) {
              if (this.data[device].length != 0 && this.data[device][item].f_device_type == dev) {
                error = false
              }
            }
          }
        }
        if (error) {
          return "请检查" + dev
        }
      }
    }

    for (let dev in this.config) {
      for(let device in this.data) {
        if (device.startsWith("device")) {
          for (let item in this.data[device]) {
            //检查每一条安检结果
            if (this.data[device].length != 0 && this.data[device][item].f_device_type == dev) {
              for (let i in this.data[device][item].f_items) {
                for (let it in this.config[dev].items) {
                  if (this.config[dev].items[it].checkmust == true && this.data[device][item].f_items[i].f_item_value == '' && this.data[device][item].f_items[i].f_path == '' && it == this.data[device][item].f_items[i].f_item_name) {
                    return dev + (this.data[device].indexOf(this.data[device][item]) + 1) + this.data[device][item].f_items[i].f_item_name + "未检查"
                  }
                }
                //检查安检下拉结果
                if (this.data[device][item].f_items[i].type == 'selector') {
                  if (this.data[device][item].f_items[i].f_is_defect == true && this.data[device][item].f_items[i].f_path == Vue.nopic) {
                    return dev + (this.data[device].indexOf(this.data[device][item]) + 1) + this.data[device][item].f_items[i].f_item_name + this.data[device][item].f_items[i].f_item_value + "选中必须拍照"
                  }
                }
              }
            }
          }
        }
      }
    }
  },


      verifyFeedback() {
        let prefix = '用户反馈：'
        console.log('this.data.f_overall_imgs==>'+this.data.f_overall_imgs.toString())
        console.log('this.data.f_overall_imgs.length==>'+this.data.f_overall_imgs.length)
        if(Vue.android && (!this.data.f_overall_imgs || this.data.f_overall_imgs.length == 0) && this.data.f_entry_status == '入户')
          return prefix + '必须有安检总体照片'
        if(Vue.android && this.data.f_defect_notified && this.data.f_notified_path == Vue.nopic)
          return prefix + '下发安检通知书则必须给通知书拍照'
        if(!this.data.f_client_evaluation && this.data.f_entry_status == '入户')
          return  prefix + '请选择服务评价'
      },

      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
      },

      getAllDefect() {
        let checkResults = {
          result: '正常',
          data: []
        }
        let value = ''
        let codata = JSON.parse(JSON.stringify(this.data))
        console.log('config =====> ' + JSON.stringify(this.config))
        console.log('codata =====> ' + JSON.stringify(codata))
        codata.f_devices = []
        this.f_devices = []
        for (let device in codata) {
          let f_device_type
          if (device.startsWith("device")) {
            console.log('codata[device] =====> ' + JSON.stringify(codata[device]))
            let hasOther = ''
            let otherValue = null
            for (let item in codata[device]) {
              codata[device][item].f_create_time = Util.toStandardTimeString()
              // if (codata[device].length > 1) {
              //     let j = Number.parseInt(item) + 1
              //     f_device_type = `${codata[device][item].f_device_type}${j}`
              // } else {
              //     f_device_type = codata[device][item].f_device_type
              // }
              // console.log('codata[device][item]=>',codata[device][item])
              for (let i in codata[device][item].f_items) {

                console.log('i' + i)
                if(i == 'sum'){
                  continue
                }
                console.log('codata[device][item].f_items' + JSON.stringify(codata[device][item].f_items))
                var items = codata[device][item].f_items[i]
                items.f_create_time = Util.toStandardTimeString

                console.log('之前items' + JSON.stringify(items))
                items.f_item_lists = []
                console.log('之后items' + JSON.stringify(items))
                // console.log('items' + JSON.stringify(items))
                // console.log(`type => ${JSON.stringify(codata[device][item].f_device_type)} name => ${JSON.stringify(items.f_item_name)} value => ${JSON.stringify(items.f_item_value)}`)
                // console.log(`f_is_defect => ${this.config[codata[device][item]
                //     .f_device_type]
                //     .items[items.f_item_name]
                //     .options
                //     .find((option)=>option.data === items.f_item_value)
                //     .map((option)=>option.f_is_defect)}`)
                // if (items.f_is_defect && (items.f_is_defect == true || items.f_is_defect == 'true')) {
                //     console.log('进入有隐患')
                //     checkResults.result = '有隐患'
                //     console.log('有隐患items.f_item_name==》' + JSON.stringify(items.f_item_name))
                //     console.log('有隐患items.f_item_value==》' + JSON.stringify(items.f_item_value))
                //     // this.$set('checkResult.' + items.f_item_name, items.f_item_value)
                //       this.checkResult[items.f_item_name] = items.f_item_value
                //     console.log('有隐患checkResult==》' + JSON.stringify(this.checkResult))
                //     // this.$set('checkResultsss.' + items.f_item_name, `${f_device_type}${items.f_item_value}`)
                //     // console.log('有隐患checkResultsss==》' + JSON.stringify(this.checkResultsss))
                // }
                if (items.type == 'selector') {
                  items.selected = []
                } else if (items.type == 'inputSelector') {
                  items.selected = ''
                }
                //遍历配置项 将所选隐患项的配置信息放入保存的数据中
                let f_is_defect   //是否是隐患
                let f_defect_level   //是否是隐患
                let f_item_name = items.f_item_name
                let f_item_value
                let f_is_eliminate //隐患是否消除
                let f_meternumber = ''
                let f_user_defects = [] // 用户所有隐患
                console.log('f_item_name=====>' + f_item_name)
                console.log('items.type=====>' + items.type)
                if (items.type === 'selector') {
                  for (let i in items.f_item_value) {
                    let configItems = this.config[codata[device][item].f_device_type].items[f_item_name]
                    console.log('configItems=====>' + JSON.stringify(configItems))
                    for (let k in configItems.options) {
                      console.log('configItems.options[k]==>' + JSON.stringify(configItems.options[k]))
                      if (items.f_item_value[i] === configItems.options[k].data) {

                        f_is_defect = configItems.options[k].isdefect
                        f_item_value = items.f_item_value[i]
                        f_defect_level = configItems.options[k].level

                        console.log('f_is_defect=====>' + f_is_defect)
                        console.log('f_item_value=====>' + f_item_value)
                        console.log('f_defect_level=====>' + f_defect_level)

                        if (f_is_defect) {
                          if (checkResults.result !== '有隐患') {
                            checkResults.result = '有隐患'
                          }
                          if (!this.checkResult.hasOwnProperty(f_item_name)) {
                            console.log(`The ${f_item_name} initialized`)
                            this.checkResult[f_item_name] = []
                          }

                          console.log(`The ${f_item_name} was pushed ${f_item_value}`)
                          this.checkResult[f_item_name].push(f_item_value)

                        }

                        let items_list = {
                          f_is_defect: f_is_defect,
                          f_item_value: f_item_value,
                          f_defect_level: f_defect_level,
                          f_is_eliminate: null,
                          f_create_time: Util.toStandardTimeString()
                        }
                        if (!items.f_item_lists) {
                          console.log('f_item_lists未定义')
                          items.f_item_lists = []
                          console.log('items_list=========>' + JSON.stringify(items_list))
                          if (JSON.stringify(items_list) !== '{}') {
                            console.log('放了')
                            items.f_item_lists.push(items_list)
                          }
                        } else {
                          console.log('items_list=========>' + JSON.stringify(items_list))
                          if (JSON.stringify(items_list) !== '{}') {
                            console.log('也放了')
                            items.f_item_lists.push(items_list)
                          }
                        }
                      }
                    }
                  }
                } else {
                  let configItems = this.config[codata[device][item].f_device_type].items[items.f_item_name]
                  console.log('configItems===>' + JSON.stringify(configItems))
                  f_is_defect = configItems.isdefect
                  f_defect_level = configItems.level
                  f_item_value = items.f_item_value
                  console.log('else f_is_defect=====>' + f_is_defect)
                  console.log('else f_defect_level=====>' + f_defect_level)
                  console.log('items.f_item_value==>' + items.f_item_value)
                  let items_list = {
                    f_is_defect: f_is_defect,
                    f_item_value: f_item_value,
                    f_defect_level: f_defect_level,
                    f_create_time: Util.toStandardTimeString()
                  }
                  console.log('items_list=========>' + JSON.stringify(items_list))
                  console.log('items.f_item_lists' + JSON.stringify(items.f_item_lists))
                  if (!items.f_item_lists) {
                    console.log('f_item_lists未定义')
                    items.f_item_lists = []
                    if (JSON.stringify(items_list) != '{}') {
                      console.log('else放了')
                      items.f_item_lists.push(items_list)
                    }
                  } else {
                    // items.f_item_lists[0].f_item_value = f_item_value
                    if (JSON.stringify(items_list) != '{}') {
                      console.log('else也放了')
                      console.log('放之后items_list=========>' + JSON.stringify(items_list))
                      console.log('放之后items.f_item_lists' + JSON.stringify(items.f_item_lists))
                      console.log('type=>items.f_item_lists' + typeof items.f_item_lists)
                      items.f_item_lists.push(items_list)
                    }
                  }
                }
                if (hasOther !== '' && otherValue !== null) {
                  console.log(`The other value was pushed.`)
                  this.checkResult[hasOther].push(otherValue)
                  hasOther = ''
                  otherValue = null
                }
                items.f_item_value = ''
              }
              console.log('安检结果checkResult' + JSON.stringify(this.checkResult))
              this.f_devices.push(codata[device][item])
            }
          }
        }
        if (this.checkResult) {
          for (let key in this.checkResult) {
            //TODO  上次安检结果数据组织
            console.log('key=>' + key)
            console.log('value=>' + this.checkResult[key])
            let temp = {}
            temp[key] = this.checkResult[key].join(',')
            checkResults.data.push(temp)
            // this.newcheckResult[key] = this.checkResult[key]
            // checkResults.data.push(this.newcheckResult)
            console.log('checkResults.data==>' + JSON.stringify(checkResults))
            // this.newcheckResult = {}
          }
          this.checkResult = {}
        }
        console.log(`typeof-checkResults-->${typeof checkResults}`)
        console.log('checkResults ==> ' + JSON.stringify(checkResults))
        codata.f_defect_content = JSON.stringify(checkResults)
        this.data.f_defect_content = JSON.stringify(checkResults)
        console.log('f_defect_content' + codata.f_defect_content)
        return codata
      },

  getWeixin(backData){
    let result = {f_user_name:backData.f_user_name,checker: Vue.user.name, f_check_date: Util.toStandardDateString(),f_userinfo_id:backData.f_userinfoid,f_address:backData.f_address}

    let Resultstr = ''

    for (let dev in this.config) {
      for (let device in backData) {
        if (device.startsWith("device")) {
          for (let item in backData[device]) {
            //遍历结果
            if (backData[device].length != 0 && backData[device][item].f_device_type == dev) {
              let error = true
              let n = 0
              let level = ''
              for (let i in backData[device][item].f_items) {
                if (backData[device][item].f_items[i].f_is_defect == true || backData[device][item].f_items[i].f_is_defect == 'true') {
                  error = false
                  n +=1
                  if(level == ''){
                    level = backData[device][item].f_items[i].f_defect_level
                  }
                  let le = backData[device][item].f_items[i].f_defect_level
                  if(le.startsWith('A')){
                    let i = parseInt(le.substring(1))
                    if(i<parseInt(le.substring(level))){
                      level = le
                    }
                  }else if (le.startsWith('B')){
                    let i = parseInt(le.substring(1))
                    if(i<parseInt(le.substring(level))){
                      level = le
                    }
                  }else if(le.startsWith('C')){
                    let i = parseInt(le.substring(1))
                    if(i<parseInt(le.substring(level))){
                      level = le
                    }
                  }
                }
              }
              if (error) {
                Resultstr += dev + (backData[device].indexOf(backData[device][item]) + 1) + ':正常;'
              } else {
                Resultstr += dev + (backData[device].indexOf(backData[device][item]) + 1) + ':有隐患;'
              }
              result['f_err_number'] = n
              result['f_danger_lever'] = level
            }
          }
        }
      }
    }
      for (let dev in this.config) {
        for (let device in backData) {
          if (device.startsWith("device")) {
            for (let item in backData[device]) {
              if (backData[device].length != 0 && backData[device][item].f_device_type == dev) {
                for (let i in backData[device][item].f_items) {
                  if (backData[device][item].f_items[i].f_is_defect == true || backData[device][item].f_items[i].f_is_defect == 'true') {
                    Resultstr += dev + (backData[device].indexOf(backData[device][item]) + 1)+ backData[device][item].f_items[i].f_item_name + ' ' + backData[device][item].f_items[i].f_item_value + ';'

                  }
                }
              }
            }
          }
        }
      }


    return result
  },

  uploadCheckPaper(){
    console.log('进入上传')
    let errString = this.errorVerify()
    if (errString) {
      console.log(errString)
      console.log('Vue.android',Vue.android)
      console.log('this.isUpload',this.isUpload)
      if (Vue.android){
        // if(this.isUpload){
        //   this.isUpload = false
        // }
        this.$showMessage(errString)
      }
      return
    } else {
      this.$set('data.f_offsite_time', Util.toStandardTimeString())
      this.$set('data.f_upload_time', Util.toStandardTimeString())
      this.$set('data.f_upload_date', Util.toStandardTimeString())
      console.log('赋值后',this.data)
      this.data.f_complete = '已完成'
      this.disableTimer()
    }
    console.log('uploadCheckPaper-->isUpload'+this.isUpload)
    this.onlySave = false
    let res =  this.save()
    // if(res) {
    //   try {
    //     let codata = this.getAllDefect()
    //     //获取微信推送内容
    //     let WxResult = this.getWeixin(codata)
    //     let haslivedispose = this.$androidUtil.bzLogic('getLiveDispose', {
    //       f_check_item_id: this.data.f_check_item_id
    //     })
    //     //如果是转维修上传，则不做校验，上传完成后自动转维修
    //     console.log('this.isToRepair=======》'+this.isToRepair)
    //     console.log('this.livedispose=======》'+this.livedispose)
    //     if(!this.isToRepair){
    //       if(haslivedispose.data.length > 0 && (this.livedispose == 'true' || this.livedispose == true)){
    //         console.log('是否已转维修')
    //         console.log(this.isSafeCheckToRepair)
    //         if(!this.isSafeCheckToRepair){
    //           this.$showMessage('有未处理的隐患，请前往拍照上传中将安检转为维修单！')
    //           return
    //         }
    //       }
    //     }
    //     console.log(`codata类型-->${typeof codata}`)
    //     for (let key in codata){
    //       if(key.startsWith("device")){
    //         codata[key] = []
    //       }
    //     }
    //     console.log(`codata内容-->${JSON.stringify(codata)}`)
    //
    //     console.log('遮挡上传')
    //     let isStart = true
    //     let res
    //     for (let i in this.f_devices){
    //       res = HostApp.organizeJSON({isStart:isStart,isDevice:true,device:this.f_devices[i]})
    //       if(res.code == 200){
    //         isStart = false
    //       }else{
    //         this.$showMessage("保存失败!")
    //       }
    //     }
    //     let result = HostApp.organizeJSON({
    //       isStart:false,
    //       isJSON:true,
    //       jsonstr:{
    //         f_check_item_id: this.data.f_check_item_id,
    //         f_checker_id: this.data.f_checker_id,
    //         row: codata
    //       }
    //     })
    //     if(result.code == 200){
    //       HostApp.__this__ = this
    //       this.runSyncLogic('上传安检信息','javascript:HostApp.__this__.uploadCallBack()',1)
    //     }
    //
    //
    //     // let response = this.$androidUtil.bzLogic('上传安检信息', {
    //     //   f_check_item_id: this.data.f_check_item_id,
    //     //   f_checker_id: this.data.f_checker_id,
    //     //   row: codata
    //     // })
    //     // if (response.code == 200) {
    //     //   console.log('=============response.data==================')
    //     //   console.log(JSON.stringify(response.data))
    //     //   let f_paper_id
    //     //   if(response.data != '' && response.data != null){
    //     //     f_paper_id = JSON.parse(response.data).id
    //     //   }
    //     //   this.$set('data.f_paper_id', f_paper_id)
    //     //   console.log('=============f_paper_id==================')
    //     //   console.log(JSON.stringify(f_paper_id))
    //     //   console.log(this.data.f_paper_id)
    //     //   console.log("===data"+JSON.stringify(this.data))
    //     //   for (let device in this.data){
    //     //     console.log("上传设备信息device=======>"+device)
    //     //     console.log("上传设备信息device=======>"+JSON.stringify(this.data[device]))
    //     //     if(device.startsWith("device")){
    //     //       for(let devices of this.data[device]) {
    //     //         devices.f_paper_id = f_paper_id
    //     //         let ret = this.$androidUtil.bzLogic('UpCheckPaperDevices', {
    //     //           row: devices
    //     //         })
    //     //         console.log(`上传设备信息结果res======${JSON.stringify(ret.data)}`)
    //     //         if(ret.code == 200){
    //     //           console.log(`设备信息id======${ret.data.f_device_id}`)
    //     //           devices.f_device_id = JSON.parse(ret.data.f_device_id).id
    //     //         }
    //     //         console.log('上传设备信息device======')
    //     //         console.log(JSON.stringify(devices))
    //     //         if (ret.code != 200) {
    //     //           //TODO 失败后处理
    //     //           // this.isUpload = false
    //     //           this.$showMessage("上传失败!")
    //     //           return false
    //     //         }
    //     //       }
    //     //     }
    //     //   }
    //     //   // for (let device of this.f_devices) {
    //     //   //   device.f_paper_id = f_paper_id
    //     //   //   console.log('上传设备信息device======')
    //     //   //   console.log(JSON.stringify(device))
    //     //   //   let ret = this.$androidUtil.bzLogic('UpCheckPaperDevices', {
    //     //   //     row: device
    //     //   //   })
    //     //   //   console.log(`上传设备信息结果res======${ret}`)
    //     //   //   if (ret.code != 200) {
    //     //   //     //TODO 失败后处理
    //     //   //     HostApp.alert("上传失败!")
    //     //   //     return false
    //     //   //   }
    //     //   // }
    //     //   let result = this.$androidUtil.bzLogic('FinishUpload',
    //     //     {
    //     //       f_check_item_id: this.data.f_check_item_id,
    //     //       f_userinfo_id: codata.f_userinfoid,
    //     //       f_last_check_result: codata.f_defect_content
    //     //     })
    //     //   if(result.code == 200){
    //     //     // this.$showAlert('上传成功!', 'success', 2000)
    //     //     this.$showMessage('上传成功!')
    //     //     this.isStrat=false
    //     //     if(url != "" ){
    //     //       this.$resetpost(`${url}`,{data:WxResult})
    //     //     }
    //     //     return true
    //     //   }else{
    //     //     // this.isUpload = false
    //     //     this.$showMessage("上传失败!")
    //     //     return false
    //     //   }
    //     // }else{
    //     //   // this.isUpload = false
    //     //   this.$showMessage("上传失败!")
    //     //   return false
    //     // }
    //   }catch (e) {
    //     console.log('上传失败==='+JSON.stringify(e))
    //     // this.isUpload = false
    //     this.$showMessage("上传失败!")
    //   }
    // }
  },

      save(type) {
        console.log('进入保存')
        if(type == 'temp'){
          this.data.f_complete = '未完成'
          this.disableTimer()
        }else {
          let errString = this.errorVerify()
          if (errString) {
            console.log(errString)
            console.log('Vue.android',Vue.android)
            console.log('this.isUpload',this.isUpload)
            if (Vue.android){
              this.$showMessage(errString)
            }
            return
          } else {
            this.data.f_complete = '已完成'
            this.$set('data.f_offsite_time', Util.toStandardTimeString())
            this.disableTimer()
          }
        }
        // try {
        let codata = this.getAllDefect()
        console.log(`codata类型-->${typeof codata}`)
        console.log(`codata内容-->${JSON.stringify(codata)}`)
        for (let key in codata) {
          if (key.startsWith("device")) {
            console.log('this.data.' + key + JSON.stringify(codata[key]))
            codata[key] = []
          }
        }
        console.log(`codata内容-->${JSON.stringify(codata)}`)
        console.log(`codata内容-->${JSON.stringify(codata.f_user_defects)}`)
        console.log('安卓环境？=》' + Vue.android)
        if (Vue.android) {
          console.log('Vue.android is true')
          let value = this.$androidUtil.path({
            alias: 'getUserinfomation',
            data: {condition: "f_userinfoid = '" + this.item.f_userinfoid + "' and f_no_checkplan = '无计划安检'"}
          })
          console.log('getUserinfomation value ==> ' + JSON.stringify(value))
          if (this.item.f_no_checkplan == '无计划安检'  && this.item.f_no_checkplan != '打回') {
            // let result = this.$androidUtil.bzLogic('SafeSaveNoPaper', {
            //   f_check_item_id: this.data.f_check_item_id,
            //   f_checker_id: this.data.f_checker_id,
            //   f_upload_state:'未传',
            //   row: codata
            // })
            console.log('无计划安检保存')
            let isStart = true
            let res
            for (let i in this.f_devices) {
              res = HostApp.organizeJSON({isStart: isStart, isDevice: true, device: this.f_devices[i]})
              if (res.code == 200) {
                isStart = false
              } else {
                this.$showMessage("保存失败!")
              }
            }
            let result = HostApp.organizeJSON({
              isStart: false,
              isJSON: true,
              jsonstr: {
                f_check_item_id: this.data.f_check_item_id,
                f_checker_id: this.data.f_checker_id,
                f_upload_state: '未传',
                row: codata
              }
            })
            if (result.code == 200) {
              HostApp.__this__ = this
              this.runSyncLogic('SafeSaveNoPaper', 'javascript:HostApp.__this__.saveCallBack()', 1)
            }
          } else {
            console.log('非无计划安检保存')
            let isStart = true
            let res
            console.log('this.f_devices' + JSON.stringify(this.f_devices))
            for (let i in this.f_devices) {
              res = HostApp.organizeJSON({isStart: isStart, isDevice: true, device: this.f_devices[i]})
              console.log('f_devices organizeJSON ==> ' + JSON.stringify(res))
              if (res.code == 200) {
                isStart = false
              } else {
                this.$showMessage("保存失败!")
              }
            }
            console.log('this.data ==> ' + JSON.stringify(this.data))
            console.log('f_check_item_id ==> ' + JSON.stringify(this.data.f_check_item_id))
            console.log('f_checker_id ==> ' + JSON.stringify(this.data.f_checker_id))
            let result = HostApp.organizeJSON({
              isStart: false,
              isJSON: true,
              jsonstr: {
                f_check_item_id: this.data.f_check_item_id,
                f_checker_id: this.data.f_checker_id,
                row: codata
              }
            })
            console.log('organizeJSON result ==> ' + JSON.stringify(result))
            if (result.code === 200) {
              HostApp.__this__ = this
              this.runSyncLogic('保存安检单信息', 'javascript:HostApp.__this__.saveCallBack()', 1)
            }
          }

        } else {
          console.log("保存的值", codata)
          let value = this.$androidUtil.path({
            alias: 'getUserinfomation',
            data: {condition: "f_userinfoid = '" + this.item.f_userinfoid + "' and f_no_checkplan = '无计划安检'"}
          })

          if (this.item.f_no_checkplan == '无计划安检' && value.data.length == 0 && this.item.f_no_checkplan != '打回') {
            this.$androidUtil.bzLogic('SafeSaveNoPaper', {
              f_check_item_id: this.data.f_check_item_id,
              f_checker_id: this.data.f_checker_id,
              f_upload_state: '未传',
              row: codata
            }).then((res) => {
              if (res.data.code == 200) {
                //保存devices
                this.$androidUtil.bzLogic('getPaperInfo', {
                  f_check_item_id: this.data.f_check_item_id
                }).then((res) => {
                  console.log(`查询paper结果res======${res}`)
                  if (res.data.code == 200) {

                    let f_paper_id = res.data.data[0].id
                    for (let device of this.f_devices) {
                      device.f_paper_id = f_paper_id
                      console.log('设备信息device======', device)
                      this.$androidUtil.bzLogic('saveDevice', {
                        row: device
                      }).then((ret) => {
                        console.log(`保存设备信息结果res======`, ret)
                        if (ret.code != 200) {
                          // if(this.isUpload){
                          //   this.isUpload = false
                          // }
                          //TODO 失败后处理
                          this.$showMessage("保存失败!")
                          return false
                        }
                      })
                    }
                  }
                })
                // this.$showAlert('保存成功!', 'success', 2000)
                this.$showMessage('保存成功!')
                return true
              } else {
                // if(this.isUpload){
                //   this.isUpload = false
                // }
                this.$showMessage("保存失败!")
                return false
              }
            })
          } else {
            this.$androidUtil.bzLogic('保存安检单信息', {
              f_check_item_id: this.data.f_check_item_id,
              f_checker_id: this.data.f_checker_id,
              row: codata
            }).then((res) => {
              console.log('asdddddddddddddddddddddddddddddd')
              if (res.data.code == 200) {
                //保存devices
                this.$androidUtil.bzLogic('getPaperInfo', {
                  f_check_item_id: this.data.f_check_item_id
                }).then((res) => {
                  console.log(`查询paper结果res======${res}`)
                  if (res.data.code == 200) {

                    let f_paper_id = res.data.data[0].id
                    for (let device of this.f_devices) {
                      device.f_paper_id = f_paper_id
                      console.log(`设备信息device======${device}`)
                      this.$androidUtil.bzLogic('saveDevice', {
                        row: device
                      }).then((ret) => {
                        console.log(`保存设备信息结果res======${ret}`)
                        if (ret.code != 200) {
                          // if(this.isUpload){
                          //   this.isUpload = false
                          // }
                          //TODO 失败后处理
                          this.$showMessage("保存失败!")
                          return false
                        }
                      })
                    }
                  }
                })
                // this.$showAlert('保存成功!', 'success', 2000)
                this.$showMessage('保存成功!')
                return true
              } else {
                // if(this.isUpload){
                //   this.isUpload = false
                // }
                this.$showMessage("保存失败!")
                return false
              }
            })
          }
        }
        // }catch (e) {
        //   console.log('保存失败==='+JSON.stringify(e))
        //   // this.isUpload = false
        //   this.$showMessage("保存失败!")
        // }
      },
      runSyncLogic(logic,callback,backresult){
        HostApp.runSyncLogic({
          // logic别名，key必须为logic
          'logic': logic,
          // 回调执行方法名，key必须为callback
          'callback': callback,
          // 固定key，代表是否将logic执行结果作为参数传入回调方法，1代表true，0代表false，
          // 执行回调方法传入key为backresult
          // 如需额外拼接参数，写在logic返回值的params，例如xxlogic返回:{"params": "success"}
          'backresult':backresult
        })
      },
      logicWithHint(logic,data,callback,backresult){
        HostApp.logicWithHint({
          // logic别名，key必须为logic
          'logic': logic,
          // 回调执行方法名，key必须为callback
          'callback': callback,
          // logic执行需要的业务参数
          'data': data,
          // 固定key，代表是否将logic执行结果作为参数传入回调方法，1代表true，0代表false，
          // 执行回调方法传入key为backresult
          // 如需额外拼接参数，写在logic返回值的params，例如xxlogic返回:{"params": "success"}
          'backresult':backresult
        })
      },
      saveCallBack(jo){
        console.log(JSON.stringify(jo))
        if(jo.state == 'ok'){
          let res = JSON.parse(jo.result)
          console.log('保存结果===》'+JSON.stringify(res))
          if(res.code == 200){
            console.log('onlySave=====>'+this.onlySave)
            if(!this.onlySave){
              let codata = this.getAllDefect()
              //获取微信推送内容
              // let WxResult = this.getWeixin(codata)
              let haslivedispose = this.$androidUtil.bzLogic('getLiveDispose', {
                f_check_item_id: this.data.f_check_item_id
              })
              //如果是转维修上传，则不做校验，上传完成后自动转维修
              console.log('this.isToRepair=======》'+this.isToRepair)
              console.log('this.livedispose=======》'+this.livedispose)
              if(!this.isToRepair){
                if(haslivedispose.data.length > 0 && (this.livedispose == 'true' || this.livedispose == true)){
                  console.log('是否已转维修')
                  console.log(this.isSafeCheckToRepair)
                  if(!this.isSafeCheckToRepair){

                  }
                }
              }
              console.log(`codata类型-->${typeof codata}`)
              for (let key in codata){
                if(key.startsWith("device")){
                  codata[key] = []
                }
              }
              console.log(`codata内容-->${JSON.stringify(codata)}`)

              console.log('遮挡上传')
              let isStart = true
              let res
              for (let i in this.f_devices){
                res = HostApp.organizeJSON({isStart:isStart,isDevice:true,device:this.f_devices[i]})
                if(res.code == 200){
                  isStart = false
                }else{
                  this.$showMessage("上传失败!")
                  return
                }
              }
              let result = HostApp.organizeJSON({
                isStart:false,
                isJSON:true,
                jsonstr:{
                  f_check_item_id: this.data.f_check_item_id,
                  f_checker_id: this.data.f_checker_id,
                  row: codata
                }
              })
              if(result.code == 200){
                HostApp.__this__ = this
                this.runSyncLogic('上传安检信息','javascript:HostApp.__this__.uploadCallBack()',1)
              }
            }else{
              this.$showMessage('保存成功！')
              if(this.clickBack){
                this.isStrat = false
                this.$dispatch('confirm')
                //this.$back()
              }
            }
          }else{
            this.$showMessage('保存失败！')
            return
          }
        }else{
          this.$showMessage('移动网络异常,请稍后再试,保存失败！')
          return
        }
      },
      uploadCallBack(jo){
        //获取微信推送路径
        let url = ""
        if(Vue.config.safecheck != undefined) {
          if (Vue.config.safecheck.ApproveConfig != undefined) {
            if (Vue.config.safecheck.ApproveConfig.weixinurl != undefined) {
              url = Vue.config.safecheck.ApproveConfig.weixinurl
            }
          }
        }
        console.log(JSON.stringify(jo))
        console.log('jo ===> ' + JSON.stringify(jo))
        if(jo.state == 'ok'){
          let res = JSON.parse(jo.result)
          console.log('上传结果===》'+JSON.stringify(res))
          console.log('上传结果的f_paper_id===》'+JSON.stringify(res.id))
          if(res.code == 200){
            this.$set('data.f_paper_id', res.id)
              this.isStrat=false
              if(url != ""){
                this.$resetpost(`${url}`,{data:WxResult})
              }
              console.log('this.isToRepair==============>'+this.isToRepair)
              if(this.isToRepair){
                for (let device in this.data){
                  if(device.startsWith("device")){
                    this.data[device] = []
                    if(res.data.length > 0){
                      for(let i in res.data[0].f_devices){
                        if(this.data[device].length > 0){
                          if(this.data[device][0].f_device_type == res.data[0].f_devices[i].f_device_type){
                            this.data[device].push(res.data[0].f_devices[i])
                            res.data[0].f_devices.splice(i,1)
                          }
                        }else{
                          this.data[device].push(res.data[0].f_devices[i])
                          res.data[0].f_devices.splice(i,1)
                        }
                      }
                    }
                  }
                }
                this.todo()
              }else{
                this.$showMessage('上传成功!')
                console.log('上传结束back')
                this.$dispatch('confirm')
                // this.$back()
              }
          }else if(res.code == 309){
            this.$showMessage('该安检单已作废!')
            console.log('该安检单已作废')
            this.$dispatch('confirm')
          }else{
            this.$showMessage('上传失败！')
            this.onlySave = true
          }
        }else {
          this.$showMessage('移动网络异常,请稍后再试,上传失败！')
          this.onlySave = true
        }
      },
      safecheckToRepairCallBack(jo){
        //获取微信推送路径
        if(jo.state == 'ok'){
          let res = JSON.parse(jo.result)
          console.log('安检转维修===》'+JSON.stringify(res))
          if(res.code == 200){
            console.log('安检转维修成功')
            if(res.data.code == 200){
              this.$showMessage('上传并转维修成功！')
            }else{
              this.$showMessage('上传并转维修成功，回写安检单失败！')
            }
            this.$dispatch('confirm')
            // this.$back()
          }else{
            this.$showMessage('上传失败！')
            this.onlySave = true
          }
        }else{
          this.$showMessage('移动网络异常,请稍后再试,上传失败！')
          this.onlySave = true
        }
      },
      todo(){
        let gen = getRepairParam(this)
        co(gen)
      },
      undo(){
        this.showCheckToRepair = !this.showCheckToRepair
        this.model.serviceacitivity[0].f_reciever = ''
        this.model.serviceacitivity[0].f_meetunit = ''
        this.model.f_repairtype = ''
        this.meading = '转站点'
      },
      disableTimer() {
        if(this.timer) {
          window.clearTimeout(this.timer)
          this.timer = null
        }
      },
      loaded(paper) {
        console.log('paper ===> ' + JSON.stringify(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')
          // 如果打回重检则重新计时
          console.log('HostApp.__this__.role' + HostApp.__this__.role + ' HostApp.__this__.f_approved:' + HostApp.__this__.data.f_approved)
          if(HostApp.__this__.role == 'inspect'
            && HostApp.__this__.data.f_approved
            && HostApp.__this__.data.f_approved == '打回') {
            console.log('打回')
            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_safecheck_type = this.item.f_safecheck_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_user_inhome_time', this.item.f_user_inhome_time)
        // this.$set('data.f_user_check_time', this.item.f_user_check_time)
        // this.$set('data.f_user_spare_phone', this.item.f_user_spare_phone)
        // this.$set('data.f_user_family_remarks', this.item.f_user_family_remarks)
        // this.$set('data.f_user_equipment_remarks', this.item.f_user_equipment_remarks)
        // 处置方式
        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.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4() + "" + this.S4()
        }

        //房屋结构
        // 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) {
                console.log('this.item.f_plan_meters[i] ===> ' + JSON.stringify(this.item.f_plan_meters[i]))
                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: "string"
                      },
                      {
                        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: "string"
                      },
                      {
                        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"
                      },
                      {
                        f_defect_level: null,
                        f_device_id: "",
                        f_is_defect: "",
                        f_item_name: "左右表",
                        f_item_value: this.item.f_plan_meters[i].f_flow_direction,
                        f_path: "",
                        type: "string"
                      }
                    ]
                  })
                } 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: "string"
                      },
                      {
                        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: "string"
                      },
                      {
                        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"
                      },
                      {
                        f_defect_level: null,
                        f_device_id: "",
                        f_is_defect: "",
                        f_item_name: "左右表",
                        f_item_value: this.item.f_plan_meters[i].f_flow_direction,
                        f_path: "",
                        type: "string"
                      }
                    ]
                  })
                }
                if (this.devices[de].device == "燃气表" && this.item.f_plan_meters[i].f_collection_type) {
                  this.data['device' + this.devices[de].n].forEach(device => {
                    console.log('device ===> ' + JSON.stringify(device))
                    console.log('this.item.f_plan_meters[i].f_collection_type ===> ' + JSON.stringify(this.item.f_plan_meters[i].f_collection_type))
                    if (this.item.f_plan_meters[i].f_collection_type == '按气量') {
                      if (!this.data.f_collection_type) {
                        this.data.f_collection_type = this.item.f_plan_meters[i].f_collection_type
                        delete this.config['燃气表']['items']['累购金额']
                        device.f_items.push(
                          {
                            f_defect_level: null,
                            f_device_id: "",
                            f_is_defect: "",
                            f_item_name: "累购气量",
                            isshow: true,
                            f_item_value: this.item.f_plan_meters[i].f_total_gas,
                            f_path: "",
                            type: "number"
                          }
                        )
                      }
                    } else if (this.item.f_plan_meters[i].f_collection_type == '按金额') {
                      if (!this.data.f_collection_type) {
                        this.data.f_collection_type = this.item.f_plan_meters[i].f_collection_type
                        delete this.config['燃气表']['items']['累购气量']
                        device.f_items.push(
                          {
                            f_defect_level: null,
                            f_device_id: "",
                            f_is_defect: "",
                            f_item_name: "累购金额",
                            isshow: true,
                            f_item_value: this.item.f_plan_meters[i].f_total_fee,
                            f_path: "",
                            type: "number"
                          }
                        )
                      }
                    }
                  })
                }
              }
            }
          }
        }
        var pardate = {
          _this:this,
          tittle:'安检详情',
          safe:true
        }
        // this.$dispatch('gotoson',pardate)
        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;
      },
      putDevices() {
        console.log('Vue.config => ' + JSON.stringify(Vue.config))
        // console.log('Vue.config.DevicesConfig => ' + JSON.stringify(Vue.config.DevicesConfig))
        this.$set('data.approve', "true")
        this.$set('data.writeback', "false")
        if (Vue.config.safecheck != undefined) {
          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
            }
          }
          console.log(Vue.config)
          console.log('Vue.config.safecheck.DevicesConfig=>' + JSON.stringify(Vue.config.safecheck.DevicesConfig))
          console.log('赋值前的config=>' + JSON.stringify(this.config))
          console.log('f_safecheck_type=>' + this.item.f_safecheck_type)
          this.data.f_safecheck_type = this.item.f_safecheck_type
          // SafecheckType.Json 文件  配置  安检类型
          if(this.item.f_safecheck_type == undefined || this.item.f_safecheck_type == '' || Vue.config.safecheck.SafecheckType == undefined) {
            this.config = this.extend(this.config, Vue.config.safecheck.DevicesConfig)
          }else{
            this.config = this.extend(this.config, Vue.config.safecheck[Vue.config.safecheck.SafecheckType[this.item.f_safecheck_type]])
          }
        }
        console.log('赋值后的config=>' + JSON.stringify(this.config))
        //遍历安检项配置
        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, [])
          if(this.config[i].quantity &&  this.config[i].quantity >0){
            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,
                      checkmust: this.config[i].items[it].options[op].checkmust,
                      f_path: "",
                      type: "selector"
                    })
                  }
                }
              }
            }
            for(let q =0;q<this.config[i].quantity;q++) {
              this.data['device' + n].push(
                {f_device_type: i, f_items:items}
              )
            }
          }
          // this.data['device' + n].push(
          //   {f_device_type: i, f_items: items}
          // )
          n = n + 1
        }

      },
      //获取当前时间
      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;
      },
      //组织安检结果数据
      // checkResult(){
      //   console.log('data===>',this.data)
      //   // for (let )
      // }
    },
    async ready() {
      console.log("radys")
      this.putDevices()
      //如果已检，则提取安检单

      if (this.item.f_state != '未检') {
        if (this.role == 'inspect' || this.role == 'androidview') {
          HostApp.__callback__ = this.loaded
          HostApp.__this__ = this
          let that = this
          let value = {}
          console.log('this.item.f_no_checkplan',this.item.f_no_checkplan)
          if (this.role == 'inspect') {
            console.log('this.item.f_no_checkplan', this.item.f_no_checkplan)
            if (this.item.f_no_checkplan == '无计划安检') {
              value = this.$androidUtil.path({
                alias: 'getUserinfomation',
                data: {condition: "f_check_item_id = '" + this.item.id + "' and f_no_checkplan = '无计划安检'"}
              })
            } else {
              value = this.$androidUtil.bzLogic('FetchCheckPaper', {id: this.item.id})
            }
          } else {
            value = await this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/path/getUserinfomation`, {data: {condition: `id = '${this.item.f_paper_id}'`}})
          }
          Util.replaceFalse(value)
          console.log("value:" + JSON.stringify(value))
          if (value.data.length != 0) {
            that.$set('data', value.data[0])
            console.log("this.data.f_collection_type:" + JSON.stringify(this.data.f_collection_type))
            if (this.data.f_collection_type == '按气量') {
              delete this.config['燃气表']['items']['累购金额']
            } else if (this.data.f_collection_type == '按金额') {
              delete this.config['燃气表']['items']['累购气量']
            }
            console.log("f_devices:" + JSON.stringify(value.data[0].f_devices))
            if (value.data[0].f_devices) {
              for (let da in that.devices) {
                that.$set('data.device' + that.devices[da].n, [])
              }
              value.data[0].f_devices.forEach((item) => {
                console.log('回写数据=>' + JSON.stringify(item))
                for (let i in item.f_items) {
                  // if (item.f_items[i].f_path != '' && item.f_items[i].f_path != null) {
                  //   this.picture.push({f_path: item.f_items[i].f_path, name: item.f_items[i].f_item_name})
                  // }
                  for (let de in that.config[item.f_device_type].items) {
                    if (item.f_items[i].f_item_name == de) {
                      if (that.config[item.f_device_type].items[de].type == 'selector') {
                        item.f_items[i].f_item_value = []
                      } else {
                        item.f_items[i].f_item_value = ''
                      }
                    }
                  }
                  console.log('回写数据item.f_items[i]=======>' + JSON.stringify(item.f_items[i]))
                  for (let j in item.f_items[i].f_item_lists) {
                    console.log('回写数据item.f_items.f_item_lists[j]=======>' + JSON.stringify(item.f_items[i].f_item_lists[j]))
                    if (item.f_items[i].f_item_value instanceof Array) {
                      item.f_items[i].f_item_value.push(item.f_items[i].f_item_lists[j].f_item_value)
                    } else {
                      item.f_items[i].f_item_value = item.f_items[i].f_item_lists[j].f_item_value
                    }

                  }
                }
                for (let de in that.devices) {
                  if (that.devices[de].device == item.f_device_type) {
                    that.data['device' + that.devices[de].n].push({
                      f_device_type: item.f_device_type,
                      f_items: item.f_items
                    })
                    console.log("device:" + JSON.stringify(that.data['device' + that.devices[de].n]))
                  }
                }
              })
              if (this.role == 'androidview') {
                Util.androidRatifyPics(that.data, this.$androidUtil.getProxyUrl())
                Util.androidRatifyPics(that.picture, this.$androidUtil.getProxyUrl())
                Util.booleanFilter(that.data)
              }
              console.log('回写数据完成后'+JSON.stringify(that.data))
            }
          } else {
            console.log("该安检单可能已不在本地!")
            this.init()
          }
          console.log('页面跳转')
          console.log('paper ====> ' + JSON.stringify(this.data))
          // 备份入户状态，如果入户完成安检后不能修改
          this.data.back_f_entry_status = this.data.f_entry_status
          var pardate = {
            _this:this,
            tittle:'安检详情',
            safe:true
          }
          // this.$dispatch('gotoson',pardate)
          that.$goto('paper-state', {}, 'paper-router')
        } else {
          let that = this
          let id
          if (this.role == 'view') {
            id = this.item.id
          }
          this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/path/getUserinfomation`, {data:{condition:`id = '${id}'`}}).then((respanse)=> {
            if (respanse.data.length != 0) {
            that.data = Object.assign(that.data,respanse.data[0])
            if(respanse.data[0].f_devices) {
              for (let da in that.devices) {
                that.$set('data.device' + that.devices[da].n, [])
              }
              respanse.data[0].f_devices.forEach((item) => {
                for (let de in that.devices) {
                if (that.devices[de].device == item.f_device_type) {
                  that.data['device' + that.devices[de].n].push({
                    f_device_type: item.f_device_type,
                    f_items: item.f_items
                  })
                }
              }
            })
            }
            Util.replaceFalse(that.data)
            Util.booleanFilter(that.data)
            if(this.role == 'view'){
              Util.ratifyPics(that.data)
            }else{
              Util.androidRatifyPics(that.data,this.$androidUtil.getProxyUrl())
            }
            console.log("that.data:", that.data)
          } else {
            alert("该安检单可能已不在本地!")
            this.init()
          }
          var pardate = {
            _this:this,
            tittle:'安检详情',
            safe:true
          }
          // this.$dispatch('gotoson',pardate)
          that.$goto('paper-state', {}, 'paper-router')
        }
        ).catch(
            (respanse) => {
            alert('查找安检单失败')
        })
        }
        // else {
        //   let that = this
        //   this.$androidUtil.bzLogic('FetchCheckPaper', {id: this.item.id}).then((respanse) => {
        //     if (respanse.data.data.length != 0) {
        //     that.data = Object.assign(that.data,respanse.data.data[0])
        //     if(respanse.data.data[0].f_devices) {
        //       for (let da in that.devices) {
        //         that.$set('data.device' + that.devices[da].n, [])
        //       }
        //       respanse.data.data[0].f_devices.forEach((item) => {
        //         for (let de in that.devices) {
        //         if (that.devices[de].device == item.f_device_type) {
        //           that.$set('data.device' + that.devices[de].n, [])
        //           that.data['device' + that.devices[de].n].push({
        //             f_device_type: item.f_device_type,
        //             f_items: item.f_items
        //           })
        //         }
        //       }
        //     })
        //     }
        //     Util.booleanFilter(that.data)
        //     console.log("that.data:", that.data)
        //   } else {
        //     alert("该安检单可能已不在本地!")
        //     this.init()
        //   }
        //   that.$goto('paper-state', {}, 'paper-router')
        // }
        // ).catch(
        //     (respanse) => {
        //     alert('查找安检单失败')
        // })
        // }
      }else{
        this.init()
      }
    },
    watch:{
    //   'isUpload'(val){
    //     console.log('isUpload发生变化===>'+val)
    //   }
    },
    destroyed() {
      console.log('退出当前页Set')
      this.disableTimer()
    }
  }
</script>
