<template>
  <div class="flex-row" v-show="isshowd">
    <div class="basic-main">
      <criteria-paged :model="model" v-ref:paged @sort="sort">
        <criteria partial='criteria' class="search_area" @condition-changed='$parent.selfSearch' v-ref:criteria>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">客户编号</label>
                <input type="text" class="input_search" v-model="model.f_userinfo_code"
                       style="width: 60%" placeholder="客户编号" condition="f_userinfo_code='{}'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">客户名称</label>
                <input type="text" class="input_search" v-model="model.f_user_name"
                       style="width: 60%" placeholder="客户名称" condition="f_user_name like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">客户电话</label>
                <input type="text" class="input_search" v-model="model.f_user_phone"
                       style="width: 60%" placeholder="客户电话" condition="f_user_phone like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">小&emsp;&emsp;区</label>
                <input type="text" class="input_search" v-model="model.f_residential_area"
                       style="width: 60%" placeholder="小区" condition="f_residential_area like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">详细地址</label>
                <input type="text" class="input_search" v-model="model.f_address"
                       style="width: 60%" placeholder="详细地址" condition="f_address like '%{}%'">
              </div>
              <div class="form-group col-sm-2" style="width: auto;margin-top:8px;float: right">
                <button class="button_search" v-if="$parent.$parent.canToRepair == '是'"  @click="$parent.$parent.toRepair">转维修</button>
                <export-excel-safe :data="$parent.$parent.searchData"
                                   :field="$parent.$parent.excelHeaders"
                                   progress="safeGetExportProgress"
                                   sqlurl="rs/logic/SafeExportExcel" sql-name="safe_singleTable_OrderBy" template-name='安检隐患明细'></export-excel-safe>
                <!--                <button class="button_spacing button_search" @click="$parent.$parent.showaudio()" v-if="!$parent.$parent.audioshow">录音</button>-->
                <button class="button_spacing button_search" @click="$parent.$parent.showaudio()" v-if="$parent.$parent.audioshow">隐藏</button>
                <button class="button_spacing button_search" @click="search()">查询</button>
                <div style="float: right" class="button_spacing"
                     :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                     @click="$parent.$parent.hidden()"></div>
              </div>

            </div>
            <div class="row">
              <div class="col-sm-4 form-group" v-show="$parent.$parent.criteriaShow" style="margin: 0">
                <role-selector-safe
                  role-name="安检员"
                  role-lable="安&nbsp;检&nbsp;员&nbsp;"
                  @re-res="$parent.$parent.getRes"
                  :value.sync="model.f_checker_id"
                  v-model="model.f_checker_id"
                  condition="f_checker_name = '{}'">
                </role-selector-safe>
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">检&ensp;查&ensp;项</label>
                <v-select :value.sync="model.f_device_type" v-model='model.f_device_type'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.device_types' placeholder='检查项'
                          close-on-select
                          @change="$parent.$parent.changeDefect"
                          condition="tpd.f_device_type = '{}'"></v-select>
                <!--<input type="text" class="input_search" v-model="model.f_device_type"-->
                <!--style="width: 60%" placeholder="检&ensp;查&ensp;项" condition="f_device_type like '%{}%'">-->
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">隐患名称</label>
                <v-select :value.sync="model.f_item_name" v-model='model.f_item_name'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.DefectConfigs' placeholder='隐患名称'
                          close-on-select
                          condition="f_item_name = '{}'"></v-select>
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">隐患情况</label>
                <input type="text" class="input_search" v-model="model.f_defect_content"
                       style="width: 60%" placeholder="隐患情况" condition="ditls.f_item_value  like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">处理情况</label>
                <input type="text" class="input_search" v-model="model.f_is_repaired"
                       style="width: 60%" placeholder="处理情况" condition="ditls.f_is_repaired  like '%{}%'">
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow">
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow" >
                <label class="font_normal_body">开始时间</label>
                <datepicker
                  class="select_list select"
                  :value.sync="model.f_check_start"
                  placeholder='开始时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_check_start"
                  condition="f_offsite_time > ='{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow" >
                <label class="font_normal_body">结束时间</label>
                <datepicker
                  :value.sync="model.f_check_end"
                  placeholder='结束时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_check_end"
                  condition="f_offsite_time <=  '{} 23:59:59'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">隐患等级</label>
                <v-select :value.sync="model.f_defect_level" v-model='model.f_defect_level'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.defect_level' placeholder='隐患等级'
                          close-on-select
                          condition="ditls.f_defect_level = '{}'"></v-select>
              </div>
            </div>
            <modal :show.sync="$parent.$parent.showModal" v-ref:modal>
              <div slot="modal-header" class="modal-header">
                <h4 class="modal-title">
                  选择计划
                </h4>
              </div>
              <div slot="modal-body" class="modal-body">
                <plan-chooser :f.sync="$parent.$parent.fun" v-ref:chooser></plan-chooser>
              </div>
              <div slot="modal-footer" class="modal-footer" style="text-align: center">
                <button class="button_search" @click="$parent.$parent.ok">确认</button>
                <button class="button_search" @click="$parent.$parent.cancel">取消</button>
              </div>
            </modal>
          </div>
        </criteria>
        <data-grid class="list_area table_sy" style="overflow: hidden" :model="model" partial='list' v-ref:grid>
          <template partial='head'>
            <tr>
              <th v-if="$parent.$parent.$parent.canToRepair=='是'"><nobr>选择</nobr></th>
              <th>
                <nobr>检查项</nobr>
              </th>
              <th>
                <nobr>隐患名称</nobr>
              </th>
              <th >
                <nobr>隐患等级</nobr>
              </th>
              <th >
                <nobr>隐患情况</nobr>
              </th>
              <th >
                <nobr>处理情况</nobr>
              </th>
              <th>
                <nobr>客户编号</nobr>
              </th>
              <th>
                <nobr>客户名称</nobr>
              </th>
              <th>
                <nobr>客户电话</nobr>
              </th>
              <th>
                <nobr>所属街道</nobr>
              </th>
              <th>
                <nobr>客户小区</nobr>
              </th>
              <th>
                <data-order field="f_address" name="客户地址"></data-order>
              </th>

              <th>
                <data-order field="f_offsite_time" name="安检时间"></data-order>
              </th>
              <th>
                <nobr>安检员</nobr>
              </th>
              <th>
                <nobr>操作</nobr>
              </th>
            </tr>
          </template>
          <template partial='body'>
            <td v-if="$parent.$parent.$parent.canToRepair=='是'" style="text-align: center;white-space:nowrap;"><input type="checkbox" v-if="['用户自行整改', '现场已处理', '维修已处理', '转维修','已处理'].indexOf(row.f_is_repaired) == -1" @click="$event.cancelBubble=true" :checked="$parent.$parent.$parent.isChecked(row)" @change="$parent.$parent.$parent.setCheckes(row)"></input></td>
            <td style="text-align: center" >{{row.f_device_type}}</td>
            <td style="text-align: center">{{row.f_item_name}}</td>
            <td style="text-align: center">{{row.f_defect_level}}</td>
            <td style="text-align: center;" >
              <button-link  type="button" class="btn btn-link"@click="$parent.$parent.$parent.situation(row)">
               {{row.f_item_value}}
              </button-link>
            </td>
            <td style="text-align: center">{{row.f_is_repaired}}</td>
            <td style="text-align: center">{{row.f_userinfo_code}}</td>
            <td style="text-align: center">{{row.f_user_name}}</td>
            <td style="text-align: center">{{row.f_user_phone}}</td>
            <td style="text-align: center">{{row.f_street}}</td>
            <td style="text-align: center">{{row.f_residential_area}}</td>
            <td style="text-align: center">{{row.f_address}}</td>
            <td style="text-align: center">{{row.f_offsite_time}}</td>
            <td style="text-align: center">{{row.f_checker_name}}</td>
            <td style="text-align: center">
              <button-link  type="button" class="btn btn-link" @click="$parent.$parent.$parent.details(row)">
                查看详情
              </button-link>
              <button-link  v-if="['用户自行整改', '现场已处理', '维修已处理', '转维修'].indexOf(row.f_is_repaired) == -1" type="button" class="btn btn-link" @click='$parent.$parent.$parent.showDealModal(row)'>
                处理
              </button-link>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
      <check-msg v-if="showcheckmsg" :show="showcheckmsg" :data="checkInfo"></check-msg>
    </div>
  </div>
<!--隐患情况详情查看  -->
  <modal :show.sync="trouble">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        隐患情况详情
      </h4>
    </div>
    <div slot="modal-body" class="modal-body" v-if="yhpath.f_path">
      <img :src="`/rs/image/file/${yhpath.f_path}`" alt="无照片！！！" width="300" height="320">
    </div>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-default" @click="trouble = false;yhpath=null">确认</button>
    </div>
  </modal>
  <!--转维修-->
  <modal :show.sync="showModal2" :backdrop="false">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        转维修
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div v-if="true">
        <div class="row" style="margin-top: 10px">
          <label class="control-label font text-left" style="float:left;margin-left:20%;margin-top:5px">派发类型</label>
          <div class="col-xs-8 col-md-8">
            <v-select :value.sync="selectData.dispatchType" :value-single="true" v-model="selectData.dispatchType"
                      :options='dispatchTypeOptions' placeholder='派发类型'
                      close-on-select>
            </v-select>
          </div>
        </div>
        <div class="row" style="margin-top: 10px" v-if="selectData.dispatchType=='派发给维修员'">
          <label class="control-label font text-left" style="float:left;margin-left:20%;margin-top:5px">维&ensp;修&ensp;员</label>
          <div class="col-xs-8 col-md-8">
            <v-select
              :value.sync="selectData.f_repairman"
              :value-single="true"
              :options='repairers'
              placeholder='请选择维修员'
              close-on-select></v-select>
          </div>
        </div>
        <div class="row" style="margin-top: 10px" v-if="selectData.dispatchType=='派发给站点'">
          <label class="control-label font text-left" style="float:left;margin-left:20%;margin-top:5px">站&ensp;&ensp;&ensp;&ensp;点</label>
          <div class="col-xs-8 col-md-8">
            <right-tree
              islist
              :source="'dep=this.getParentByType($organization$).getSpecialResByType($department$),tool.getFullTree(dep.where(row.hasSpecialRole($派单员$)))'"
              @re-res="getSiteRes"></right-tree>
          </div>
        </div>
        <div class="row" style="margin-top: 10px">
          <label class="control-label font text-left" style="float:left;margin-left:20%;margin-top:5px">报修类型</label>
          <div class="col-xs-8 col-md-8">
            <v-select :value.sync="selectData.f_repairtype" style="width:60%"
                      class="select select_list"
                      :value-single="true"
                      :options='repairTypeOptions'
                      close-on-select>
            </v-select>
          </div>
        </div>
        <div class="row" style="margin-top: 10px">
          <label  class="control-label font text-left" style="float:left;margin-left:20%;margin-top:5px">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
          <div class="col-xs-8 col-md-8">
            <textarea style="width: 60%; height: 100px" v-model="selectData.f_remarks"></textarea>
          </div>
        </div>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer" style="text-align: center">
      <button class="button_search" @click="rectification">转维修</button>
      <button class="button_search" @click="cancel1">取消</button>
    </div>
  </modal>
  <!--转维修进度条-->
  <modal :show.sync="showModal3">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        转维修进度{{ progressbarWidth }}%
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div class="progress">
        <div class="progress-bar" role="progressbar" aria-valuenow="60"
             aria-valuemin="0" aria-valuemax="100" :style="'width:'+ progressbarWidth+'%'">
        </div>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer" style="text-align: center" v-show="false"></div>
  </modal>
  <!--处理隐患-->
  <modal :show.sync="showSolveModal" v-ref:solveModal width="750px">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        处理隐患
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div style="width: 100%;height: 36px;background-color: #f1f8ff;float: left">
        <div style="width: 8px;height: 100%;background-color: #6aa6e2;margin-right: 20px;float: left"></div>
        <div style="width: auto;height:100%;float: left;"><p class="title-font" style="margin-top: 5px">处理前</p></div>
      </div>

      <div class="col-sm-6" style="margin-top: 10px">
        <label class="font_normal_body">安&nbsp;检&nbsp;员</label>
        <input class="input_search" style="width: 60%" type="text" disabled="true" v-model="check.f_checker_name" placeholder="安检员">
      </div>
      <div class="col-sm-6" style="margin-top: 10px">
        <label class="font_normal_body">安检时间</label>
        <input class="input_search" style="width: 60%" type="text" disabled="true" v-model="check.f_offsite_time" placeholder="安检时间">
      </div>
      <div class="col-sm-12" style="margin-bottom: 10px; display: flex; gap: 10px" >
        <label class="font_normal_body">隐患图片</label>
        <img-self-plus v-if="solveModal.preData.defectImg" :width="200" :height="200" :src="solveModal.preData.defectImg"></img-self-plus>
      </div>

      <div style="width: 100%;height: 36px;background-color: #f1f8ff;float: left">
        <div style="width: 8px;height: 100%;background-color: #6aa6e2;margin-right: 20px;float: left"></div>
        <div style="width: auto;height:100%;float: left;"><p class="title-font" style="margin-top: 5px">处理后</p></div>
      </div>
      <div v-if="solveModal.preData.state == '未处理'" class="col-sm-12" style="margin-bottom: 10px">
        <label class="font_normal_body">处理后图片</label>
        <avatar-upload :width="200" :height="200" :img-src.sync="solveModal.uploadData.imgSrc" :filename.sync="solveModal.uploadData.filename" v-ref:imginfo></avatar-upload>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer" style="text-align: center">
      <button class="button_search" @click="deal">确认</button>
      <button class="button_search" @click="showSolveModal = false">取消</button>
    </div>
  </modal>
</template>

<script>
import {PagedList} from 'vue-client'
import Vue from 'vue'
import co from 'co'
import AppData from '../../../stores/AppData'
import * as Util from '../../Util'
import getNowDate from "../../../utils/getNowDate";
import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
import BenzAMRRecorder from 'benz-amr-recorder'

//获取json配置文件
let asyncReady = async function (self) {
  // 获取配置信息
  try {
    let res = await Vue.resetget(`/phone/rs/vue`, {data: {}}, {resolveMsg: null, rejectMsg: null})
    Vue.config = res.data
    self.getDefectInfoConfig(res.data)
  } catch (error) {
    // 忽略704,文件找不到异常R
    if (error.status !== 704) {
      throw error
    }
  }
}

let select = function* (self) {
  let http = new HttpResetClass()
  let getGasman = yield http.load('POST', '/rs/search', {
    source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1))',
    userid: self.$login.f.id
  }, {resolveMsg: null, rejectMsg: null})
  ////tag
  self.checkersid.push({label: '全部', value: ''})
  getGasman.data.forEach((checker) => {
    self.checkersid.push({label: checker.name, value: checker.id})
  })
}

export default {
  title: '隐患明细查看',
  data() {
    let model = new PagedList('rs/sql/safe_singleTable_OrderBy', 20, {
      items: "`tcp.*,tpd.f_device_type,ditls.f_item_name,ditls.f_item_value,ditls.f_path,ditls.f_defect_level,ass.f_user_type,ass.version, ditls.f_defect_id,tpd.f_paper_id,ditls.f_repair_path,ditls.f_is_repaired`",
      tablename: "`t_check_paper tcp LEFT JOIN t_paper_devices tpd ON tcp.id= tpd.f_paper_id  LEFT JOIN t_userfiles ass on tcp.f_userinfoid=ass.f_userinfo_id LEFT JOIN (SELECT CASE WHEN dits.f_is_defect != 'true' THEN '无隐患' WHEN dits.f_is_defect = 'true' AND (dits.f_user_changes = '是' or dits.f_deal_dispose in ('自行处理', '自行整改')) THEN '用户自行整改' WHEN dits.f_is_defect = 'true' AND (dits.f_live_dispose = '是' or dits.f_deal_dispose='现场整改') THEN '现场已处理' WHEN dits.f_is_defect = 'true' AND dits.f_is_repaired = '已处理' THEN '已处理' WHEN dits.f_is_defect = 'true' AND dits.f_is_repaired = '转维修' THEN '转维修' ELSE '隐患未处理' END f_is_repaired, dits.f_repair_path,  dits.id as f_defect_id,dits.f_user_changes,dits.f_deal_dispose,dits.f_live_dispose, dits.f_is_defect,dits.f_device_id,dits.f_item_name,ditl.f_item_value ,dits.f_path,dits.f_defect_level FROM t_devices_items dits LEFT JOIN t_devices_items_lists ditl ON dits.id = ditl.f_item_id ) ditls ON tpd.id= ditls.f_device_id`",
      orderitem: "'f_offsite_time'"
    })
    model.f_plan_id = ''
    model.f_approved = ''
    model.f_entry = ''
    model.f_no_checkplan = ''
    model.f_filialeid = `('${this.$login.f.orgid}')`
    //model.f_check_type='民用'
    // let searchData={
    //     f_plan_id: this.model.f_checker_id==undefined?"":this.model.f_checker_id,
    //     f_approved: this.model.f_approved,
    //     f_entry_status: this.model.f_entry,
    //     f_no_checkplan:this.model.f_no_checkplan[0],
    //     f_filialeid: this.model.f_filialeid,
    //     //orderitem: this.model.f_offsite_time,
    //     //condition:this.model.condition
    // }
    // model.f_subcompany = this.$login.f.f_fengongsi

    return {
      isshowd:true,
      audioshow:false,
      trouble:false,
      searchData: {
        condition: "ditls.f_is_defect = 'true' and ass.f_table_state !='换表' ",
        items: "tcp.*,tpd.f_device_type,ditls.f_item_name,ditls.f_item_value,ditls.f_path,ditls.f_defect_level,ass.f_user_type,ass.version, ditls.f_defect_id,tpd.f_paper_id,ditls.f_repair_path,ditls.f_is_repaired",
        tablename: "t_check_paper tcp LEFT JOIN t_paper_devices tpd ON tcp.id= tpd.f_paper_id  LEFT JOIN t_userfiles ass on tcp.f_userinfoid=ass.f_userinfo_id LEFT JOIN (SELECT CASE WHEN dits.f_is_defect != 'true' THEN '无隐患' WHEN dits.f_is_defect = 'true' AND (dits.f_user_changes = '是' or dits.f_deal_dispose in ('自行处理', '自行整改')) THEN '用户自行整改' WHEN dits.f_is_defect = 'true' AND (dits.f_live_dispose = '是' or dits.f_deal_dispose='现场整改') THEN '现场已处理' WHEN dits.f_is_defect = 'true' AND dits.f_is_repaired = '已处理' THEN '已处理' WHEN dits.f_is_defect = 'true' AND dits.f_is_repaired = '转维修' THEN '转维修' ELSE '隐患未处理' END f_is_repaired, dits.f_repair_path, dits.f_defect_level,  dits.id as f_defect_id,dits.f_user_changes,dits.f_deal_dispose,dits.f_live_dispose, dits.f_is_defect,dits.f_device_id,dits.f_item_name,ditl.f_item_value ,dits.f_path FROM t_devices_items dits LEFT JOIN t_devices_items_lists ditl ON dits.id = ditl.f_item_id ) ditls ON tpd.id= ditls.f_device_id",
        orderitem: "f_offsite_time"
      },
      model: model,
      //searchData:searchData,
      excelHeaders: {
        'f_device_type': '检查项',
        'f_item_name': '隐患名称',
        'f_item_value': '隐患情况',
        'f_is_repaired': '处理情况',
        'f_userinfo_code': '客户编号',
        'f_user_name': '客户姓名',
        'f_user_phone': '客户电话',
        'f_street': '所属街道',
        'f_residential_area': '小区',
        'f_address': '客户地址',
        'f_offsite_time': '安检时间',
        'f_checker_name': '安检员',
        'f_defect_level': '隐患等级'
      },
      fun: this.$login.f,
      checkersid: [],
      safetype: [
        {label: '全部', value: ''}, ...this.$appdata.getParam('安检类型')],
      criteriaShow: false,
      showModal: false,
      defect_level: [{label: '全部', value: ''}, ...this.$appdata.getParam('隐患等级')],
      f_approval_states: this.$appdata.getParam('安检单审核状态'),
      f_entry_status: [{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')],
      f_checkplans: this.$appdata.getParam('有无计划'),
      showcheckmsg: false,
      checkInfo: {},
      orderDefault: "'f_offsite_time'",
      orderFields: {
        f_offsite_time: 'no'
      },
      DefectConfig:'' ,
      DefectConfigs:[{label:'全部',value:''}],
      device_types:[{label:'全部',value:''}],
      sliceArea: [],
      cbc:[],
      yhpath:null,
      checkes:[],
      dangerGroups:[],
      showModal2: false,
      showModal3: false,
      selectData:{
        dispatchType:'',
        f_repairman:'',
        f_remarks:'',
        f_repairtype:''
      },
      repairers: [],
      repairTypeOptions:this.$appdata.getParam('报修类型'),
      dispatchTypeOptions: [{label: '派发给站点', value: '派发给站点'},{label: '派发给维修员', value: '派发给维修员'}],
      progressbarWidth:'0',
      showSolveModal: false,
      check: null,
      solveModal: {
        preData: {
          type: '',
          defectImg: '',
          repairedImg: '',
          state: ''
        },
        uploadData: {
          id: '',
          f_repairman: this.$login.f.name,
          f_repair_date: Util.getNowDate(),
          f_repair_path: '',
          imgSrc: '',
          filename: ''
        }
      },
      canToRepair: this.$appdata.getSingleValue('隐患明细转维修'),
     }
  },
  methods: {
    getEmp() {
      let val = {source: 'this.getParentByType($organization$).getSpecialResByType($user$).where(row.getAttributes().get($rolestr$)!=null ).where(row.getAttributes().get($rolestr$).indexOf($维修员$) != -1))', userid: `${this.$login.f.id}`}
      let http = new HttpResetClass()
      http.load('POST', '/rs/search', {data: val}, {resolveMsg: null, rejectMsg: null}).then((res) => {
        if (res.data.length == 0){
          this.repairers= []
          return
        }
        let str=``
        res.data.forEach((item,idx,arr) => {
          if(idx+1==arr.length){
            str += item.id
          }else{
            str += item.id+`','`
          }
        })
        let http1 = new HttpResetClass()
        http1.load('POST', 'rs/sql/tel_singleTable_OrderBy', {
          data: {
            items: 'id,f_user_telephone',
            tablename: 't_user',
            condition: `id  in  ('${str}')`,
            orderitem: 'id'
          }
        }, {resolveMsg: null, rejectMsg: null}).then((ress) => {
          res.data.forEach((user)=>{
            try {
              ress.data.forEach((tel,tidx,arr)=>{
                if(user.id==tel.id){
                  this.repairers.push({label: `${user.name}：${tel.f_user_telephone}`, value: user.name})
                  ress.data.splice(tidx,1)
                }
              })
            }catch (e) {
            }
          })
        }).catch(error=>{
          res.data.forEach((user)=>{
            this.repairers.push({label: user.name, value: user.name})
          })
        })

      })
    },
    deal(){
      if (!(this.solveModal.uploadData.filename && this.solveModal.uploadData.filename.length > 0)) {
        this.$showMessage('请录入处理后照片')
        return
      }
      this.upSolveDefect()
    },
    async upSolveDefect() {
      this.solveModal.uploadData.f_repairman = this.$login.f.name
      this.solveModal.uploadData.f_repair_date = Util.getNowDate()
      let res = await this.$resetpost('/rs/logic/pcRepairDefect', this.solveModal.uploadData, {resolveMsg: null, rejectMsg: null})
      if (res.data.code === 200) {
        this.$showMessage('操作成功')
      }else {
        this.$showMessage('网络异常')
      }
      this.showSolveModal = false
      this.$refs.paged.$refs.criteria.search()
      this.solveModal.uploadData={
        id: '',
        f_repairman: '',
        f_repair_date: '',
        f_repair_path: '',
        imgSrc: '',
        filename: '',
        f_defect_remark:''
      }
    },
    showDealModal(row){
      console.log('row=', JSON.stringify(row))
      this.check = row
      this.solveModal.preData.state = '未处理'
      this.solveModal.preData.defectImg = row.f_path ? '/rs/image/file/' + row.f_path : ''

      this.solveModal.preData.repairedImg = row.f_repair_path ? '/rs/image/file/' + row.f_repair_path : ''
      this.solveModal.uploadData.id = row.f_defect_id
      this.solveModal.uploadData.f_repairman = row.f_repairman
      this.solveModal.uploadData.f_repair_date = row.f_repair_date
      this.showSolveModal = !this.showSolveModal
    },
    cancel1(){
      this.showModal2=false
      this.selectData={
        dispatchType:'',
        f_repairman:'',
        f_remarks:'',
        f_repairtype:''
      }
    },
    async rectification(){
      if(this.selectData.dispatchType){
        if(this.selectData.dispatchType=='派发给站点'){
          if(!this.selectData.f_reciever){
            this.$showMessage('请选择部门！')
            return
          }
        }else{
          if(!this.selectData.f_repairman){
            this.$showMessage('请选择维修员！')
            return
          }
        }
      }else {
        this.$showMessage('请选择派发类型！')
        return
      }

      if(!this.selectData.f_repairtype){
        this.$showMessage('请选择报修类型！')
        return
      }
      this.showModal3=true
      let act={}
      let toRepair=''
      let successCount=0
      if(this.selectData.dispatchType=='派发给站点'){
        act={f_meetunit:this.selectData.f_meetunit,f_reciever:this.selectData.f_reciever,f_service_acitivity_type:'派单'}
        toRepair=null
      }else{
        console.log('派发给维修员---------'+this.selectData.f_repairman)
        act={f_meetunit:'',f_reciever:this.selectData.f_repairman,f_service_acitivity_type:'派单'}
        toRepair='一级派单'
      }
      let rep={
        loginUser: {
          name: this.$login.f.name,
          ename: this.$login.f.ename
        },
        f_meetunit: this.$login.f.deps,
        f_attendant: this.$login.f.name,
        f_outlets: this.$login.f.deps,
        f_remarks: this.selectData.f_remarks,
        f_repairtype: this.selectData.f_repairtype,
        toRepair: toRepair,
        activity:act
      }
      for(let i=0; i<this.dangerGroups.length; i++){
        let defectIdStr = ''
        const defectIds = []
        for (let j = 0; j < this.dangerGroups[i].dangers.length; j++) {
          defectIds.push(`'${this.dangerGroups[i].dangers[j].f_defect_id}'`)
        }
        defectIdStr = `(${defectIds.join(',')})`
        const data = {
          id:this.dangerGroups[i].dangers[0].f_paper_id,
          repData:rep,
          source:'pc',
          defectIdStr: defectIdStr
        }
        console.log('data=', JSON.stringify(data))
        try {
          let result =await new HttpResetClass().load('post','/rs/logic/phoneUploadRectification', data, {resolveMsg: null, rejectMsg: null})
          if (result.data.code==200) {
            successCount += result.data.successcon
            this.progressbarWidth=Math.ceil((i+1)*100/(this.dangerGroups.length))
          }
        }catch (e) {
          this.showModal3=false
          this.$showMessage('网络异常，请稍后再试！')
          return
        }
      }
      this.showModal3=false
      this.cancel1()
      this.refresh()
      this.$showMessage('本次转维修成功'+successCount+'单')
    },
    getSiteRes(obj) {
      if(obj.resids[0]){
        this.selectData.f_meetunit = obj.res.join('.')
        this.selectData.f_reciever = obj.resids.join('.')
        this.selectData.f_outlets = obj.res[obj.res.length - 1]
      }else {
        this.selectData.f_meetunit = ''
        this.selectData.f_reciever = ''
        this.selectData.f_outlets = ''
      }
    },
    toRepair(){
      console.log('this.checkes=', JSON.stringify(this.checkes))
      if(this.checkes.length==0){
        return this.$showMessage('请先选择需要转维修的隐患！')
      }
      const dangerGroups = []
      for (const danger of this.checkes) {
        let i = dangerGroups.findIndex(dangerGroup => dangerGroup.f_userinfo_code === danger.f_userinfo_code)
        if (i == -1){
          dangerGroups.push({
            f_userinfo_code: danger.f_userinfo_code,
            dangers: []
          })
          i = dangerGroups.length - 1
        }
        dangerGroups[i].dangers.push(danger)
      }
      this.dangerGroups = dangerGroups
      this.showModal2=true
    },
    isChecked(row) {
      return this.checkes.findIndex(item => item.f_defect_id == row.f_defect_id) != -1
    },
    setCheckes(row) {
      let index=this.checkes.findIndex(item => item.f_defect_id == row.f_defect_id)
      if(index<0){
        this.checkes.push(row)
      }else{
        this.checkes.splice(index,1)
      }
    },
    //隐患情况详情查看
    situation(row){
      //tag
      if (row.f_item_name === '气量异常差值'){
        this.$showMessage('气量异常差值无照片！！！')
      }else {
        this.yhpath=row
        //tag;
        //tag
        this.trouble=true
      }
    },
    details(row) {
      // Vue.$login = {jwt: row.f_checker_id}
      asyncReady(this).then(() => {
        ////tag)
        row.f_upload_state = '已传'
        this.isshowd=false
        this.$goto('new-check-paper', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self',this.isshowdtrue)
      }).catch(
        (respanse) => {
          alert('获取配置文件失败')
        })
    },
    isshowdtrue() {
      this.isshowd = true
    },
    showaudio(){
      //tag
      this.audioshow=!this.audioshow
      //tag
    },
    changeDefect(val){
      try {
        if(val){
          for (var Key1 in this.DefectConfig){
            if(Key1 == val){
              this.DefectConfigs = [{label:'全部',value:''}]
              for(var Key2 in this.DefectConfig[Key1].items){
                this.DefectConfigs.push({label:Key2,value:Key2})
              }
              if(Key1 == '燃气表'){
                this.DefectConfigs.push({label:'气量异常差值',value:'气量异常差值'})
                this.DefectConfigs.push({label:'金额异常差值',value:'金额异常差值'})
              }
              return
            }
          }
        }else if(val == ''){
          this.DefectConfigs = [{label:'全部',value:''}]
          for (var Key1 in this.DefectConfig){
            for(var Key2 in this.DefectConfig[Key1].items){
              this.DefectConfigs.push({label:Key2,value:Key2})
            }
          }
          this.DefectConfigs.push({label:'气量异常差值',value:'气量异常差值'})
          this.DefectConfigs.push({label:'金额异常差值',value:'金额异常差值'})
        }
      }catch (e) {
        //tag
      }
    },
    getDefectInfoConfig(val){
      try {
        if (val.safecheck.DevicesSetConfig != undefined) {
          this.DefectConfig = val.safecheck.DevicesConfig
          // 获取到配置项，进行遍历，获取每个隐患项
          for (var Key1 in this.DefectConfig){
            this.device_types.push({label:Key1,value:Key1})
            for(var Key2 in this.DefectConfig[Key1].items){
              this.DefectConfigs.push({label:Key2,value:Key2})
            }
          }
          // 非民用或其他配置项加入，在进行遍历
        }
      }catch (e) {
        //tag
      }
    },
    getmeterbook(val){
      this.cbc=[]
      this.cbc.push({
        label:'全部',
        value:''
      })
      if (val==''){

        this.cbcs.forEach(res=>{
          this.cbc.push({
            label:res.f_book_name,
            value:res.id
          })
        })
      }else{
        this.cbcs.forEach(res=>{
          if (res.f_book_slice_area==val){
            this.cbc.push({
              label:res.f_book_name,
              value:res.id
            })
          }
        })
      }
    },
    Mreadibook(val){
      ////tag
      ////tag
      this.sliceArea=[]
      if (val){
        new HttpResetClass().load('POST',`/rs/sql/safe_singleTable_OrderBy`, {data: {
            items: 'name',
            tablename: 't_zone',
            condition: `parentid  in ${val}`,
            orderitem: 'id'
          }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          this.sliceArea.push({
            label:'全部',
            value:''
          })
          res.data.forEach(ress=>{
            this.sliceArea.push({
              label:ress.name,
              value:ress.name
            })
          })

        })
      }
    },
    getAllMeterBook(val){
      ////tag
      ////tag
      this.cbcs=[]
      if (val){
        new HttpResetClass().load('POST',`/rs/sql/safe_singleTable_OrderBy`, {data: {
            items: 'f_book_name,f_book_slice_area,id',
            tablename: 't_meter_book',
            condition: `f_filiale_id  in ${val}`,
            orderitem: 'id'
          }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          res.data.forEach(ress=>{
            this.cbcs.push({
              id:ress.id,
              f_book_name:ress.f_book_name,
              f_book_slice_area:ress.f_book_slice_area
            })
          })
          this.cbc=[]
          this.cbc.push({
            label:'全部',
            value:''
          })
          this.cbcs.forEach(res=>{
            this.cbc.push({
              label:res.f_book_name,
              value:res.id
            })
          })
        })
      }
    },
    getRes(obj) {
      this.model.f_filialeid = this.$login.convertToIn(obj.resids);
      this.searchData.f_filialeid = this.$login.convertToIn(obj.resids);
      this.Mreadibook(this.model.f_filialeid)
      this.getAllMeterBook(this.model.f_filialeid)
      //this.$refs.paged.$refs.criteria.search()
    },
    readConfig() {
      let gen = asyncReady(this)
      return co(gen)
    },
    showChooser() {
      this.showModal = true
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    refresh() {
      this.$refs.paged.$refs.criteria.search()
    },
    ok() {
      this.showModal = false
      if (this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow.id) {
        this.model.f_plan_id = this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow.id
        this.model.f_check_plan=this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow
      }
    },
    cancel() {
      this.showModal = false
      this.model.f_check_plan = {f_plan_name: '', id: ''}
      this.model.f_plan_id=''
    },
    print(row) {
      this.showcheckmsg = true
      this.checkInfo = row
    },
    sort(field, rule) {
      // 将所有排序方式设为不排序，实现相互排斥
      for (let key in this.orderFields) {
        if (key === field) {
          this.orderFields[key] = rule
        } else {
          this.orderFields[key] = 'no'
        }
      }
      // 如果新规则不排序，还原为默认排序
      if (rule === 'no') {
        this.model.paramSource.orderitem = `'${this.orderDefault}'`
      } else {
        this.model.paramSource.orderitem = `'${field} ${rule}'`
      }
      this.search()
    },
    search() {
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch(args) {
      ////tag
      args.condition+=" and ditls.f_is_defect = 'true' "
      this.model.search(args.condition, args.model, args.condValue)
    }
  },
  ready() {
    ////tag
    this.getEmp()
    this.readConfig()
    this.function = this.f
    ////tag

    let gen = select(this)
    //this.pianqu()
    this.Mreadibook(`('${this.$login.f.orgid}')`)
    co(gen)
  },
  watch: {
    'model.f_no_checkplan'(val) {
      if (this.model.f_no_checkplan){
        this.searchData.f_no_checkplan = val
      }
      if (this.model.f_no_checkplan == '有计划安检') {

        this.showChooser()
      }
    },
    'model.condition'(val) {
      if (val) {
        this.searchData.condition = val
      }

    },
    'model.f_entry'(val) {
      if (val) {
        this.searchData.f_entry_status = val
      }
    },
    'model.f_plan_id'(val) {
      if (val) {
        this.searchData.f_plan_id = val
      }
    },
    'model.f_slice_area'(val) {
      if (val) {

      }
    },
    'model.f_approved'(val) {
      if (val) {
        this.searchData.f_approved = val
      }
    },
  }

}
</script>
