<template>
    <div>
        <criteria-paged :model="model" v-ref:paged>
            <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:criteria>
                <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
                    <div class="row">
                        <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                            <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="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                            <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-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">用户类型</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="model.f_check_type"
                                  v-model="model.f_check_type"
                                  :options='$parent.$parent.userTypes'
                                  placeholder='用户类型'
                                  condition="f_check_type = '{}'"
                                  close-on-select>
                        </v-select>
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">用户地址</label>
                        <input type="text" class="input_search" v-model="model.f_address" id="f_address" style="width:60%;"
                               placeholder="用户地址" condition="f_address like '%{}%'">
                      </div>
                      <div :class="{'col-sm-6':$parent.$parent.$parent.showItem,'col-sm-4':!$parent.$parent.$parent.showItem}" style="float: right;padding-bottom:5px">
                        <div class="span" style="float: right;margin-top: 8px">
                          <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="GetCheckPaperByDefectToExcel" template-name='安检计划明细' :choose-col="true"></export-excel-safe>
                          <button class="button_search button_spacing" @click="$parent.$parent.showChooser1">转维修</button>
                          <button class="button_search button_spacing" @click="$parent.$parent.showChooser2">整改</button>
                          <button class="button_search button_spacing" @click="search">查询</button>
                          <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>
                        </div>
                      </div>
                      <!--<div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-3':!$parent.$parent.$parent.showItem}" v-if="!$parent.$parent.$parent.showItem">
                        <label class="font_normal_body">用户名称</label>
                        <input type="text" class="input_search" v-model="model.f_user_name" id="f_user_name" style="width:60%;"
                               placeholder="用户名称" condition="f_user_name like '{}%'">
                      </div>-->
                        <!--<div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-3':!$parent.$parent.$parent.showItem}" v-if="!$parent.$parent.$parent.showItem">
                            <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>
                   <!-- <div class="row">
                      <div :class="{'col-sm-7':$parent.$parent.$parent.showItem,'col-sm-7':!$parent.$parent.$parent.showItem}" style="float: right;padding-bottom:5px">
                        <div class="span" style="float: right;margin-top: 8px">
                          <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="GetCheckPaperByDefectToExcel" template-name='安检计划明细' :choose-col="true"></export-excel-safe>
                          <button class="button_search button_spacing" @click="$parent.$parent.showChooser1">转维修</button>
                          <button class="button_search button_spacing" @click="$parent.$parent.showChooser2">整改</button>
                          <button class="button_search button_spacing" @click="search">查询</button>
                          <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>
                        </div>
                      </div>
                    </div>-->
                    <div class="row" v-if="$parent.$parent.criteriaShow">
                      <div :class="{'col-sm-6':$parent.$parent.$parent.showItem,'col-sm-4':!$parent.$parent.$parent.showItem}">
                        <role-selector-safe
                          :left-width="'60%'"
                          :right-width="'60%'"
                          role-name="安检员"
                          role-lable="安&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="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                            <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="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                            <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 :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">隐患级别</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="$parent.$parent.defectLeave"
                                  v-model="$parent.$parent.defectLeave"
                                  :options='$parent.$parent.defectLeaveList'
                                  placeholder='隐患级别'
                                  condition="f_street = '{}'"
                                  close-on-select>
                        </v-select>
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">隐患类型</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="$parent.$parent.defectType"
                                  v-model="$parent.$parent.defectType"
                                  :options='$parent.$parent.getdefectType'
                                  placeholder='隐患类型'
                                  condition="f_street = '{}'"
                                  :multiple="true">
                        </v-select>
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">所属区域</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="model.f_street"
                                  v-model="model.f_street"
                                  :options='$parent.$parent.streets'
                                  placeholder='所属区域'
                                  condition="f_street = '{}'"
                                  close-on-select>
                        </v-select>
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">小&ensp;区&ensp;域</label>
                        <input type="text" class="input_search" v-model="model.f_small_area" id="f_small_area " style="width:60%;"
                               placeholder="小区域 " condition="f_small_area  like '%{}%'">
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">用户编号</label>
                        <input type="text" class="input_search" v-model="model.f_userinfo_code" id="f_userinfo_code" style="width:60%;"
                               placeholder="用户编号" condition="f_userinfo_code like '{}%'">
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">用户名称</label>
                        <input type="text" class="input_search" v-model="model.f_user_name" id="f_user_name" style="width:60%;"
                               placeholder="用户名称" condition="f_user_name like '{}%'">
                      </div>

                      <!--<div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-3':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">用户类型</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="model.f_check_type"
                                  v-model="model.f_check_type"
                                  :options='$parent.$parent.userTypes'
                                  placeholder='用户类型'
                                  condition="f_check_type = '{}'"
                                  close-on-select>
                        </v-select>
                      </div>-->
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">维修情况</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="model.f_repaired"
                                  v-model="model.f_repaired"
                                  :options='$parent.$parent.weixiuTypes'
                                  placeholder='维修情况'
                                  condition="{}"
                                  close-on-select>
                        </v-select>
                      </div>
                      <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
                        <label class="font_normal_body">整改情况</label>
                        <v-select style="width:60% "
                                  class="select select_list"
                                  :value.sync="model.f_rectificationed"
                                  v-model="model.f_rectificationed"
                                  :options='$parent.$parent.zhenggaicondition'
                                  placeholder='整改情况'
                                  condition="{}"
                                  close-on-select>
                        </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"/> 全选</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'><!-- @checked="isChecked(row.id)"  $parent.$parent.$parent.isChecked(row.id)-->
                  <td style="text-align: center;white-space:nowrap;"><input type="checkbox" onClick="event.cancelBubble = true" :checked="$parent.$parent.$parent.isChecked(row.id)"  @change="$parent.$parent.$parent.setCheckes(row.id)" /></td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_entry_status}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_user_name}}</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_defect_content.substring(26).replaceAll('{','').replaceAll('}','').replaceAll(']','').replaceAll('"','')}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_has_defect}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_repaired?row.f_repaired:(row.f_state ?row.f_state:(row.defname ?row.defname:'')) }}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_rectificationed ? row.f_rectificationed : ( row.f_is_repair == '已处理' ? '整改完成' : '' )}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_defect_count}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_fist_count}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_second_count}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_third_count}}</td>
                    <td style="text-align: center;white-space:nowrap;">{{row.f_other_count}}</td>
                </template>
              <template partial="foot">
                <td style="text-align: center"><span><b>合计：</b></span></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center"></td>
                <td style="text-align: center">{{model.sums.f_defect_count}}</td>
                <td style="text-align: center">{{model.sums.f_fist_count}}</td>
                <td style="text-align: center">{{model.sums.f_second_count}}</td>
                <td style="text-align: center">{{model.sums.f_third_count}}</td>
                <td style="text-align: center">{{model.sums.f_other_count}}</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="showModal1" >
        <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 for="f_repair" 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="faultCategory" :value-single="true" v-model="faultCategory"
                          :options='faultCategoryOption' placeholder='故障类型'
                          close-on-select>
                </v-select>
              </div>
            </div>
            <div class="row" style="margin-top: 10px">
              <label for="f_repair" 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="processingLevel" :value-single="true" v-model="processingLevel"
                          :options='processingLevelOption' placeholder='处理级别'
                          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="remarks"></textarea>
              </div>

            </div>

          </div>
        </div>
        <div slot="modal-footer" class="modal-footer" style="text-align: center">
          <button class="button_search" @click="ok1">确认</button>
          <button class="button_search" @click="cancel1">取消</button>
        </div>
      </modal>
      <modal :show.sync="showModal2">
        <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="rectify" :value-single="true" v-model="rectify"
                          :options='rectifys' placeholder='隐患整改员'
                          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">当前部门</label>
              <div class="col-xs-8 col-md-8">
                <input type="text" class="input_search" style="width: 60%;" v-model="department" disabled/>
              </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="cremarks"></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>
    </div>
</template>
<script>
  import {PagedList} from 'vue-client'
  import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
  import * as Util from '../Util'
  import {toStartDateString} from '../Util'

  export default {
    title: '隐患查询',
    data() {
      let model = new PagedList('rs/sql/GetCheckPaperByDefect', 20, {
        f_filialeids: 'this.f_filialeids',f_defect_content: 'this.f_defect_content'
      },{f_defect_count: '', f_fist_count: '', f_second_count: '',f_third_count: '',f_other_count:''})
      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 {
        hasDefectOptions: [{label: '全部', value: ''}, {label: '有隐患', value: '有隐患'}, {label: '无隐患', value: '无隐患'}],
        f: this.$login.f,
        model: model,
        criteriaShow: false,
        showModal: false,
        showModal1:false,
        showModal2:false,
        f_check_plan: {f_plan_name: '', id: ''},
        sumsmodel: {},
        all: false,
        fields: {},
        streets:[],
        zhenggaicondition:[{label:'全部',value:''},{label: '已派整改单', value: 'f_rectificationed=\'已派整改单\''}, {label: '整改完成', value: 'f_rectificationed=\'整改完成\''}, {label: '未派整改单', value: 'f_rectificationed is null and  f_is_repair != \'已处理\' '}],
        weixiuTypes:[{label:'全部',value:''},{label: '已派维修单', value: 'f_repaired=\'已派维修单\''}, {label: '维修完成', value: '(f_repaired=\'维修完成\' or defname = \'维修完成\' )'}, {label: '未派发维修', value: 'defname is null and f_repaired is null'},{label: '已处置', value: 'defname = \'已处置\' and f_repaired is null'}],
        modelval: [],
        defectType:[],
        userTypes:[{label: '民用', value: '民用'}, {label: '非民用', value: '非民用'}],
        defectLeave:'',
        defectLeaveList:[{label:'全部',value:''},{label:'一级隐患',value:'一级隐患'},{label:'二级隐患',value:'二级隐患'},{label:'三级隐患',value:'三级隐患'},{label: '其他隐患',value:'其他隐患'}],
        thead: '',
        headData: ['入户状态','用户名','用户电话','用户地址','安检时间','安检员','计划名','是否有隐患','隐患数','一级隐患数','一级隐患','二级隐患数','二级隐患','三级隐患数','三级隐患','其他隐患','隐患内容'],
        bodyData: ['f_entry_status','f_user_name','f_user_phone','f_address','f_offsite_time','f_checker_name','f_plan_name','f_has_defect','f_defect_count','f_fist_count','f_fist_content','f_second_count','f_second_content','f_third_count','f_third_content','f_other_count','f_defect_content'],
        checkAll:false,
        checkes:[],
        faultCategory:'安检隐患',
        processingLevel:"普通",
        department:this.$login.f.f_department_name,
        dep:[],
        faultCategoryOption:[{label: '民用', value: '民用'}, {label: '工商', value: '工商'}],
        processingLevelOption:[{label: '普通', value: '普通'}, {label: '加急', value: '加急'}, {label: '紧急', value: '紧急'}],
        remarks:"",
        cremarks:"",
        rectifys:[],
        rectify:''

      }
    },
    methods: {
      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)
        }
      },
      hiddenr() {
        this.$parent.showItem = !this.$parent.showItem
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      search(args) {
        if (this.f_check_plan.f_plan_name) {
          args.condition += ` and f_check_plan_id = '${this.f_check_plan.id}'`
        }
        if(this.defectLeave){
          if(this.defectLeave=='一级隐患'){
            args.condition += ` and f_fist_count > 0`
          }
          if(this.defectLeave=='二级隐患'){
            args.condition += ` and f_second_count > 0`
          }
          if(this.defectLeave=='三级隐患'){
            args.condition += ` and f_third_count > 0`
          }
          if(this.defectLeave=='其他隐患'){
            args.condition += ` and f_other_count > 0`
          }
        }
        if(this.defectType.length>0){
          args.condition += ` and (`
          for(let sqlstr=0;sqlstr<this.defectType.length;sqlstr++){
            //tag
            //tag
            args.condition += ` f_defect_content like '%${this.defectType[sqlstr]}%'`
            if(sqlstr<this.defectType.length-1){
              args.condition +=' or'
            }
          }
          args.condition += ` )`
        }
        /*if(this.defectType.length>0){
          for(let sqlstr in this.defectType){
            args.condition += ` and f_defect_content like '%${this.defectType[sqlstr]}%'`
          }
        }*/
        this.model.search(args.condition, args.model)
        this.checkAll=false;
        // 全选改变后，清空选中数据
        this.checkes = []
        //tag)
        //tag)
      },
      getRes(obj) {
        this.model.f_filialeids = this.$login.convertToIn(obj.resids);
        //tag
      },
      showChooser() {
        this.showModal = true
      },
      showChooser1() {
        this.showModal1 = true
      },
      showChooser2() {
        this.showModal2 = true
      },
      getYHZG(){
        new HttpResetClass().load('POST', '/rs/search', {
          source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($整改人员$) != -1))',
          userid: this.$login.f.id
        }, {resolveMsg: null, rejectMsg: null}).then((res)=>{
          //tag+"---id")
          res.data.forEach((resRow)=>{
            this.rectifys.push({label:resRow.name,value:resRow.name})
          })

        })

      },
      //进行整改
      rectification(){

        this.$showMessage('确定要整改当前选中用户吗？！', ['confirm', 'cancel']).then((msg)=>{
          if(msg=='confirm'){
            if (this.checkAll  ||  this.checkes.length>0) {
              this.$resetpost(`/rs/logic/UploadRectification`,
                {
                  condition:this.model.params.condition,
                  f_filialeids:this.model.params.f_filialeids,
                  switchCheckAll:true,
                  checkAll:this.checkAll,
                  param:this.checkes,
                  columnName:'id',
                  processingLevel:this.processingLevel,
                  faultCategory:this.faultCategory,
                  remarks:this.cremarks,
                  deps:this.$login.f.deps,
                  f_attendant: this.$login.f.name,
                  loginUser:{name:this.$login.f.name,ename:this.$login.f.ename},
                  repairman:this.rectify
                },{resolveMsg: null, rejectMsg: null}).then((res) => {
                if(res.data.code=200){
                  this.$showMessage('本次成功派发'+res.data.successcon+'个整改单！'+`其中${res.data.nohidden}个不需要隐患整改,${res.data.repeatCount}个已经派发过隐患整改单`)
                  this.checkAll=false;
                  // 全选改变后，清空选中数据
                  this.checkes = []
                }
              })
            }else{
              this.$showMessage("请勾选用户后进行整改！")
            }
          }
        })
      },
      ok() {
        //tag)
        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: ''}
      },
      ok1() {
        if (this.checkAll  ||  this.checkes.length>0) {
          this.$resetpost(`/rs/logic/SafeToRepair`,
            {
              condition:this.model.params.condition,
              f_filialeids:this.model.params.f_filialeids,
              switchCheckAll:true,
              checkAll:this.checkAll,
              param:this.checkes,
              columnName:'id',
              processingLevel:this.processingLevel,
              faultCategory:this.faultCategory,
              remarks:this.remarks
            },{resolveMsg: null, rejectMsg: null}).then((res) => {
              if(res.data.code=200){
                this.$showMessage("本次成功派发"+res.data.successcon+"个维修单！"+`其中${res.data.nohidden}个不需要维修,${res.data.repeatCount}个已经派发过维修`)
                this.checkAll=val;
                // 全选改变后，清空选中数据
                this.checkes = []
              }
               })
        }else{
          this.$showMessage("请勾选隐患进行转维修！")
        }
        this.showModal1 = false
      },
      cancel1() {
        this.showModal1 = false
        this.showModal2 = false
      },
      async initstreets(){
        this.streetslist = []
        let HttpReset = new HttpResetClass()
        let req = await HttpReset.load('POST', 'rs/sql/address_singleTableOrderBy', {
          data: {
            items: '*',
            tablename: 't_street',
            orderitem: 'id',
            condition: `f_orgid = '${this.$login.f.orgid}'`
          }
        }, {resolveMsg: null, rejectMsg: '获取地址失败!'})
        let redata = []
        req.data.forEach((row, n) => {
          redata[n] = {
            label: row.f_street,
            value: row.f_street,
            data:row,
            id:row.id
          }
        })
        this.streets=redata
      }
    },
    ready() {
      //tag)
      this.$refs.paged.$refs.criteria.model.f_has_defect = '有隐患'
      this.$refs.paged.$refs.criteria.model.f_start_time = Util.toStartDateString()
      this.initstreets()
      this.getYHZG()
    },
    watch:{
      'checkAll'(val){
        this.checkAll=val;
        // 全选改变后，清空选中数据
        this.checkes = []
      },
      'model.rows.length'() {
        //tag
        // 如果查询无结果，将合计置为0
        if(this.model.rows.length < 1){
          this.model.sums.f_defect_count = 0
          this.model.sums.f_fist_count = 0
          this.model.sums.f_second_count = 0
          this.model.sums.f_third_count = 0
        }
      }
    },
    computed: {
      getdefectType(){
          this.defectType=[]
          return [... this.$appdata.getParam(this.defectLeave)]
      },
      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>
