<template>
  <form novalidate class="form-horizontal" style="width: 95%;margin: auto">
    <div class="form-group col-sm-12 col-xs-12 col-md-12 info">
      <div class="text-center">
        <label class="font">检查说明：</label>
      </div>
      <div class="col-md-12 col-sm-12 col-xs-12">
        <ol class="showInput">
          <li>已对客户燃气设施进行了安全检查</li>
          <li>已对客户进行了安全知识宣传，并发放宣传资料</li>
          <li>已对客户的资料进行了登记</li>
          <li>已对违章及隐患之客户下发隐患整改告知书</li>
        </ol>
      </div>
    </div>
    <div class="form-group col-sm-12">
      <label class="text-left font">总体安检照片1</label>

      <div class="auto">
        <div class="panel">
          <div class="panel-body panel-self" style="background-color: #F8F8F8;width: 100%;height: 260px;position: relative">
            <div class="row" style="height: 240px;overflow: scroll;top: 1px">
              <div class="col-sm-4">
                <img-self :src="paper.f_overall_path" alt="总体安检照片" width="150" height="200"></img-self>
              </div>
            </div>
            <div class="row text-right div-photo">
              <button type="button" name="button" class="btn btn-primary btn-photo" @click="takePic('f_overall_path', '总体安检照片1')">拍照</button>
              &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../assets/remove.png" :class="style__" @click="delfile('f_overall_path', paper.f_overall_path)" style="width: 25%;"></img>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="form-group col-sm-12">
      <label class="text-left font">总体安检照片2</label>
      <div class="auto">
        <div class="panel">
          <div class="panel-body panel-self" style="background-color: #F8F8F8;width: 100%;height: 260px;position: relative">
            <div class="row" style="height: 240px;overflow: scroll;top: 1px">
              <div class="col-sm-4">
                <img-self  :src="paper.f_overall2_path" alt="总体安检照片2" width="150" height="200"></img-self>
              </div>
            </div>
            <div class="row text-right div-photo">
              <button type="button" name="button" class="btn btn-primary btn-photo" @click="takePic('f_overall2_path', '总体安检照片2')">拍照</button>
              &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../assets/remove.png" :class="style__"  @click="delfile('f_overall2_path', paper.f_overall2_path)" style="width: 25%;"></img>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="form-group col-sm-12">
      <label class="text-left font">用户签名</label>
      <div class="auto">
        <div class="panel">
          <div class="panel-body panel-self" style="background-color: #F8F8F8;width: 100%;height: 260px;position: relative">
            <div class="row" style="height: 240px;overflow: scroll;top: 1px">
              <div class="col-sm-4">
                <img :class="style__" :src="paper.f_sign_path" :width="200" :height="150" />
              </div>
            </div>
            <div class="row text-right div-photo">
              <button type="button" name="button" class="btn btn-primary btn-photo" @click="sign">签名</button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="form-group col-md-12 col-sm-12 col-xs-12">
      <div  class="form-group col-md-12 col-sm-12 col-xs-12">
          <input type="checkbox" v-model="paper.f_defect_notified" class="showInput">安检通知书/隐患整改通知书</input>
      </div>
      <div class="form-group col-md-12 col-sm-12 col-xs-12" v-if="paper.f_defect_notified">
        <div  class="form-group col-md-12 col-sm-12 col-xs-12">
          <button type="button" @click="print()">打印隐患整改单</button>
        </div>
        <div  class="form-group col-md-12 col-sm-12 col-xs-12">
          <label class="text-left font">安检通知书/隐患整改通知书照片(要求能清晰反应安检通知单和用户签字内容)：</label>
          <div class="auto" >
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self" style="background-color: #F8F8F8;width: 100%;height: 260px;position: relative">
                <div class="row" style="height: 240px;overflow: scroll;top: 1px">
                  <div class="col-sm-4">
                    <img-self  :src="paper.f_notified_path" alt="安检通知书/隐患整改通知书照片" width="150" height="200"></img-self>
                  </div>
                </div>
                <div class="row text-right div-photo">
                  <button type="button" name="button" class="btn btn-primary btn-photo" @click="takePic('f_notified_path', '安检通知书/隐患整改通知书照片')">拍照</button>
                  &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../assets/remove.png" :class="style__"  @click="delfile('f_notified_path', this.paper.f_notified_path)" style="width: 25%;"></img>
                </div>
              </div>
              </div>
            </div>
          </div>
      </div>
      <div class="form-group col-md-12 col-sm-12 col-xs-12">
        <div class="row">
          <label class="text-left">请对我们的服务做出评价：</label>
        </div>
        <div class="col-xs-4 col-sm-4"  v-for="item in radios">
            <input v-model="paper.f_client_evaluation" :value="item.label"  :checked='item.isChecked'  @click="check(item.value)" type="radio">{{item.label}}
        </div>

        <!--<div class="col-sm-4">-->
          <!--<radio-group :value.sync="paper.f_client_evaluation" type="success" buttons="false">-->
            <!--<radio value="满意">满意</radio>-->
            <!--<radio value="基本满意">基本满意</radio>-->
            <!--<radio value="不满意">不满意</radio>-->
          <!--</radio-group>-->
        <!--</div>-->
      </div>
      <div class="form-group col-md-12 col-sm-12 col-xs-12">
        <label class="text-left font">反馈录音:</label>
        <div class="col-md-12 col-sm-12 col-xs-12">
          <button type="button" name="button" class="btn btn-primary btn-voice" @click="record">
            <img src="../../assets/录音.png" style="width: 14%;">
            <span v-if="!paper.f_recording1_path">开始录音</span>
            <span v-if="paper.f_recording1_path">已录音</span>
          </button>
          &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../assets/remove.png" style="width: 15px;" :class="style__" @click="delAudioFile('f_recording1_path', paper.f_recording1_path)"></img>
        </div>
      </div>
      <div class="text-center form-group col-md-12 col-sm-12 col-xs-12">
        <button type="button" v-show="$parent.$parent.actionEnabled" class="btn save-btn" @click="$parent.$parent.savePaper(true)">保存</button>
        <button id="upload" type="button" v-show="$parent.$parent.actionEnabled && !$parent.$parent.isBusy" class="btn upload-btn" @click="$parent.$parent.uploadPaper" >上传</button>
        <button v-if="safeCheckToRepair && $parent.$parent.actionEnabled" class="btn repair-btn btn-warning" type="button" @click="showToRepair">转维修</button>
      </div>
      </div>
    </form>
  <modal :show.sync="showCheckToRepair" v-ref:modal :backdrop="isback">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        安检转维修
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div v-if="showrepair">
        <div class="row">
          <label class="col-xs-4 col-md-4 control-label text-left">派单方式</label>
          <div class="col-xs-8 col-md-8">
            <label v-for="handling1 in handling" >
              <input type="radio"
                     v-model="meading"
                     value="{{handling1.label}}">
              {{handling1.label}}
            </label>
          </div>
        </div>
        <div class="row" v-if="meading == '转站点'">
          <label class="col-xs-4 col-md-4 control-label font text-left" for="f_reciever">站点</label>
          <!--<input type="text" v-show="false" v-model="serviceacitivity.f_reciever"-->
          <!--v-validate:f_reciever='{ required: true }'>-->
          <div class="col-xs-8 col-md-8">
            <right-tree @ready="onReady" islist :Url="Url" :userid="userid" :source="source"  v-on:re-res="reres" :textContent="选择站点管理员" :selectData="" v-ref:f_reciever>
            </right-tree>
          </div>
        </div>

        <div class="row" style="margin-top: 6px" v-if="meading == '转维修员'">
          <label class="col-xs-4 col-md-4 control-label font text-left">维修人</label>
          <div class="col-xs-8">
            <v-select :value="model.serviceacitivity[0].f_reciever" :value-single="true"
                      :options='f_repair_person' placeholder='请选择维修员'
                      close-on-select v-on:change="repiarmancg"></v-select>
          </div>

        </div>
        <div class="row" style="margin-top: 6px">
          <label for="f_repair" class="col-xs-4 col-md-4 control-label font text-left">报修类型</label>
          <div class="col-xs-8 col-md-8">
            <v-select :value.sync="model.f_repairtype" :value-single="true"
                      :options='repairstypes' placeholder='报修类型'
                      close-on-select>
            </v-select>
          </div>
        </div>

        <div class="row" style="margin-top: 6px">
          <label class="control-label font text-left col-md-4 col-xs-4">备注</label>
          <div class="col-xs-8 col-md-8">
            <input type="text" v-model="model.f_remarks"/>
          </div>

        </div>

      </div>
      <div v-if="!showrepair">
        暂无隐患设备信息
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-default" @click="uploadPaper()">确定</button>
      <button type="button" class="btn btn-default" @click="undo()">取消</button>
    </div>
  </modal>
</template>

<script>
  import Vue from 'vue'
  import * as Util from '../Util'
  import { HttpResetClass } from 'vue-client'
  import RadioGroup from 'vue-client/src/vue-strap/src/radioGroup'
  import Radio from 'vue-client/src/vue-strap/src/radioBtn'
  import co from 'co'

  let getRepairParam = function * (self){
    let data = {
      model: self.model, loginUser: {
        name: self.role == 'view'?self.$login.f.name:Vue.user.name,
        ename: self.role == 'view'?self.$login.f.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.$parent.$parent.errorVerify()
    if(errString){
      //tag
      if (Vue.android)
        self.undo()
      this.$showMessage(errString)
      return
    } else {
      if(self.role == 'inspect'){
        if(self.meading == '转维修员' && (self.model.serviceacitivity[0].f_reciever == '' || self.model.serviceacitivity[0].f_reciever == undefined)){
          this.$showMessage("请选择维修员!")
          return
        }
        if(self.meading == '转站点' && (self.model.serviceacitivity[0].f_reciever == '' || self.model.serviceacitivity[0].f_reciever == undefined)){
          this.$showMessage("请选择站点!")
          return
        }
        if(self.model.f_repairtype == ''){
          this.$showMessage("请选择报修类型!")
          return
        }
        //tag)
        let checkResult = '正常'
        let options = [{"data": "已处理"},{"data": "未处理"}]
        let value = ''
        let codata = JSON.parse(JSON.stringify(self.paper))
        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', res.data[0].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)
        res = self.$androidUtil.bzLogic('safecheckToRepair',data)
        //tag
        //tag
        //tag
        if(res.code == 200){
          self.$parent.$parent.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.paper.f_paper_id,f_SafeToRepair_id:res.data.f_service_id}}).then((ret)=>{
            //tag
            if(ret.data.code ==200){
              //tag
              self.$parent.$parent.$back()
            }else{
              self.$showMessage('安检转维修失败！')
            }
          }).catch(v=>{
            //tag)
            self.$showMessage('安检转维修失败！')
          })
        }else{
          self.$showMessage('安检转维修失败！')
        }
      }
    }
  }



  let getRepairs = async function(self,url) {
    // 获取配置信息
    try {
      let val = {source: 'this.getParentByType($department$).getChildByName($维修员$).getUsers()', userid: `${Vue.$login.jwt}`}
      let repairs =[]
      let res = await Vue.resetpost(`${url}/rs/search`,{data: val},{resolveMsg: null, rejectMsg: null})
      res.data.forEach((item) => {
        repairs.push({label: item.name, value: item})
      })
      self.f_repair_person = repairs
      if(self.$parent.$parent.role == 'inspect'){
        let res = self.$androidUtil.bzLogic('getUserInfo',{id:self.paper.f_userinfoid})
        if(res.code == 200){
          self.user = res.data[0]
          self.model.f_area = self.user.f_area
        }
      }else{
        //tag
        self.$resetpost(`${self.Url}/rs/sql/getUserInfo`,{data:{id:self.paper.f_userinfoid}},{resolveMsg: null, rejectMsg: null}).then((res)=>{
          //tag
          if(res.data.length != 0){
            self.user = res.data[0]
            self.model.f_area = self.user.f_area
          }
        })
        // path({alias:'getUserInfo',data:{id:this.paper.f_userinfoid}})
      }
    } catch (error) {
      //tag
    }
  }

  export default {
    title: '用户反馈',
    data() {
      return {
        paper:this.$parent.$parent.data,
        printContent:[],
        radios:[
          {
            label: '满意',
            value: 0,
            isChecked: false,
          },
          {
            label: '基本满意',
            value:1,
            isChecked: false,
          },
          {
            label: '不满意',
            value:2,
            isChecked: false,
          },
        ],
        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:[],
        repairstypes:this.$appdata.getParam('报修类型'),
        f_repair_person: this.readRepair(),
        showrepair: false,
        safeCheckToRepair:'',
        showCheckToRepair:false,
        userid: '',
        source:
        'dep=this.getParentByType($organization$).getSpecialResByType($department$),' +
        'tool.getFullTree(dep.where(row.getChildByName($派单员$) != null))',
        isback:false,
        defectDevice:{},
        detail:{},
        callObj:null,
        user:{},
        role:this.$parent.$parent.role,
        handling:[{label:'转站点',value:'转站点'},{label:'转维修员',value:'转维修员'}],
        meading:'转站点',
        Url:this.$androidUtil.getProxyUrl()
      }
    },
    props: ['idx'],
    components: {
      RadioGroup,
      Radio
    },
    methods: {
      check(index) {
        //tag
        // 先取消所有选中项
        for (let item of this.radios){
          item.isChecked = false;
        }
        //再设置当前点击项选中
        this.paper.f_client_evaluation = this.radios[index].label;
        // 设置值，以供传递
        this.radios[index].isChecked = true;
        //tag;
      },
      getSignValue(fileName) {
        this.f_signname = fileName
      },
      cameraCallBack(prop, fileName) {
        HostApp.__this__.paper[prop] = fileName + '?' + Math.random()
        HostApp.__callback__ = null
        HostApp.__this__ = null
      },
      takePic(prop, title) {
        HostApp.__callback__ = this.cameraCallBack
        HostApp.__this__ = this
        //tag
        //tag
        let fileName
        if (!this.paper[prop] || this.paper[prop].includes("nopic.png")) {
          fileName = Util.guid() + '-' + prop + '.jpg'
        } else {
          fileName = Util.getFileName(this.paper[prop])
        }
        HostApp._open_a_page({
          type: 'boomerang',
          page: 'com.aofeng.hybrid.android.peripheral.CameraActivity',
          param: {
            file: fileName,
            requestCode: 111,
            callback: 'javascript:HostApp.__callback__("' + prop + '", "%s");',
            watermark: title + '\t时间：' + Util.toStandardTimeString() + '\t' + Vue.user.name
          }
        })
      },
      amrCallBack(fileName) {
        HostApp.__this__.$set('paper.f_recording1_path', fileName)
        HostApp.__callback__ = null
        HostApp.__this__ = null
      },
      record() {
        if (this.$parent.$parent.role != 'inspect') {
          if (this.paper.f_recording1_path != '') {
          window.location = this.paper.f_recording1_path
        }
        } else {
          HostApp.__callback__ = this.amrCallBack
          HostApp.__this__ = this
          let fileName
          if (!this.paper.f_recording1_path) {
            fileName = Util.guid() + '.amr'
          } else {
            fileName = Util.getFileName(this.paper.f_recording1_path)
          }
          HostApp._open_a_page({
            type: 'boomerang',
            page: 'com.aofeng.hybrid.android.peripheral.AudioClipActivity',
            param: {file: fileName, requestCode: 111, callback: 'javascript:HostApp.__callback__("%s");'}
          })
        }
      },
      // 签名回调
      signCallback(prop, fileName) {
        // HostApp.alert('绑定属性:' + prop + ' 文件全路径如file:///storage/sdcard0/safecheck/abc.jpg：' + fullFileName)
        HostApp.__this__.$set('paper.f_sign_path', fileName)
        HostApp.__callback__ = null
        HostApp.__this__ = null
      },
      // 用户签名
      sign() {
        this.delAudioFile('f_sign_path', this.paper.f_sign_path)
        let prop = 'f_sign_path'
        let idx = 'aofeng'
        let fileName
        if (!this.paper.f_sign_path) {
          fileName = Util.guid() + '-valve-' + idx + '-' + prop + '.jpg'
        } else {
          fileName = Util.getFileName(this.paper.f_sign_path)
        }
        HostApp.__callback__ = this.signCallback
        HostApp.__this__ = this
        HostApp.getSignature({
          file: fileName,
          requestCode: 111,
          callback: 'javascript:HostApp.__callback__("' + prop + '", "%s");'
        })
      },
      delfile(prop, fileName) {
        if (fileName == Vue.nopic)
          return
        else {
          HostApp.delfile(fileName)
          this.paper[prop] = Vue.nopic
        }
      },
      delAudioFile(prop, fileName) {
        if (!fileName)
          return
        else {
          HostApp.delfile(fileName)
          this.paper[prop] = null
        }
      },
      //获取打印用户信息
      getUser() {
        if (this.paper.f_user_name == undefined)
          this.paper.f_user_name = ''
        this.printContent.push({type: 3, text: '用户名称：' + this.paper.f_user_name, fontsize: 2, isbold: false, align: 'left'})
        if (this.paper.f_userinfo_code == undefined)
          this.paper.f_userinfo_code = ''
        this.printContent.push({type: 3, text: '用户编号:' + this.paper.f_userinfo_code, fontsize: 2, isbold: false, align: 'left'})
        if (this.paper.f_address == undefined)
          this.paper.f_address = ''
        this.printContent.push({type: 3, text: '地址:' + this.paper.f_address, fontsize: 2, isbold: false, align: 'left'})
        if (this.paper.f_user_phone == undefined)
          this.paper.f_user_phone = ''
        this.printContent.push({type: 3, text: '电话:' + this.paper.f_user_phone, fontsize: 2, isbold: false, align: 'left'})
      },
      verify(){
        let hasError = this.$parent.$parent.verifyUser()
        if(hasError)
          return hasError
        hasError = this.$parent.$parent.verifyDevices()
        if(hasError)
          return hasError
      },
      print() {
        let errString = this.verify()
        if (errString) {
          //tag
          if (Vue.android)
            this.$showMessage(errString)
          return
        }
        // 文本
        let templatename = '安检结果单'
        if(Vue.config.safecheck != undefined) {
          if (Vue.config.safecheck.ApproveConfig != undefined) {
            if (Vue.config.safecheck.ApproveConfig.templatename != undefined) {
              templatename = Vue.config.safecheck.ApproveConfig.templatename
            }
          }
        }
        let textHead = {type: 3, text: templatename, fontsize: 3, isbold: true, align: 'center'}
        let feedPageHead = {type: 4, value: 2, unit: 'line'}
        let feedPageEnd = {type: 4, value: 4, unit: 'line'}
        this.printContent.push(textHead)
        this.printContent.push(feedPageHead)
        this.getUser()
        this.getDefect()
        this.getCheck()
        this.printContent.push(feedPageEnd)
        let arrstr = JSON.stringify(this.printContent)
        //tag
        this.$androidUtil.print(arrstr)
        this.$set('printContent', [])
      },
      //打印安检信息
      getCheck() {
        let telephone = '96777'
        if(Vue.config.safecheck != undefined) {
          if (Vue.config.safecheck.ApproveConfig != undefined) {
            if (Vue.config.safecheck.ApproveConfig.checkphone != undefined) {
              telephone = Vue.config.safecheck.ApproveConfig.checkphone
            }
          }
        }
        this.printContent.push({type: 3, text: '*******************************', fontsize: 3, isbold: false, align: 'center'})
        this.printContent.push({type: 3, text: '咨询电话；'+telephone, fontsize: 2, isbold: false, align: 'left'})
        this.printContent.push({type: 3, text: '安检人：'+Vue.user.name, fontsize: 2, isbold: false, align: 'left'})
        this.printContent.push({type: 3, text: '安检时间：' + this.getNowFormatDate(), fontsize: 2, isbold: false, align: 'left'})
        this.printContent.push({type: 3, text: '用户签字：', fontsize: 2, isbold: false, align: 'left'})
        this.printContent.push({type: 4, value: 4, unit: 'line'})
     },

      getDefect() {
        let showmore = false
        if(Vue.config.safecheck != undefined) {
          if (Vue.config.safecheck.ApproveConfig != undefined) {
            if (Vue.config.safecheck.ApproveConfig.showmore != undefined) {
              showmore = Vue.config.safecheck.ApproveConfig.showmore
            }
          }
        }

        let backData = this.$parent.$parent.getAllDefect()
        // 对隐患信息进行遍历
        let res = JSON.parse(backData.f_defect_content)
          this.printContent.push({
            type: 3,
            text: '安检结果：' + res.result,
            fontsize: 2,
            isbold: false,
            align: 'left'
          })
        this.printContent.push({type: 3, text: '*******************************', fontsize: 3, isbold: false, align: 'center'})


        if(showmore) {
          //全部打印
          for (let dev in this.$parent.$parent.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
                    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
                      }
                    }
                    if (error) {
                      this.printContent.push({
                        type: 3,
                        text: dev + (backData[device].indexOf(backData[device][item]) + 1) + '：正常',
                        fontsize: 2,
                        isbold: false,
                        align: 'left'
                      })
                    } else {
                      this.printContent.push({
                        type: 3,
                        text: dev + (backData[device].indexOf(backData[device][item]) + 1) + ':有隐患',
                        fontsize: 2,
                        isbold: true,
                        align: 'left'
                      })
                    }

                    for (let i in backData[device][item].f_items) {
                      if (backData[device][item].f_items[i].f_item_value != '' && backData[device][item].f_items[i].f_item_value != null) {
                        this.printContent.push({
                          type: 3,
                          text:  backData[device][item].f_items[i].f_item_name + backData[device][item].f_items[i].f_item_value,
                          fontsize: 2,
                          isbold: false,
                          align: 'left'
                        })
                      }
                    }
                    this.printContent.push({type: 4, value: 2, unit: 'line'})
                  }
                }
              }
            }
          }

          for (let dev in this.$parent.$parent.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
                    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
                      }
                    }
                    if (!error) {
                      this.printContent.push({
                        type: 3,
                        text:  '隐患:',
                        fontsize: 2,
                        isbold: true,
                        align: 'left'
                      })
                    }
                  }
                }
              }
            }
            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') {
                      this.printContent.push({
                        type: 3,
                        text: backData[device][item].f_items[i].f_item_name + ' ' + backData[device][item].f_items[i].f_item_value,
                        fontsize: 2,
                        isbold: true,
                        align: 'left'
                      })
                    }
                  }
                  }
                }
              }
            }

          }
        }else {
          for (let dev in this.$parent.$parent.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
                    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
                      }
                    }
                    if (error) {
                      this.printContent.push({
                        type: 3,
                        text: dev + (backData[device].indexOf(backData[device][item]) + 1) + '：正常',
                        fontsize: 2,
                        isbold: false,
                        align: 'left'
                      })
                    } else {
                      this.printContent.push({
                        type: 3,
                        text: dev + (backData[device].indexOf(backData[device][item]) + 1) + ':有隐患',
                        fontsize: 2,
                        isbold: false,
                        align: 'left'
                      })
                    }

                    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') {
                        this.printContent.push({
                          type: 3,
                          text: '隐患:' + backData[device][item].f_items[i].f_item_name + backData[device][item].f_items[i].f_item_value,
                          fontsize: 2,
                          isbold: false,
                          align: 'left'
                        })
                      }
                    }
                    this.printContent.push({type: 4, value: 2, unit: 'line'})
                  }
                }
              }
            }
          }
        }
      },
      //获取当前时间
      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;
      },
      readRepair () {
        let url = this.$androidUtil.getProxyUrl()
        let gen = getRepairs(this,url)
        return co(gen)
      },
      showToRepair(){
        let res = this.hasDefect()
        //tag
        //tag
        if(res == '正常'){
          this.showrepair = false
        }else{
          this.showrepair = true
          this.assignObj()
        }
        this.showCheckToRepair = !this.showCheckToRepair
      },
      // 选中部门
      reres(val){
        if(val.res == undefined){
          return
        }
        this.model.serviceacitivity[0].f_meetunit = val.res
        this.model.f_meetunit = val.res
        this.model.f_orgstr = val.resids
        var arr = val.res.split('.')
        this.model.f_outlets = arr[arr.length - 1]
        this.model.serviceacitivity[0].f_reciever = val.resids
      },
      assignObj(){
        this.model.f_contact_phone = this.paper.f_user_phone
        this.model.f_user_name = this.paper.f_user_name
        this.model.f_address = this.paper.f_address
        this.model.f_user_type = this.paper.f_check_type
        this.model.f_street = this.paper.f_street
        this.model.f_residential_area = this.paper.f_residential_area
        this.model.f_building = this.paper.f_building
        this.model.f_unit = this.paper.f_unit
        this.model.f_floor = this.paper.f_floor
        this.model.f_room = this.paper.f_room
        this.model.f_floor = this.paper.f_floor
        this.model.f_userinfo_id = this.paper.f_userinfoid
        this.model.f_userinfo_code = this.paper.f_userinfo_code
      },
      hasDefect(){
        let checkResult = '正常'
        let codata = JSON.parse(JSON.stringify(this.paper))
        for(let device in this.paper){
          if(device.startsWith("device")){
              for(let item in this.paper[device]) {
                for(let i in this.paper[device][item].f_items){
                  let items = this.paper[device][item].f_items[i]
                  //tag
                  if(items.f_is_defect == true || items.f_is_defect == 'true'){
                    checkResult = '有隐患'
                  }
                }
              }
          }
        }
        return checkResult
      },
      uploadPaper() {
        if(this.showrepair){
          this.$parent.$parent.isToRepair = true
          this.$parent.$parent.savePaper(false).then((res) => {
            //tag
            if(res != true){
              //tag
              return
            }else{
              //TODO 上传成功 转维修失败
              this.todo()
            }
          })
        }else{
          this.undo()
        }

      },
      //确认安检转维修
      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 = '转站点'
      },
      repiarmancg(val){
        if(val){
          //tag
          this.model.serviceacitivity[0].f_reciever = val.name
          let http1 = new HttpResetClass()
          http1.load('POST',`${this.Url}/rs/sql/tel_singleTable_OrderBy`, {data: {
              items: 'f_user_telephone',
              tablename: 't_user',
              condition: `name  = '${val}'`,
              orderitem: 'id'
            }}, {resolveMsg: null, rejectMsg: null}).then((ress) => {
            this.model.f_repairman_phone = ress.data[0].f_user_telephone
          })
        }
      },
    },
    ready() {
      if(!this.$parent.$parent.showBack){
        this.$parent.$parent.showBack= true
      }
      for (let item of this.radios){
         if(this.paper.f_client_evaluation == item.label){
          item.isChecked = true;
        }
      }
      //tag
      //tag
      //tag
      //tag
      if (!this.paper.f_notified_path)
        this.$set('paper.f_notified_path', Vue.nopic)
      if (!this.paper.f_sign_path)
        this.$set('paper.f_sign_path', Vue.nopic)
      if (!this.paper.f_overall_path)
        this.$set('paper.f_overall_path', Vue.nopic)
      if (!this.paper.f_overall2_path)
        this.$set('paper.f_overall2_path', Vue.nopic)

      this.userid = this.role == 'view'? this.$login.f.id:Vue.user.id
      if(Vue.config.safecheck != undefined){
        if(Vue.config.safecheck.ApproveConfig != undefined){
          if(Vue.config.safecheck.ApproveConfig.safeCheckToRepair != undefined) {
            this.safeCheckToRepair = Vue.config.safecheck.ApproveConfig.safeCheckToRepair
          }
        }
      }
      //tag
      //tag
    },
    watch:{
      '$parent.$parent.isUpload'(val){
        //tag
      }
    }
  }
</script>
<style>
  .text-left{
    text-align:left;
  }
  .font{
    font: 15px PingFang-SC-Medium;
    color: #333333;
  }
  .showInput{
    font: 14px PingFang-SC-Medium;
    color: #666666;
  }
  .info{
    margin-top: 15px;
    border-radius: 5px;
    background-color: #f3faff;
  }
  .btn-photo{
    border: 0;
    border-radius: 7px;
    background-color: #7dc1f4;
    font: 15px PingFang-SC-Bold;
    height: 20%;
  }
  .div-photo{
    width: auto;
    height: auto;
    /* margin-top: 10px; */
    position: absolute;
    bottom: 10px;
    right: 10px;
  }
  .btn-voice{
    border-radius: 7px;
    border: 1px solid #dedede;
    background-color: #f5fbff;
    font: 15px PingFang-SC-Bold;
    color: #499edf;
  }
  .save-btn{
    width: 25%;
    background-color:#499edf;
    border-radius: 6px;
    color: #FFFFFF;
    font: 15px PingFang-SC-Bold;
  }
  .upload-btn{
    width: 25%;
    background-color:#ffffff;
    border: 1px solid #499edf;
    border-radius: 6px;
    color: #499edf;
    font: 15px PingFang-SC-Bold;
  }
  .repair-btn{
    width: 25%;
    border: 1px solid #499edf;
    border-radius: 6px;
    font: 15px PingFang-SC-Bold;
  }
</style>
