<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){
    //tag
    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
    //tag
    //tag
    let res
    let errString = self.errorVerify()
    if(errString){
      //tag
      if (Vue.android)
        self.undo()
      self.$showMessage(errString)
      return
    } else {
      if(self.role == 'inspect'){
        //tag)
        let checkResult = '正常'
        let options = [{"data": "已处理"},{"data": "未处理"}]
        let value = ''
        let codata = JSON.parse(JSON.stringify(self.data))
        for(let device in codata){
          //tag)
          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
              }
              // //tag
              let details = []
              for(let i in codata[device][item].f_items){
                let items = codata[device][item].f_items[i]
                //tag)
                if(items.f_is_defect == true || items.f_is_defect == 'true'){
                  checkResult = '有隐患'
                  //tag
                  // let res = yield self.$resetpost(`${self.Url}/rs/sql/getDeviceItem`,{data:{f_device_id:codata[device][item].f_device_id,f_item_name:items.f_item_name}})
                  // //tag)
                  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 = {}
              }
              //tag
              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 = {}
              //tag
            }
          }
        }
        self.$set('model.f_repairitems.data',self.repairitems)

        //tag)
        HostApp.__this__ = self
        self.logicWithHint('safecheckToRepair',{data:data,f_paper_id:self.data.f_paper_id},'javascript:HostApp.__this__.safecheckToRepairCallBack()',1)

        // //tag
        // //tag
        // //tag
        // if(res.code == 200){
        //   self.isSafeCheckToRepair = true
        //   // self.undo()
        //   // self.$set('paper.f_SafeToRepair_id',res.data.f_service_id)
        //   // //tag
        //   // self.$resetpost(`${self.Url}/rs/logic/updatePaperRepair`,{data:{f_paper_id:self.data.f_paper_id,f_SafeToRepair_id:res.data.f_service_id}}).then((ret)=>{
        //   //   //tag
        //   //   if(ret.data.code ==200){
        //   //tag
        //   self.$showMessage('上传并转维修成功！')
        //   self.$back()
        //     // }else{
        //     //   self.$showMessage('安检转维修失败！')
        //     // }
        //   // }).catch(v=>{
        //   //   //tag)
        //   //   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":true},
              "表号":{"index":3,"type":"string","readonly":true},
              "表封号":{"index":4,"type":"number","readonly":true},
              "表型号":{"index":5,"type":"string","readonly":true},
              "位置":{"index":6,"type":"string","readonly":true},
              "表底数":{"index":7,"type":"number","readonly":true},
              "累购气量":{"index":8,"type":"number","readonly":true},
              "累购金额":{"index":8,"type":"number","readonly":true},
              "左右表":{"index":9,"type":"string","readonly":true}
            }
          }
        }
      }
    },
    components: {
      RadioGroup,
      Radio
    },
    computed: {
      selector: {
        get() {
          return 'paper-state'
        },
        set(val) {
          //tag
          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) {
        //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() ? '已修' : '在修'
      },
      // async savePaper(saveOnly) {
      //   //tag
      //   //tag
      //   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 {
      //         //tag
      //         if(!this.data.f_offsite_time){
      //           this.$set('data.f_offsite_time', Util.toStandardTimeString())
      //         }
      //         //tag
      //         this.data.f_complete = '已完成'
      //         this.disableTimer()
      //         this.save()
      //       }}}
      //   //   }else {
      //   //     let errString = this.errorVerify()
      //   //     //tag
      //   //     if (errString) {
      //   //       //tag
      //   //       //tag
      //   //       //tag
      //   //       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())
      //   //       }
      //   //       //tag
      //   //       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
      //   //tag
      //   this.savePaper(false).then((res) => {
      //     //tag
      //     // //tag
      //     // this.isUpload = false
      //     // //tag
      //     if(res != true){
      //       //tag
      //       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 = '用户反馈：'
        //tag)
        //tag
        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))
        //tag)
        //tag)
        codata.f_devices = []
        this.f_devices = []
        for (let device in codata) {
          let f_device_type
          if (device.startsWith("device")) {
            //tag)
            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
              // }
              // //tag
              for (let i; i < codata[device][item].f_items.length ; i++) {
                //tag
                if(i == 'sum'){
                  continue
                }
                //tag)
                var items = codata[device][item].f_items[i]
                items.f_create_time = Util.toStandardTimeString()
                //tag)
                items.f_item_lists = []
                //tag)
                // //tag)
                // //tag} 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')) {
                //     //tag
                //     checkResults.result = '有隐患'
                //     //tag)
                //     //tag)
                //     // this.$set('checkResult.' + items.f_item_name, items.f_item_value)
                //       this.checkResult[items.f_item_name] = items.f_item_value
                //     //tag)
                //     // this.$set('checkResultsss.' + items.f_item_name, `${f_device_type}${items.f_item_value}`)
                //     // //tag)
                // }
                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 = [] // 用户所有隐患
                //tag
                //tag
                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]
                    //tag)
                    for (let k in configItems.options) {
                      //tag)
                      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

                        //tag
                        //tag
                        //tag

                        if (f_is_defect) {
                          if (checkResults.result !== '有隐患') {
                            checkResults.result = '有隐患'
                          }
                          if (!this.checkResult.hasOwnProperty(f_item_name)) {
                            //tag
                            this.checkResult[f_item_name] = []
                          }

                          //tag
                          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) {
                          //tag
                          items.f_item_lists = []
                          //tag)
                          if (JSON.stringify(items_list) !== '{}') {
                            //tag
                            items.f_item_lists.push(items_list)
                          }
                        } else {
                          //tag)
                          if (JSON.stringify(items_list) !== '{}') {
                            //tag
                            items.f_item_lists.push(items_list)
                          }
                        }
                      }
                    }
                  }
                } else {
                  let configItems = this.config[codata[device][item].f_device_type].items[items.f_item_name]
                  //tag)
                  f_is_defect = configItems.isdefect
                  f_defect_level = configItems.level
                  f_item_value = items.f_item_value
                  //tag
                  //tag
                  //tag
                  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()
                  }
                  //tag)
                  //tag)
                  if (!items.f_item_lists) {
                    //tag
                    items.f_item_lists = []
                    if (JSON.stringify(items_list) != '{}') {
                      //tag
                      items.f_item_lists.push(items_list)
                    }
                  } else {
                    // items.f_item_lists[0].f_item_value = f_item_value
                    if (JSON.stringify(items_list) != '{}') {
                      //tag
                      //tag)
                      //tag)
                      //tag
                      items.f_item_lists.push(items_list)
                    }
                  }
                }
                if (hasOther !== '' && otherValue !== null) {
                  //tag
                  this.checkResult[hasOther].push(otherValue)
                  hasOther = ''
                  otherValue = null
                }
                items.f_item_value = ''
              }
              //tag)
              this.f_devices.push(codata[device][item])
            }
          }
        }
        if (this.checkResult) {
          for (let key in this.checkResult) {
            //TODO  上次安检结果数据组织
            //tag
            //tag
            let temp = {}
            temp[key] = this.checkResult[key].join(',')
            checkResults.data.push(temp)
            // this.newcheckResult[key] = this.checkResult[key]
            // checkResults.data.push(this.newcheckResult)
            //tag)
            // this.newcheckResult = {}
          }
          this.checkResult = {}
        }
        //tag
        //tag)
        codata.f_defect_content = JSON.stringify(checkResults)
        this.data.f_defect_content = JSON.stringify(checkResults)
        //tag
        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(){
    //tag
    let errString = this.errorVerify()
    if (errString) {
      //tag
      //tag
      //tag
      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())
      //tag
      this.data.f_complete = '已完成'
      this.disableTimer()
    }
    //tag
    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
    //     })
    //     //如果是转维修上传，则不做校验，上传完成后自动转维修
    //     //tag
    //     //tag
    //     if(!this.isToRepair){
    //       if(haslivedispose.data.length > 0 && (this.livedispose == 'true' || this.livedispose == true)){
    //         //tag
    //         //tag
    //         if(!this.isSafeCheckToRepair){
    //           this.$showMessage('有未处理的隐患，请前往拍照上传中将安检转为维修单！')
    //           return
    //         }
    //       }
    //     }
    //     //tag
    //     for (let key in codata){
    //       if(key.startsWith("device")){
    //         codata[key] = []
    //       }
    //     }
    //     //tag}`)
    //
    //     //tag
    //     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) {
    //     //   //tag
    //     //   //tag)
    //     //   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)
    //     //   //tag
    //     //   //tag)
    //     //   //tag
    //     //   //tag)
    //     //   for (let device in this.data){
    //     //     //tag
    //     //     //tag)
    //     //     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
    //     //         })
    //     //         //tag}`)
    //     //         if(ret.code == 200){
    //     //           //tag
    //     //           devices.f_device_id = JSON.parse(ret.data.f_device_id).id
    //     //         }
    //     //         //tag
    //     //         //tag)
    //     //         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
    //     //   //   //tag
    //     //   //   //tag)
    //     //   //   let ret = this.$androidUtil.bzLogic('UpCheckPaperDevices', {
    //     //   //     row: device
    //     //   //   })
    //     //   //   //tag
    //     //   //   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) {
    //     //tag)
    //     // this.isUpload = false
    //     this.$showMessage("上传失败!")
    //   }
    // }
  },

      save(type) {
        //tag
        if(type == 'temp'){
          this.data.f_complete = '未完成'
          this.disableTimer()
        }else {
          let errString = this.errorVerify()
          if (errString) {
            //tag
            //tag
            //tag
            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()
        //tag
        //tag}`)
        for (let key in codata) {
          if (key.startsWith("device")) {
            //tag)
            codata[key] = []
          }
        }
        //tag}`)
        //tag}`)
        //tag
        if (Vue.android) {
          //tag
          let value = this.$androidUtil.path({
            alias: 'getUserinfomation',
            data: {condition: "f_userinfoid = '" + this.item.f_userinfoid + "' and f_no_checkplan = '无计划安检'"}
          })
          //tag)
          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
            // })
            //tag
            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 {
            //tag
            let isStart = true
            let res
            //tag)
            for (let i in this.f_devices) {
              res = HostApp.organizeJSON({isStart: isStart, isDevice: true, device: this.f_devices[i]})
              //tag)
              if (res.code == 200) {
                isStart = false
              } else {
                this.$showMessage("保存失败!")
              }
            }
            //tag)
            //tag)
            //tag)
            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
              }
            })
            //tag)
            if (result.code === 200) {
              HostApp.__this__ = this
              this.runSyncLogic('保存安检单信息', 'javascript:HostApp.__this__.saveCallBack()', 1)
            }
          }

        } else {
          //tag
          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) => {
                  //tag
                  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
                      //tag
                      this.$androidUtil.bzLogic('saveDevice', {
                        row: device
                      }).then((ret) => {
                        //tag
                        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) => {
              //tag
              if (res.data.code == 200) {
                //保存devices
                this.$androidUtil.bzLogic('getPaperInfo', {
                  f_check_item_id: this.data.f_check_item_id
                }).then((res) => {
                  //tag
                  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
                      //tag
                      this.$androidUtil.bzLogic('saveDevice', {
                        row: device
                      }).then((ret) => {
                        //tag
                        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) {
        //   //tag)
        //   // 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){
        //tag)
        if(jo.state == 'ok'){
          let res = JSON.parse(jo.result)
          //tag)
          if(res.code == 200){
            //tag
            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
              })
              //如果是转维修上传，则不做校验，上传完成后自动转维修
              //tag
              //tag
              if(!this.isToRepair){
                if(haslivedispose.data.length > 0 && (this.livedispose == 'true' || this.livedispose == true)){
                  //tag
                  //tag
                  if(!this.isSafeCheckToRepair){

                  }
                }
              }
              //tag
              for (let key in codata){
                if(key.startsWith("device")){
                  codata[key] = []
                }
              }
              //tag}`)

              //tag
              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
            }
          }
        }
        //tag)
        //tag)
        if(jo.state == 'ok'){
          let res = JSON.parse(jo.result)
          //tag)
          //tag)
          if(res.code == 200){
            this.$set('data.f_paper_id', res.id)
              this.isStrat=false
              if(url != ""){
                this.$resetpost(`${url}`,{data:WxResult})
              }
              //tag
              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('上传成功!')
                //tag
                this.$dispatch('confirm')
                // this.$back()
              }
          }else if(res.code == 309){
            this.$showMessage('该安检单已作废!')
            //tag
            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)
          //tag)
          if(res.code == 200){
            //tag
            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) {
        //tag)
        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_read_instructions', null)
        this.$set('data.f_blacklist', null)
        // 用户信息
        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) {
                //tag)
                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 => {
                    //tag)
                    //tag)
                    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() {
        //tag)
        // //tag)
        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
            }
          }
          //tag
          //tag)
          //tag)
          //tag
          // 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]])
          }
        }
        //tag)
        //遍历安检项配置
        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(){
      //   //tag
      //   // for (let )
      // }
    },
    async ready() {
      //tag
      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 = {}
          //tag
          if (this.role == 'inspect') {
            //tag
            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)
          //tag)
          if (value.data.length != 0) {
            that.$set('data', value.data[0])
            //tag)
            if (this.data.f_collection_type == '按气量') {
              delete this.config['燃气表']['items']['累购金额']
            } else if (this.data.f_collection_type == '按金额') {
              delete this.config['燃气表']['items']['累购气量']
            }
            //tag)
            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) => {
                //tag)
                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 = ''
                      }
                    }
                  }
                  //tag)
                  for (let j in item.f_items[i].f_item_lists) {
                    //tag)
                    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
                    })
                    //tag)
                  }
                }
              })
              if (this.role == 'androidview') {
                Util.androidRatifyPics(that.data, this.$androidUtil.getProxyUrl())
                Util.androidRatifyPics(that.picture, this.$androidUtil.getProxyUrl())
                Util.booleanFilter(that.data)
              }
              //tag)
            }
          } else {
            //tag
            this.init()
          }
          //tag
          //tag)
          // 备份入户状态，如果入户完成安检后不能修改
          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())
            }
            //tag
          } 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)
        //     //tag
        //   } else {
        //     alert("该安检单可能已不在本地!")
        //     this.init()
        //   }
        //   that.$goto('paper-state', {}, 'paper-router')
        // }
        // ).catch(
        //     (respanse) => {
        //     alert('查找安检单失败')
        // })
        // }
      }else{
        this.init()
      }
    },
    watch:{
    //   'isUpload'(val){
    //     //tag
    //   }
    },
    destroyed() {
      //tag
      this.disableTimer()
    }
  }
</script>
