<template>
  <div class="flex-row">
    <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_id"
                       style="width: 60%" placeholder="客户编号" condition="f_userinfo_id='{}'">
              </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">是否处理</label>
                <v-select :value.sync="model.f_is_repaired" v-model='model.f_is_repaired'
                          :value-single="true" style="width: 60%"
                          :options='$parent.$parent.dealOptions' placeholder='请选择'
                          close-on-select
                          condition="f_is_repaired = '{}'"></v-select>
              </div>
              <div class="form-group col-sm-2" style="width: auto;margin-top:8px;float: right">
                <export-excel-safe :data="$parent.$parent.searchData"
                              :field="$parent.$parent.excelHeaders"
                              progress="safeGetExportProgress"
                              sqlurl="rs/logic/SafeExportExcel" sql-name="defectDetails" template-name='隐患处置'></export-excel-safe>
                <button style="margin-left: 4px" class="button_search button_spacing" @click="$parent.$parent.showaudio()" v-if="$parent.$parent.audioshow">隐藏</button>
                <button style="margin-left: 4px" class="button_search button_spacing"  @click="$parent.$parent.toRepair" v-if="$parent.$parent.canToRepair == '是'">转维修</button>
                <button style="margin-left: 4px" class="button_search button_spacing" @click="search()">查询</button>
                <div
                     :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="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <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="col-sm-4 form-group" style="margin: 0" v-show="$parent.$parent.criteriaShow">
                <role-selector-safe
                  role-name="新安检员"
                  role-lable="安&nbsp;检&nbsp;员&nbsp;"
                  :value.sync="model.f_checker_id"
                  v-model="model.f_checker_id"
                  :value-multiple="true"
                  :value-close="false"
                  condition="f_checker_name in {}">
                </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"
                          style="width: 60%"
                          :options='$parent.$parent.device_types'
                          placeholder='检查项'
                          :multiple="true"
                          condition="f_device_type in {}"></v-select>
              </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'
                          style="width: 60%"
                          :options='$parent.$parent.DefectConfigs'
                          placeholder='隐患名称'
                          :multiple="true"
                          condition="f_item_name in {}"></v-select>
              </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_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_check_type" v-model='model.f_check_type'
                          :value-single="true" style="width: 60%"
                          :options='$parent.$parent.f_check_type' placeholder='请选择'
                          close-on-select
                          condition="f_check_type = '{}'"></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_address"
                       style="width: 60%" placeholder="详细地址" condition="f_address like '%{}%'">
              </div>
              <div class="form-group col-sm-2"   v-show="$parent.$parent.criteriaShow">
                <dep-selector
                  :value.sync="model.parentid"
                  v-model="model.parentid"
                  condition="parentid in {}">
                </dep-selector>
              </div>
            </div>
          </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>
                <data-order field="f_offsite_time" name="安检时间"></data-order>
              </th>
              <th>
                <nobr>安检员</nobr>
              </th>
              <th>
                <nobr>是否处理</nobr>
              </th>
              <th style="width: 188px">
                <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}}/{{row.f_item_value}}</td>
            <td style="text-align: center">{{row.f_defect_level}}</td>
            <td style="text-align: center">{{row.f_userinfo_id}}</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_check_type}}</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">{{row.f_is_repaired}}</td>
            <td style="" v-if="row.f_is_repaired == '未处理'">
              <datepicker
                :value.sync="row.f_handle_date"
                placeholder='到期时间' style="width: 60%; position: static"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="row.f_handle_date">
              </datepicker>
              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.a(row)'>修改</button>
            </td>
            <td style="text-align: center" v-if="row.f_is_repaired == '已处理' || row.f_is_repaired == '转维修'">
              {{row.f_handle_date}}
            </td>
            <td style="text-align: center">
              <button style="margin-bottom: 5px" class="button_spacing button_search-1" @click='$parent.$parent.$parent.showDealModal(row)'>{{row.f_is_repaired == '未处理' ? '处理' : '查看'}}</button>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
      <check-msg v-if="showcheckmsg" :show="showcheckmsg" :data="checkInfo"></check-msg>
      <modal :show.sync="showSolveModal" v-ref:solveModal width="750px">
        <div slot="modal-header" class="modal-header">
          <h4 class="modal-title">
            {{solveModal.preData.state == '已处理' ? '查看隐患' : '处理隐患'}}
          </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>
            <img-self-plus v-if="solveModal.preData.defectImg1" :width="200" :height="200" :src="solveModal.preData.defectImg1"></img-self-plus>
            <img-self-plus v-if="solveModal.preData.defectImg2" :width="200" :height="200" :src="solveModal.preData.defectImg2"></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 class="col-sm-6" style="margin-top: 10px" v-if="solveModal.preData.state == '已处理'">
            <label class="font_normal_body">处&nbsp;理&nbsp;人</label>
            <input class="input_search" style="width: 60%" disabled="true" type="text" v-model="solveModal.uploadData.f_repairman" placeholder="处理人">
            <v-select
              v-if="solveModal.preData.type == 'solve'"
              :value.sync="solveModal.uploadData.f_repairman"
              :value-single="true"
              :options='toRepairModal.preData.repairers'
              placeholder='请选择维修员'
              close-on-select></v-select>
          </div>
          <div class="col-sm-6" style="margin-top: 10px" v-if="solveModal.preData.state == '已处理'">
            <label class="font_normal_body">处理时间</label>
            <datepicker
              :disabled="true"
              placeholder='处理时间' style="width:60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd'"
              :show-rest-button="reset"
              :value.sync="solveModal.uploadData.f_repair_date">
            </datepicker>
          </div>
          <div v-if="solveModal.preData.state == '未处理'" class="col-sm-12" style="margin-bottom: 10px">
            <label class="font_normal_body">处理后图片</label>
            <safecheck-file-upload
              :issearch="false"
              :isupload="Upload"
              :blodid="check.f_defect_id"
              :isdelete="true"
              flag="safeCheck"
              @filename="getfile"
            ></safecheck-file-upload>
          </div>
          <div v-if="solveModal.preData.state == '已处理'" class="col-sm-12" style="margin-bottom: 10px">
            <p> <label class="font_normal_body">处理后图片</label></p>
            <P></P>
            <div class="col-sm-12">
              <div class="col-sm-6" v-if="solveModal.preData.repairedImg">
                <img-self-plus :width="200" :height="200" :src="solveModal.preData.repairedImg" style="margin-left: 10px"></img-self-plus>
              </div>
              <div class="col-sm-6" v-if="solveModal.preData.repairedImg1">
                <img-self-plus :width="200" :height="200" :src="solveModal.preData.repairedImg1"  style="margin-left: 10px"></img-self-plus>
              </div>
              <div class="col-sm-6" v-if="solveModal.preData.repairedImg2">
                <img-self-plus :width="200" :height="200" :src="solveModal.preData.repairedImg2"  style="margin-left: 10px"></img-self-plus>
              </div>
            </div>
          </div>
        </div>
        <div slot="modal-footer" class="modal-footer" style="text-align: center">
          <button class="button_search" v-if="checkDefect=='是' && solveModal.preData.type == 'view'" @click="auditsure('通过')" v-if="solveModal.preData.type == 'view' && !solveModal.f_audit_results">审核通过</button>
          <button class="button_search" v-if="checkDefect=='是' && solveModal.preData.type == 'view'" @click="auditsure('不通过')" v-if="solveModal.preData.type == 'view' && !solveModal.f_audit_results">审核不通过</button>
          <button class="button_search" v-if="solveModal.preData.state == '未处理'" @click="ok">确认</button>
          <button class="button_search" @click="cancel">取消</button>
          <button class="button_search" v-if="solveModal.preData.state == '未处理'" @click="toRepair(check)">转维修</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>

            </div>
            <!--            <div v-for="(index, item) in dangerGroup">-->

            <!--            </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.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
                  :userid="userid"
                  :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="$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>
      <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>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import Vue from 'vue'
  import co from 'co'
  import * as Util from '../../Util'
  import HttpResetClass from "vue-client/src/plugins/HttpResetClass";

  //获取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: 'tool.getChildrenOfResName($新安检员$)',
      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/DefectDetailsYC', 20,{
      })
      model.f_plan_id = ''
      model.f_approved = ''
      model.f_entry = ''
      model.f_no_checkplan = ''
      model.f_check_type=''
      return {
        audioshow:false,
        Upload:true,
        model: model,
        deal_dispose:[{label:'全部',value:''},{label:'报修',value:'报修'},{label:'现场整改',value:'现场整改'},{label:'自行处理',value:'自行处理'},{label:'未处理',value:'未处理'}],
        repairStateOptions: [{label:'全部',value:''}, {label:'转维修',value:'转维修'}, {label:'维修已处理',value:'维修已处理'}, {label: '隐患未处理', value: '隐患未处理'}, {label:'现场已处理',value:'现场已处理'}, {label:'用户自行整改',value:'用户自行整改'}],
        //searchData:searchData,
        excelHeaders: {
          'f_device_type': '检查项',
          'f_item_name': '隐患名称',
          'f_item_value': '隐患内容',
          'f_defect_level': '隐患级别',
          'f_userinfo_id': '客户编号',
          'f_user_name': '客户姓名',
          'f_user_phone': '客户电话',
          'f_check_type': '客户类型',
          'f_residential_area': '客户小区',
          'f_address': '客户地址',
          'f_offsite_time': '安检时间',
          'f_checker_name': '安检员',
        },
        fun: this.$login.f,
        checkersid: [],
        safetype: this.getSafeParam('安检类型'),
        criteriaShow: false,
        showModal: false,
        f_approval_states: this.getSafeParam('安检单审核状态'),
        f_entry_status:this.getSafeParam('安检状态'),
        f_checkplans: this.getSafeParam('有无计划'),
        showcheckmsg: false,
        checkInfo: {},
        orderDefault: "'f_offsite_time'",
        orderFields: {
          f_offsite_time: 'no'
        },
        sliceArea: [],
        cbc:[],
        DefectConfig:'' ,
        DefectConfigs:[],
        device_types:[],
        f_check_type: [{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
        dealOptions: [{label:'全部',value:''},{label:'已处理',value:'已处理'},{label:'未处理',value:'未处理'},{label:'转维修',value:'转维修'}],
        showModal2: false,
        selectData:{
          dispatchType:'',
          f_repairman:'',
          f_remarks:'',
          f_repairtype:''
        },
        repairers: [],
        repairTypeOptions:this.$appdata.getParam('报修类型'),
        dispatchTypeOptions: [{label: '派发给站点', value: '派发给站点'},{label: '派发给维修员', value: '派发给维修员'}],
        dangerGroups: [],
        showModal3: false,
        progressbarWidth:'0',
        canToRepair: this.$appdata.getSingleValue('隐患明细转维修'),
        checkes: [],
        solveModal: {
          preData: {
            type: '',
            defectImg: '',
            defectImg1: '',
            defectImg2: '',
            repairedImg: '',
            repairedImg1: '',
            repairedImg2: '',
            state: ''
          },
          uploadData: {
            id: '',
            f_repairman: this.$login.f.name,
            f_repair_date: Util.getNowDate(),
            f_repair_path: '',
            imgSrc: '',
            filename: ''
          }
        },
        showSolveModal: false,
        check: null
      }
    },
    computed :{
      searchData() {
        return {condition: this.model.condition}
      }
    },
    methods: {
      getfile(res){
        this.solveModal.uploadData.filename=res.f_filename
        this.Upload=false
      },
      async getDefectOption() {
        let res = await new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_GroupBy`, {
          data: {
            items: "pd.f_device_type",
            tablename: "t_paper_devices pd left join t_devices_items di on pd.id = di.f_device_id",
            groupitem: "pd.f_device_type",
            condition: `di.f_is_defect = 'true' and di.f_is_repaired is null`
          }
        }, {resolveMsg: null, rejectMsg: null})
        const device_types = [{label: '全部', value: ''}]
        res.data.forEach((item) => {
          device_types.push({label: item.f_device_type, value: item.f_device_type})
        })
        this.device_types = device_types
        res = await new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_GroupBy`, {
          data: {
            items: "di.f_item_name",
            tablename: "t_paper_devices pd left join t_devices_items di on pd.id = di.f_device_id",
            groupitem: "di.f_item_name",
            condition: `di.f_is_defect = 'true' and di.f_is_repaired is null`
          }
        }, {resolveMsg: null, rejectMsg: null})
        const DefectConfigs = [{label: '全部', value: ''}]
        res.data.forEach((item) => {
          DefectConfigs.push({label: item.f_item_name, value: item.f_item_name})
        })
        this.DefectConfigs = DefectConfigs
      },
      async a(row) {
        console.log('row=', JSON.stringify(row))
        let res = await this.$showMessage('确认修改到期时间吗？', ['confirm', 'cancel'])
        if (res == 'confirm'){
          await new HttpResetClass().http('post', '/rs/logic/updateDefectTime', {
            defect: {
              f_defect_id: row.f_defect_id,
              f_handle_date: row.f_handle_date
            },
            user: {
              name: this.$login.f.name,
              id: this.$login.f.id,
            }
          })
          this.$refs.paged.$refs.criteria.search()
          this.$showMessage('修改成功')
        }
      },
      async upSolveDefect() {
        console.log('this.solveModal.uploadData=', JSON.stringify(this.solveModal.uploadData))
        this.solveModal.uploadData.f_repairman = this.$login.f.name
        this.solveModal.uploadData.f_repair_date = Util.getNowDate()
        let res = await this.$resetpost('/rs/logic/pcRepairDefectNew', 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:''
        }
        this.Upload=true
      },
      ok() {
        if (!(this.solveModal.uploadData.filename && this.solveModal.uploadData.filename.length > 0)) {
          this.$showMessage('请录入处理后照片')
          return
        }
        this.upSolveDefect()
      },
      cancel() {
        this.showSolveModal = false
        this.Upload=true
      },
      showDealModal(row){
        console.log('row=', JSON.stringify(row))
        this.check = row
        this.solveModal.preData.state = (row.f_is_repaired == '未处理' ? '未处理' : '已处理')
        this.solveModal.preData.defectImg = row.f_path ? '/rs/image/file/' + row.f_path : ''
        this.solveModal.preData.defectImg1 = row.f_p1_path ? '/rs/image/file/' + row.f_p1_path : ''
        this.solveModal.preData.defectImg2 = row.f_p2_path ? '/rs/image/file/' + row.f_p2_path : ''
        this.solveModal.preData.repairedImg = row.f_repair_path ? '/rs/image/file/' + row.f_repair_path : ''
        this.solveModal.preData.repairedImg1 = row.f_repair1_path ? '/rs/image/file/' + row.f_repair1_path : ''
        this.solveModal.preData.repairedImg2 = row.f_repair2_path ? '/rs/image/file/' + row.f_repair2_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
        console.log('this.solveModal=', JSON.stringify(this.solveModal))
      },
      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)
        }
        console.log('this.checkes=', JSON.stringify(this.checkes))
      },
      toRepair(check){
        this.Upload=true
        console.log('this.checkes=', JSON.stringify(this.checkes))
        let checkes = []
        if (check){
          checkes.push(check)
        }else {
          checkes = this.checkes
        }
        if(checkes.length==0){
          return this.$showMessage('请先选择需要转维修的隐患！')
        }

        const dangerGroups = []
        for (const danger of checkes) {
          let i = dangerGroups.findIndex(dangerGroup => dangerGroup.f_userinfo_id === danger.f_userinfo_id)
          if (i == -1){
            dangerGroups.push({
              f_userinfo_id: danger.f_userinfo_id,
              dangers: []
            })
            i = dangerGroups.length - 1
          }
          dangerGroups[i].dangers.push(danger)
        }
        this.dangerGroups = dangerGroups
        console.log('this.dangerGroups=', JSON.stringify(this.dangerGroups))
        this.showModal2=true
      },
      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) => {
          let str=''
          res.data.forEach((item,idx,arr) => {
            //tag
            if(idx+1==arr.length){
              str += `'${item.id}'`
            }else{
              str += `'${item.id}',`
            }

          })
          let http1 = new HttpResetClass()
          http1.load('POST', 'rs/sql/safe_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)=>{
                  //tag
                  if(user.id==tel.id){
                    this.repairers.push({label: `${user.name}：${tel.f_user_telephone}`, value: user.name})
                    ress.data.splice(tidx,1)
                    //tag
                    throw new Error("跳出循环");
                  }
                })
              }catch (e) {
                //tag
              }
            })
          })

        })
      },
      getSiteRes(obj) {
        console.log('siteRes ---> ')
        console.log(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 = ''
        }
      },
      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.$showMessage('本次转维修成功'+successCount+'单')
        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:''
        }
      },
      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
        }
      },
      showaudio(){
        //tag
        this.audioshow=!this.audioshow
        //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
              })
            }
          })
        }
      },
      getSafeParam(val){
        if(this.$appdata.getParam(val)){
          return [{label: '全部', value: ''}, ...this.$appdata.getParam(val)]
        }else{
          return [{label: '全部', value: ''}]
        }

      },
      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
              })
            })
          })
        }
      },
      change(row) {
        // Vue.$login = {jwt: row.f_checker_id}
        // asyncReady(this).then(() => {
        //     ////tag)
        //     row.f_upload_state = '已传'
        //     this.$goto('new-check-paper', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
        // }).catch(
        //   (respanse) => {
        //     alert('获取配置文件失败')
        //   })
      },
      readConfig() {
        let gen = asyncReady(this)
        return co(gen)
      },
      showChooser() {
        this.showModal = true
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      refresh() {
        this.$refs.paged.$refs.criteria.search()
      },
      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 f_is_repaired = '未处理'`
        this.model.search(args.condition, args.model, args.condValue)
      }
    },

    ready() {
      // this.$refs.paged.$refs.criteria.model.f_check_start = Util.toStartDateString()
      this.getDefectOption()
      this.getEmp()
      // this.readConfig()
      ////tag
      this.function = this.f
      ////tag

      let gen = select(this)
      //this.pianqu()
      this.Mreadibook(`('${this.$login.f.orgid}')`)
      co(gen)
    }
  }
</script>
