<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_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-4" style="display: flex; gap: 15px">
                <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 class="button_search" @click="$parent.$parent.showaudio()" v-if="$parent.$parent.audioshow">隐藏</button>
                <button class="button_search"  @click="$parent.$parent.toRepair" v-if="$parent.$parent.canToRepair == '是'">转维修</button>
                <button class="button_search" @click="search()">查询</button>
                <div 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"
                :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%"
                          class="select_list select"
                          :options='$parent.$parent.device_types'
                          placeholder='检查项'
                          :multiple="true"
                          condition="f_device_type in {}"></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'
                          style="width: 60%"
                          class="select_list select"
                          :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
                  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
                  class="select_list select"
                  :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%"
                          class="select_list select"
                          :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>
                <v-select :value.sync="model.f_deal_dispose"
                          v-model='model.f_deal_dispose'
                          style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.deal_dispose' placeholder='请选择'
                          :multiple="true"
                          condition="f_deal_dispose in {}"></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">
                <label class="font_normal_body">隐患状态</label>
                <v-select :value.sync="model.f_is_repaired"
                          v-model='model.f_is_repaired'
                          style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.repairStateOptions' placeholder='请选择'
                          :multiple="true"
                          condition="f_is_repaired in {}"></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_repairman"
                       style="width: 60%" placeholder="处理人" condition="f_repairman = '{}'">
              </div>
              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <label for="startDate" class="font_normal_body">处理时间：</label>
                <datepicker id="startDate" placeholder="处理开始日期"
                            style="width: 60%!important;"
                            v-model="model.sq_startDate"
                            :value.sync="model.sq_startDate"
                            :format="'yyyy-MM-dd 00:00:00'"
                            :show-reset-button="true"
                            condition="f_repair_date >= '{}'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <label for="endDate" class="font_normal_body">处理时间：</label>
                <datepicker id="endDate" placeholder="处理结束日期"
                            style="width: 60%!important;"
                            v-model="model.sq_endDate"
                            :value.sync="model.sq_endDate"
                            :format="'yyyy-MM-dd 23:59:59'"
                            :show-reset-button="true"
                            condition="f_repair_date<= '{}'">
                </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_gasstart"
                  placeholder='开始时间' style="width: 60%"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="true"
                  v-model="model.f_check_gasstart"
                  condition="f_gas_date > ='{} 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_gasend"
                  placeholder='结束时间' style="width: 60%"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="true"
                  v-model="model.f_check_gasend"
                  condition="f_gas_date <=  '{} 23:59:59'">
                </datepicker>
              </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>
                <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>
              <th>
                <nobr>处理人</nobr>
              </th>
              <th>
                <nobr>处理方式</nobr>
              </th>
              <th>
                <nobr>处理时间</nobr>
              </th>
              <th>
                <nobr>工单编号</nobr>
              </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}}/{{row.f_item_value}}</td>
            <td style="text-align: center">{{row.f_defect_level}}</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_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="text-align: center">{{row.f_repairman}}</td>
            <td style="text-align: center">{{row.f_deal_dispose}}</td>
            <td style="text-align: center">{{row.f_repair_date}}</td>
            <td style="text-align: center">{{row.f_service_id}}</td>
            <td style="text-align: center">{{row.f_handlingtype}}</td>
            <td style="text-align: center">{{row.f_order_man}}</td>
          </template>
        </data-grid>
      </criteria-paged>
      <check-msg v-if="showcheckmsg" :show="showcheckmsg" :data="checkInfo"></check-msg>
      <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="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 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/defectDetails', 20,{
        f_filialeid: 'this.f_filialeid'
      })
      model.f_plan_id = ''
      model.f_approved = ''
      model.f_entry = ''
      model.f_no_checkplan = ''
      model.f_check_type=''
      model.f_filialeid = `('${this.$login.f.orgid}')`
      return {
        audioshow:false,

        model: model,
        deal_dispose:[{label:'全部',value:''},{label:'报修',value:'报修'},{label:'现场整改',value:'现场整改'},{label:'自行处理',value:'自行处理'},{label:'未处理',value:'未处理'},{label:'已处理',value:'已处理'}],
        repairStateOptions: this.getSafeParam('隐患状态'),
        //searchData:searchData,
        excelHeaders: {
          'f_device_type': '检查项',
          'f_item_name': '隐患名称',
          'f_item_value': '隐患值',
          'f_userinfo_code': '客户编号',
          'f_user_name': '客户姓名',
          'f_user_phone': '客户电话',
          'f_residential_area': '小区',
          'f_address': '客户地址',
          'f_offsite_time': '安检时间',
          'f_checker_name': '安检员',
          'f_deal_dispose': '处理方式',
          'f_is_repaired': '隐患状态',
          'f_repairman':'处理人',
          'f_repair_date':'处理时间'
        },
        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:[{label:'全部',value:''},{label: '金额异常差值', value: '金额异常差值'},{label: '气量异常差值', value: '气量异常差值'}],
        device_types:[{label:'全部',value:''}],
        f_check_type:[{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: []
      }
    },
    computed :{
      searchData() {
        return {condition: this.model.condition}
      }
    },
    methods: {
      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(){
        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
        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) => {
          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})
            })
          })

        })
      },
      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+'单')
      },
      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
              })
            })
          })
        }
      },
      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()
      },

      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()
      },
      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 f_filialeid in ${this.model.f_filialeid}`
        this.model.search(args.condition, args.model, args.condValue)
      }
    },

    ready() {
      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>
