<template>
  <div class="flex">
    <work-busy :is-busy="isbusy"></work-busy>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria'  @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row" v-if="!$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">安检计划</label>
              <input type="text" class="input_search" v-model="$parent.$parent.f_check_plan.f_plan_name"
                     @click="$parent.$parent.showChooser"
                     style="width: 60%" placeholder="安检计划" readonly="readonly">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">存在隐患</label>
              <v-select style="width:60% "
                        class="select select_list"
                        :value.sync="model.f_has_defect"
                        v-model="model.f_has_defect"
                        :options='$parent.$parent.hasDefectOptions'
                        :placeholder='model.f_has_defect'
                        condition="f_has_defect = '{}'"
                        close-on-select>
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search" v-model="model.f_userinfo_code"
                     condition="f_userinfo_code = '{}'"
                     style="width: 60%" placeholder="用户编号">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">结果查询</label>
              <v-select
                placeholder='维修结果查询'
                :value-single="true"
                class="select select_list" style="width: 60%"
                v-model='model.f_is_repair'
                :value.sync="model.f_is_repair"
                :options='$parent.$parent.repaired'
                condition="f_is_repair  = '{}'"
                close-on-select clear-button> </v-select>
            </div>
            <div class=" col-sm-4 form-group button-range"  >
              <div class="span" style="float: right;margin-top: 8px">
                <div style="float: right" class="button_spacing"
                     :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                     @click="$parent.$parent.hiddenr()"></div>
                <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>
                <button style="float: right" class="button_search button_spacing" @click="search">查询</button>
                <button style="float: right" class="button_search button_spacing" @click="$parent.$parent.toRepair">转维修</button>
                <div style="float: right">
                  <export-excel-safe   :data="{condition: $parent.$parent.model.condition,f_filialeids:$parent.$parent.model.f_filialeids,f_defect_content:$parent.$parent.model.f_defect_content}"
                                      :field="$parent.$parent.getfield"
                                      sqlurl="rs/logic/SafeExportExcel" sql-name="GetCheckPaperByDefect" template-name='安检隐患明细' :choose-col="true"></export-excel-safe>
                </div>
              </div>
            </div>
          </div>
          <div class="row" v-if="$parent.$parent.criteriaShow&&!$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">片&emsp;&emsp;区</label>
              <v-select class="select_list select"
                        placeholder='片区/管理站' style="width: 60%"
                        :value.sync="model.f_slice_area" v-model="model.f_slice_area"
                        :options='$parent.$parent.sliceArea'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_slice_area='{}'"
                        @change="$parent.$parent.getmeterbook(model.f_slice_area)"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style2" 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="$parent.$parent.style">
              <label class="font_normal_body">抄&ensp;表&ensp;册</label>
              <v-select class="select_list select"
                        placeholder='抄表册' style="width: 60%"
                        :value.sync="model.f_meter_book_num" v-model="model.f_meter_book_num"
                        :options='$parent.$parent.cbc'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_meter_book_num={}"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">起始时间</label>
              <datepicker
                placeholder='起始时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                :value.sync="model.f_start_time"
                v-model="model.f_start_time"
                condition="f_offsite_time >= '{} 00:00:00'">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">结束时间</label>
              <datepicker
                placeholder='结束时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                :value.sync="model.f_end_time"
                v-model="model.f_end_time"
                condition="f_offsite_time <= '{} 23:59:59'">
              </datepicker>
            </div>


          </div>
          <div class="row" v-if="$parent.$parent.criteriaShow&&!$parent.$parent.$parent.showItem">

            <div :class="$parent.$parent.style">
              <label class="font_normal_body">维&ensp;修&ensp;员</label>
              <input type="text" class="input_search" v-model="model.f_repairman"
                     condition="f_repairman = '{}'"
                     style="width: 60%" placeholder="维修员">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">处理查询</label>
              <v-select
                placeholder='处理结果查询'
                :value-single="true"
                class="select select_list" style="width: 60%"
                v-model='model.f_is_deal'
                :value.sync="model.f_is_deal"
                :options='$parent.$parent.deals'
                condition="f_is_deal  = '{}'"
                close-on-select clear-button> </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">是否维修</label>
              <v-select
                placeholder='是否维修'
                :value-single="true"
                class="select select_list" style="width: 60%"
                v-model='model.f_repaired'
                :value.sync="model.f_repaired"
                :options='$parent.$parent.repairedOptions'
                condition="f_repaired  = '{}'"
                close-on-select clear-button> </v-select>
            </div>

          </div>



          <div class="row" v-if="$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">安检计划</label>
              <input type="text" class="input_search" v-model="$parent.$parent.f_check_plan.f_plan_name"
                     @click="$parent.$parent.showChooser"
                     style="width: 60%" placeholder="安检计划" readonly="readonly">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">存在隐患</label>
              <v-select style="width:60% "
                        class="select select_list"
                        :value.sync="model.f_has_defect"
                        v-model="model.f_has_defect"
                        :options='$parent.$parent.hasDefectOptions'
                        :placeholder='model.f_has_defect'
                        condition="f_has_defect = '{}'"
                        close-on-select>
              </v-select>
            </div>

            <div class=" col-sm-4 form-group button-range">
              <div class="span" style="float: right;margin-top: 8px;margin-right: 50px">
                <div style="float: right" class="button_spacing"
                     :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                     @click="$parent.$parent.hiddenr()"></div>
                <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>
                <button style="float: right" class="button_search button_spacing" @click="search">查询</button>
                <button style="float: right" class="button_search button_spacing" @click="$parent.$parent.toRepair">转维修</button>
                <div style="float: right">
                  <export-excel-safe   :data="{condition: $parent.$parent.model.condition,f_filialeids:$parent.$parent.model.f_filialeids}"
                                      :field="$parent.$parent.getfield"
                                      sqlurl="rs/logic/SafeExportExcel" sql-name="GetCheckPaperByDefect" template-name='安检计划明细' :choose-col="true"></export-excel-safe>
                </div>
              </div>
            </div>



          </div>
          <div class="row" v-if="$parent.$parent.criteriaShow&&$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search" v-model="model.f_userinfo_code"
                     condition="f_userinfo_code = '{}'"
                     style="width: 60%" placeholder="用户编号">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">结果查询</label>
              <v-select
                placeholder='处理结果查询'
                :value-single="true"
                class="select select_list" style="width: 60%"
                v-model='model.f_repaired'
                :value.sync="model.f_repaired"
                :options='$parent.$parent.repaired'
                condition="f_repaired  = '{}'"
                close-on-select clear-button> </v-select>
            </div>

            <div :class="$parent.$parent.style2" 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>
          <div class="row" v-if="$parent.$parent.criteriaShow && $parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">片&emsp;&emsp;区</label>
              <v-select class="select_list select"
                        placeholder='片区/管理站' style="width: 60%"
                        :value.sync="model.f_slice_area" v-model="model.f_slice_area"
                        :options='$parent.$parent.sliceArea'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_slice_area='{}'"
                        @change="$parent.$parent.getmeterbook(model.f_slice_area)"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">抄&ensp;表&ensp;册</label>
              <v-select class="select_list select"
                        placeholder='抄表册' style="width: 60%"
                        :value.sync="model.f_meter_book_num" v-model="model.f_meter_book_num"
                        :options='$parent.$parent.cbc'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_meter_book_num={}"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">起始时间</label>
              <datepicker
                placeholder='起始时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                :value.sync="model.f_start_time"
                v-model="model.f_start_time"
                condition="f_offsite_time >= '{} 00:00:00'">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">结束时间</label>
              <datepicker
                placeholder='结束时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                :value.sync="model.f_end_time"
                v-model="model.f_end_time"
                condition="f_offsite_time <= '{} 23:59:59'">
              </datepicker>
            </div>


          </div>
          <div class="row" v-if="$parent.$parent.criteriaShow && $parent.$parent.$parent.showItem">

            <div :class="$parent.$parent.style">
              <label class="font_normal_body">维&ensp;修&ensp;员</label>
              <input type="text" class="input_search" v-model="model.f_repairman"
                     condition="f_repairman = '{}'"
                     style="width: 60%" placeholder="维修员">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">处理查询</label>
              <v-select
                placeholder='处理结果查询'
                :value-single="true"
                class="select select_list" style="width: 60%"
                v-model='model.f_is_deal'
                :value.sync="model.f_is_deal"
                :options='$parent.$parent.deals'
                condition="f_is_deal  = '{}'"
                close-on-select clear-button> </v-select>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <template partial='head'>
          <tr>
            <!--            <th><nobr><input type="checkbox" v-model="$parent.$parent.$parent.checkAll" @click.stop="()=>{return}" />全选</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><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>
          </tr>
        </template>
        <template partial='body'>
          <!--          <td style="text-align: center;white-space:nowrap;"><input type="checkbox" @click="$event.cancelBubble=true" :checked="$parent.$parent.$parent.isChecked(row.id)" @change="$parent.$parent.$parent.setCheckes(row.id)"></input></td>-->
          <td style="text-align: center;white-space:nowrap;">{{row.f_entry_status}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_userinfo_code}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_user_name}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_user_phone}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_residential_area}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_address}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_offsite_time}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_checker_name}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_plan_name}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_has_defect}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_defect_count}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_deal_count}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_repair_count}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_is_deal}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_is_repair}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_repaired}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_repairman}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_defect_content}}</td>
          <td style="text-align: center;white-space:nowrap;">
            <button v-if="row.f_is_deal == '未处理' && row.f_is_repair != '已报备'" style="float: right" class="button_search button_spacing" @click="$parent.$parent.$parent.modal_show(row)">隐患处理</button>
          </td>
        </template>
      </data-grid>
    </criteria-paged>

    <modal :show.sync="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="this.$login.f" v-ref:chooser></plan-chooser>
      </div>
      <div slot="modal-footer" class="modal-footer" style="text-align: center">
        <button class="button_search" @click="ok">确认</button>
        <button class="button_search" @click="cancel">取消</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
                :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+'%'">
            <!--          <span class="sr-only">40% 完成</span>-->
          </div>
        </div>
      </div>
      <div slot="modal-footer" class="modal-footer" style="text-align: center" v-show="false"></div>
    </modal>
    <modal :show.sync="showUpload" v-ref:modal backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="close"><span class="glyphicon glyphicon-remove"></span></button>
        <h4 class="modal-title" style="text-align: center">文件上传</h4>
      </header>
      <article slot="modal-body" class="modal-body form-horizontal">
        <div class="form-group" style="text-align: center">
          <file-upload class="my-file-uploader" :name="'myFile' + blodid"
                       action="rs/file/uploadFile" tagname="文件上传" :headers="headers" multiple v-ref:file></file-upload>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button style="float: right" class="button_search button_spacing" :disabled="is_handle" @click="handle()">提交</button>
        <button style="float: right" class="button_search button_spacing" @click="close()">取消</button>
      </footer>
    </modal>
  </div>
</template>
<script>
import {PagedList} from 'vue-client'
import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
import co from 'co'
import Vue from 'vue'
import * as Util from '../../../components/Util'

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.name})
  })
}
export default {
  title: '隐患查询',
  data() {
    let model = new PagedList('rs/sql/GetCheckPaperByDefect', 20, {
      f_filialeids: 'this.f_filialeids',f_defect_content: 'this.f_defect_content'
    })
    model.f_filialeids = '(' + this.$login.f.orgid + ')'
    model.f_defect_content="CASE WHEN CHARINDEX( '\"result\":\"正常\"', f_defect_content ) > 0 THEN '无隐患' ELSE replace(replace(replace( replace( RIGHT ( f_defect_content, len( f_defect_content ) - 26 ), substring('{}',2,1), '' ), substring('{}',1,1), '' ),']',''),'\"','') END"
    return {
      is_handle:true,
      showUpload:false,
      row:{},
      headers: {
        'username': this.$login.f.name,
        'blodid': '',
        'businessid': '',
        'fremarks': '',
        'defname': '',
        'fusetype': ''
      }, // 调用rs/file/uploadFile 的参数
      blodid: '',
      repaired:[{label: '全部', value: ''},{label: '未完成', value: '未完成'}, {label: '已完成', value: '已完成'}],
      deals:[{label: '全部', value: ''},{label: '未处理', value: '未处理'}, {label: '已处理', value: '已处理'}, {label: '已报备', value: '已报备'}],
      hasDefectOptions: [{label: '全部', value: ''}, {label: '有隐患', value: '有隐患'}, {label: '无隐患', value: '无隐患'}],
      f: this.$login.f,
      model: model,
      criteriaShow: false,
      checkAll:false,
      timercount:0,
      showModal2:false,
      repairTypeOptions:this.$appdata.getParam('报修类型'),
      dispatchTypeOptions: [{label: '派发给维修员', value: '派发给维修员'}],
      checkes:[],
      showModal: false,
      f_check_plan: {f_plan_name: '', id: ''},
      sumsmodel: {},
      all: false,
      fields: {},

      selectData:{
        dispatchType:'',
        f_repairman:'',
        f_remarks:'',
        f_repairtype:''
      },
      progressbarWidth:'0',
      modelval: [],
      isbusy:false,
      checkersid: [],
      showModal3:false,
      toRepairCount:0,
      sliceArea: [],
      callSends:[],
      cbc:[],
      repairedOptions:[{label: '全部', value: ''},{label: '已修', value: '已修'}, {label: '未修', value: '未修'}],
      repairers:[],
      cbcs:[],
      thead: '',
      headData: ['入户状态','用户编号','用户名','用户电话','用户小区','用户地址','安检时间','安检员','计划名','是否有隐患','隐患数','隐患明细'],
      bodyData: ['f_entry_status','f_userinfo_code','f_user_name','f_user_phone','f_residential_area','f_address','f_offsite_time','f_checker_name','f_plan_name','f_has_defect','f_defect_count','f_defect_content'],
    }
  },
  props:{
    style: {
      type: String,
      default: 'col-sm-2 form-group'
    },
    style2: {
      type: String,
      default: 'col-sm-4 form-group'
    }

  },
  events:{
    onFileUpload: function (file, res) {
      this.row.f_handle_path = res.f_filename
      this.is_handle = false
    }
  },
  methods: {
    modal_show(row){
      this.row = row
      this.showUpload = true
      this.blodid = this.row.f_userinfo_id
      this.headers.blodid = this.row.f_userinfo_id
    },
    close() {
      this.is_handle =true
      this.showUpload = false
      this.blodid = ''
      this.headers.blodid = ''
      this.row = {}
    },
    handle(){
      this.row.f_repairman = this.$login.f.name
      this.row.f_repair_date = Util.getNowDate()
      new HttpResetClass().load('POST', '/rs/logic/handleDefectPC', {data:this.row}).then((res) => {
        this.$showMessage('操作成功')
        this.close()
    }).catch((err) => {
        this.$showMessage('操作失败')
        this.close()
      })
    },
    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/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)=>{
                //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
            }
          })
        })

      })
    },
    toRepair(){
      //tag
      this.showModal2=true
    },
    async rectification(){
      this.isbusy =true
      // if (this.checkAll){
      let data={
        f_filialeids: this.model.params.f_filialeids,
        f_defect_content: this.model.params.f_defect_content,
        condition:this.model.params.condition
      }
      let res1= await new HttpResetClass().load('post','rs/sql/GetCheckPaperByDefect',{data: data })
      let res2 = await new HttpResetClass().load('POST' , 'rs/sql/GetCheckPaperByDefectAllInfo' , {data: data } )
      for (let i = 0; i < res1.data.length; i++) {
        //tag
        let uploadData = {
          model: {
            serviceacitivity: [{
              f_service_acitivity_type: '派单'
            }],
            f_repairitems: {},
            failure: '',
            f_source: '安检',
            f_service_id: '',
            f_contact_phone: '',
            f_meetunit: '',
            f_phone: '',
            f_user_name: '',
            f_address: '',
            f_repair_date: '',
            f_reciever: '',
            f_remarks: '',
            f_user_type: '',
            f_area: '',
            f_unit_name: '',
            f_street: '',
            f_residential_area: '',
            f_building: '',
            f_unit: '',
            f_floor: '',
            f_room: '',
            aState: '',
            f_repairtype: '',
            f_userinfo_id: '',
            f_userinfo_code: '',
            f_orgstr: '',
            f_outlets: '',
            f_attendant: this.$login.f.name
          },
          loginUser: {
            name: this.$login.f.name,
            ename: this.$login.f.ename
          },
          user: {
            f_userinfo_id: ''
          },
          callObj: null
        }
        uploadData.model.serviceacitivity[0].f_reciever = this.selectData.f_repairman
        // uploadData.model.f_meetunit = self.$login.f.orgpathnames
        // uploadData.model.f_orgstr = self.$login.f.orgpathstr
        // uploadData.model.f_outlets = self.$login.f.f_parentname
        uploadData.model.f_meetunit = this.$login.f.deps
        uploadData.model.f_orgid = this.$login.f.orgid
        uploadData.model.f_filiale = this.$login.f.org
        uploadData.model.f_outlets = this.$login.f.deps
        uploadData.model.f_filiale_id = this.$login.f.orgid
        uploadData.toRepair = '一级派单'
        uploadData.model = Object.assign(uploadData.model, res1.data[i])
        uploadData.user.f_userinfo_id = res1.data[i].f_userinfo_id
        uploadData.model.f_repair_date = Util.getNowDate()
        uploadData.model.f_repairtype = '隐患处理'
        uploadData.model.f_remarks = null
        let failure = []
        res2.data.filter(item=>item.f_paper_id === res1.data[i].id).forEach(row => {
          if (row.f_repaire_type == '隐患未处理') {
            failure.push({
              f_failure_type: row.f_item_name,
              failurecase: row.f_item_value.split(',')
            })
          }
        })
        uploadData.model.failure = failure
        // 拼接repairitems
        let rows = JSON.parse(JSON.stringify(res2.data.filter(item=>item.f_paper_id === res1.data[i].id)))
        let repairitems = {
          data: []
        }
        let safecheckOptions = [{"data": "已处理"}, {"data": "未处理"}]
        // 取隐患未处理的
        rows = rows.filter(row => row.f_repaire_type == '隐患未处理')
        //tag)
        // 开始拼接
        rows.forEach(row => {
          let existIndex = -1
          // 判断该设备是否已经存在
          for (let i = 0; i < repairitems.data.length; i++) {
            if (repairitems.data[i].f_type == row.f_device_type) {
              existIndex = i
              break
            }
          }
          if (existIndex == -1) {
            // 不存在则新建
            let newItem = {
              f_type: row.f_device_type,
              details: [{
                f_defect_id: row.id,
                f_project: `${row.f_item_name}:${row.f_item_value}`,
                type: 'selector',
                options: safecheckOptions
              }]
            }
            repairitems.data.push(newItem)
          } else {
            // 存在则追加
            repairitems.data[existIndex].details.push({
              f_defect_id: row.id,
              f_project: `${row.f_item_name}:${row.f_item_value}`,
              type: 'selector',
              options: safecheckOptions
            })
          }
        })
        uploadData.model.f_repairitems = repairitems
        uploadData.rows=rows
        delete uploadData.model.id
        //tag)
        //tag
        if (uploadData.model.f_repairitems.data.length>0){
          this.callSends.push(uploadData)
        }else{
          //tag
        }
      }
      //tag)
      let timer = setInterval(async ()=>{
        this.showModal3=true
        this.isbusy=false
        if (this.timercount<this.callSends.length){
          //tag)
          let rows=this.callSends[this.timercount].rows
          //tag)
          let result = await this.$resetpost('/rs/logic/callerSend', this.callSends[this.timercount])
          //tag)
          if (result.data.f_service_id) {
            const data = {
              f_paper_id: rows[0].f_paper_id,
              f_service_id: result.data.f_service_id,
              itemsId: this.$login.convertToIn(rows.map(row => row.id))
            }
            //tag
            let updateRes = await this.$resetpost('/rs/logic/updateDefectState', data)
          }
          this.toRepairCount++
          //tag
          this.timercount++
        }else{
          clearInterval(timer)
          //tag
          this.callSends=[]
          this.timercount=0
          this.showModal3=false
          this.cancel1()
          this.$showMessage('本次转维修成功'+this.toRepairCount+'单')
          this.toRepairCount=0
        }
      }, 3000)
    },
    cancel1(){
      this.showModal2=false
      this.selectData={
        dispatchType:'',
        f_repairman:'',
        f_remarks:'',
        f_repairtype:''
      }
    },
    sleep(d){
      //tag)
      var t = Date.now()
      while(Date.now - t <= d){

      }
      //tag)
    },
    isChecked(v) {
      // 如果全选，不在的按选中算，否则，在的按选中算
      if (this.checkAll) {
        return this.checkes.indexOf(v) == -1
      } else {
        return this.checkes.indexOf(v) != -1
      }
    },
    setCheckAll() {
      this.checkAll=this.checkAll?false:true;
      // 全选改变后，清空选中数据
      this.checkes = []
    },
    setCheckes(id) {
      let index=this.checkes.indexOf(id)
      if(index<0){
        this.checkes.push(id)
      }else{
        this.checkes.splice(index,1)
      }
    },

    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/tel_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/tel_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
            })
          })
        })
      }
    },
    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    search(args) {
      //tag
      if (this.f_check_plan.f_plan_name) {
        args.condition += ` and f_check_plan_id = '${this.f_check_plan.id}'`
      }
      this.checkes = []
      this.checkAll=false
      this.model.search(args.condition, args.model)
    },
    getRes(obj) {
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
      this.Mreadibook(this.model.f_filialeids)
      this.getAllMeterBook(this.model.f_filialeids)
    },
    showChooser() {
      this.showModal = true
    },
    ok() {
      this.showModal = false
      if (this.$refs.modal.$children[0].selectedRow.id) {
        this.f_check_plan = this.$refs.modal.$children[0].selectedRow
      }
    },
    cancel() {
      this.showModal = false
      this.f_check_plan = {f_plan_name: '', id: ''}
    }
  },
  ready() {
    //tag
    this.$refs.paged.$refs.criteria.model.f_has_defect = '有隐患'
    this.getEmp()
    let gen = select(this)
    // this.Mreadibook(`('${this.$login.f.orgid}')`)
    co(gen)
  },
  watch:{
    'timercount'(){
      if (this.timercount===0){
        this.progressbarWidth = '0'
      }else {
        //tag
        //tag
        this.progressbarWidth=parseInt(this.timercount*100/(this.callSends.length+1))
      }

    }
  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    },
    getfield () {
      //tag
      let data = {}
      this.bodyData.forEach((value, index) => {
        data[this.bodyData[index]] = this.headData[index]
      })
      //合计字段打印
      this.tfoot = `<tr><th colspan=${this.modelval.length}>全表汇总信息: `
      if (this.sumsmodel) {
        Object.keys(this.sumsmodel).forEach((key) => {
          this.tfoot += this.fields[key] + '合计: ' + `<font color="blue">${this.sumsmodel[key]} </font>`
        })
      } else {
        this.tfoot += '暂无'
      }
      this.tfoot += '</th></tr>'
      return data
    }
  }
}
</script>
