<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"  :class="style__">
      <div class="text-center">
        <label class="font">请拍摄总体巡检照片：</label>
      </div>
    </div>
    <div class="form-group col-sm-12"  :class="style__">
      <label class="text-left font">总体安检照片</label>

      <div class="auto" :class="style__">
        <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-xs-4 col-sm-3 col-md-2" style="margin-bottom: 35px" v-for="(index,img) in paper.f_overall_imgs">
                <img-self :src="img.f_overall_path" alt="总体安检照片" :width="140" :height="170"></img-self>
                <img src="../../assets/删除.png" @click="delfile('f_overall_path', img.f_overall_path,index)" style="width: 15px;margin-top: -80px" alt="">
              </div>
            </div>
            <div class="row text-right div-photo">
              <button type="button" name="button" class="btn btn-photo" @click="takePic('f_overall_path', '总体安检照片')">拍照</button>
              <!--<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', img.f_overall_path)" style="width: 25%;"></img>-->
            </div>
          </div>
        </div>
      </div>
    </div>
    </form>
</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 getRepairs = async function(self,url) {
    // 获取配置信息
    try {
      let val = {source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($维修员$) != -1 ))', userid: `${Vue.user.id}`}
      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.$parent.$parent.user = res.data[0]
          self.$parent.$parent.model.f_area = self.$parent.$parent.user.f_area
        }
      }else{
        //tag
        self.$resetpost(`${self.Url}/rs/sql/safeCheckgetUserInfo`,{data:{id:self.paper.f_userinfoid}},{resolveMsg: null, rejectMsg: null}).then((res)=>{
          //tag
          if(res.data.length != 0){
            self.$parent.$parent.user = res.data[0]
            self.$parent.$parent.model.f_area = self.$parent.$parent.user.f_area
          }
        })
        // path({alias:'getUserInfo',data:{id:this.paper.f_userinfoid}})
      }
    } catch (error) {
      //tag
    }
  }

  export default {
    title: '用户反馈',
    data() {
      return {
        images: [],
        showmodelthree: false,
        isneedDate: this.$parent.$parent.isneedDate,
        plan: this.$parent.$parent.item,
        meading: this.$parent.$parent.meading,
        paper: this.$parent.$parent.data,
        printContent: [],
        upload_state: this.$parent.$parent.item.f_upload_state,
        enabled: false,//控制限制购气是否可选
        deleteenabled: false,
        showmodel: false,
        backlistisselect: false,
        deletebacklistisselect: false,
        radios: [
          {
            label: '满意',
            value: 0,
            isChecked: false,
          },
          {
            label: '基本满意',
            value: 1,
            isChecked: false,
          },
          {
            label: '不满意',
            value: 2,
            isChecked: false,
          },
        ],
        repairitems: [],
        showrepair: false,
        safeCheckToRepair: '',
        showCheckToRepair: false,
        userid: '',
        source:
          'dep=this.getParentByType($organization$).getSpecialResByType($department$),' +
          'tool.getFullTree(dep.where(row.hasSpecialRole($派单员$)))',
        isback: false,
        defectDevice: {},
        detail: {},
        callObj: null,
        user: {},
        role: this.$parent.$parent.role,
        Url: this.$androidUtil.getProxyUrl(),
        cause: "",
        deletecause: "",
      }
    },
    props: ['idx'],
    components: {
      RadioGroup,
      Radio
    },
    methods: {
      timeSet(val) {
        ////tag
        if (!val) {
          return
        }
        let time = new Date(val).getTime()
        let time2 = new Date().getTime()
        if (time2 > time) {
          return true
        }
      },
      // async isoverDate(){
      //   //tag
      //   let res= await this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/androidGetuserinfo`, {data:{
      //       condition:"f_plan_item_id='"+this.$parent.$parent.item.id+"'"
      //     }
      //   })
      //   this.isneedDate=res.data[0]["f_subscribe_date"]
      //   //tag
      // },
      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) {
        if (prop == 'f_overall_path') {
          let f_overall_path = fileName + '?' + Math.random()
          HostApp.__this__.paper.f_overall_imgs.push({
            f_overall_path: f_overall_path
          })
        } else {
          HostApp.__this__.paper[prop] = fileName + '?' + Math.random()
        }
        HostApp.__callback__ = null
        HostApp.__this__ = null
      },
      takePic(prop, title, index) {
        HostApp.__callback__ = this.cameraCallBack
        HostApp.__this__ = this
        //tag
        //tag
        let fileName
        if (prop == 'f_overall_path') {
          if (!this.paper.f_overall_imgs[index] || this.paper.f_overall_imgs[index].f_overall_path.includes("nopic.png")) {
            fileName = Util.guid() + '-' + prop + '.jpg'
          } else {
            fileName = Util.getFileName(this.paper.f_overall_imgs[index].f_overall_path)
          }
        } else {
          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 + '\t' + this.paper.f_userinfo_code+ '\t' + this.paper.f_user_name+ '\t' + this.paper.f_address
          }
        })
      },
      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() {
        if (!this.paper.f_read_instructions) {
          this.$showMessage('请先阅读并勾选用户须知内容后进行签名！')
          return
        }
        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, index) {
        if (fileName == Vue.nopic)
          return
        else {
          if (prop == 'f_overall_path') {
            this.paper.f_overall_imgs.splice(index, 1)
            HostApp.delfile(fileName)
          } 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
      },



      //获取当前时间
      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.$parent.$parent.model.serviceacitivity[0].f_meetunit = val.res
        this.$parent.$parent.model.f_meetunit = val.res
        this.$parent.$parent.model.f_orgstr = val.resids
        var arr = val.res.split('.')
        this.$parent.$parent.model.f_outlets = arr[arr.length - 1]
        this.$parent.$parent.model.serviceacitivity[0].f_reciever = val.resids
      },
      assignObj() {
        this.$parent.$parent.model.f_contact_phone = this.paper.f_user_phone
        this.$parent.$parent.model.f_user_name = this.paper.f_user_name
        this.$parent.$parent.model.f_address = this.paper.f_address
        this.$parent.$parent.model.f_user_type = this.paper.f_check_type
        this.$parent.$parent.model.f_street = this.paper.f_street
        this.$parent.$parent.model.f_residential_area = this.paper.f_residential_area
        this.$parent.$parent.model.f_building = this.paper.f_building
        this.$parent.$parent.model.f_unit = this.paper.f_unit
        this.$parent.$parent.model.f_floor = this.paper.f_floor
        this.$parent.$parent.model.f_room = this.paper.f_room
        this.$parent.$parent.model.f_floor = this.paper.f_floor
        this.$parent.$parent.model.f_userinfo_id = this.paper.f_userinfoid
        this.$parent.$parent.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) {
          //tag
          //tag
          //tag
          //tag

          if (this.meading == '转维修员' && (this.$parent.$parent.model.serviceacitivity[0].f_reciever == '' || this.$parent.$parent.model.serviceacitivity[0].f_reciever == undefined)) {
            this.$showMessage("请选择维修员!")
            return
          }
          if (this.$parent.$parent.meading == '转站点' && (this.$parent.$parent.model.serviceacitivity[0].f_reciever == '' || this.$parent.$parent.model.serviceacitivity[0].f_reciever == undefined)) {
            this.$showMessage("请选择站点!")
            return
          }
          if (this.$parent.$parent.model.f_repairtype == '') {
            this.$showMessage("请选择报修类型!")
            return
          }
          this.$parent.$parent.isToRepair = true
          this.$parent.$parent.uploadCheckPaper()
          // this.$parent.$parent.savePaper(false).then((res) => {
          //   //tag
          //   if(res != true){
          //     //tag
          //     return
          //   }else{
          // this.$parent.$parent.todo()
          //   }
          // })
        } else {
          this.$parent.$parent.undo()
        }

      },
      //确认安检转维修

      undo() {
        this.showCheckToRepair = !this.showCheckToRepair
        this.$parent.$parent.model.serviceacitivity[0].f_reciever = ''
        this.$parent.$parent.model.serviceacitivity[0].f_meetunit = ''
        this.$parent.$parent.model.f_repairtype = ''
        this.meading = '转站点'
      },
      //取消拉黑
      async deletebacklist() {
        if (!this.deletecause) {
          this.$showMessage("请填写取消拉黑原因！")
          return
        }
        this.paper.f_blocking_cause = this.deletecause
        //tag)
        let http = new HttpResetClass()
        //tag
        let res1 = await http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/sql/safe_singleTable_OrderBy`, {
          data: {
            items: "version",
            tablename: "t_userinfo",
            condition: "f_userinfo_id=" + this.paper.f_userinfoid,
            orderitem: "f_userinfo_id"
          }
        }, {resolveMsg: null, rejectMsg: null})
        //tag)
        //tag
        let res2 = await http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/logic/backlistOperate`, {
          data: {
            "f_operat_type": "取消拉黑",
            "f_state": "有效",
            "f_user_name": this.paper.f_user_name,
            "f_comments": this.paper.f_delete_cause,
            "f_operator": Vue.user.name,
            "f_operatorid": Vue.user.id,
            "f_orgid": Vue.user.orgid,
            "f_orgname": Vue.user.orgs,
            "f_depid": Vue.user.depids,
            "f_depname": Vue.user.deps,
            "f_describe": `${Vue.user.name}对用户${this.paper.f_user_name}进行取消拉黑`,
            "f_userinfo_id": {
              "f_userinfo_id": this.paper.f_userinfoid,
              "f_user_state": "正常",
              "version": res1.data[0].version
            },
            "f_limit_times":"",
            "f_limit_value":""
          }
        }, {resolveMsg: null, rejectMsg: null})

        //tag)
        if (res2.data.code == 200) {
          this.showmodelthree = false
          this.deleteenabled = true
          this.paper.f_blacklist = "否"
          this.$showMessage("取消该用户限制购气成功！")
        } else {
          this.$showMessage("网络异常，请稍后再试！")
        }
      },
      async backlist() {
        if (!this.cause) {
          this.$showMessage("请填写拉黑原因！")
          return
        }
        this.paper.f_blocking_cause = this.cause
        //tag)
        let http = new HttpResetClass()
        //tag
        let res1 = await http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/sql/safe_singleTable_OrderBy`, {
          data: {
            items: "version",
            tablename: "t_userinfo",
            condition: "f_userinfo_id=" + this.paper.f_userinfoid,
            orderitem: "f_userinfo_id"
          }
        }, {resolveMsg: null, rejectMsg: null})
        //tag)
        //tag
        let res2 = await http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/logic/backlistOperate`, {
          data: {
            "f_operat_type": "拉黑",
            "f_state": "有效",
            "f_user_name": this.paper.f_user_name,
            "f_comments": this.paper.f_blocking_cause,
            "f_operator": Vue.user.name,
            "f_operatorid": Vue.user.id,
            "f_orgid": Vue.user.orgid,
            "f_orgname": Vue.user.orgs,
            "f_depid": Vue.user.depids,
            "f_depname": Vue.user.deps,
            "f_describe": `${Vue.user.name}对用户${this.paper.f_user_name}进行拉黑`,
            "f_userinfo_id": {
              "f_userinfo_id": this.paper.f_userinfoid,
              "f_user_state": "正常",
              "version": res1.data[0].version
            },
            "f_limit_times":"1",
            "f_limit_value":"3"
          }
        }, {resolveMsg: null, rejectMsg: null})

        //tag)
        if (res2.data.code == 200) {
          this.showmodel = false
          this.enabled = true
          this.paper.f_blacklist = "是"
          this.$showMessage("将该用户限制购气成功！")
        } else if (res2.data.msg == '数据增加重复') {
          this.showmodel = false
          this.enabled = true
          this.$showMessage("该用户已被限制购气，请勿重复提交！")
        } else {
          this.$showMessage("网络异常，请稍后再试！")
        }
      },
      cancel() {
        this.backlistisselect = false
        this.showmodel = false
      },
      deletecancel() {
        this.deletebacklistisselect = false
        this.showmodelthree = false
      },
      repiarmancg(val) {
        if (val) {
          //tag
          this.$parent.$parent.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.$parent.$parent.model.f_repairman_phone = ress.data[0].f_user_telephone
          })
        }
      },
    },
    async ready() {
      // await this.isoverDate()
      //tag
      //tag
      //tag)
      if (this.$parent.$parent.role == 'repair') {
        this.$set('style__', 'divmask')
        this.$set('style_view_', '')
      } else if (this.$parent.$parent.role == 'view' || this.$parent.$parent.item.f_upload_state == '已传') {
        this.$set('style__', 'divmask')
        this.$set('style_view_', 'divmask')
        //tag
      } else {
        this.$set('style__', '')
        this.$set('style_view_', '')
      }

      for (let item of this.radios) {
        if (this.paper.f_client_evaluation == item.label) {
          item.isChecked = true;
        }
      }
      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)
      //tag
      if (!this.paper.f_overall_imgs) {
        let imgs = []
        // imgs.push({f_overall_path:Vue.nopic})
        this.$set('paper.f_overall_imgs', imgs)
        //tag
      }
      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
      //tag
      //tag
      //tag
      //tag
      //tag
    }
  }
</script>
<style scoped>
  .panel-self{
    border-radius: 5px;
    border:1px solid #c5e1f7;
    background-color: #F2F6FA;
  }
  .text-left{
    text-align:left;
  }
  .font{
    font: 15px PingFang-SC-Medium;
    color: #333333;
  }
  .showIi{
    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;
  }
  #el_ca_tx{
    width: 100%;
    margin: 5px;
  }
  #el_ca_txt{
    width: 100%;
    margin: 5px;
  }
</style>
