<template>
  <div style="flex:1;" class="flex">
    <button class="btn btn-xs" v-show="!criteriaShow" @click="show()" >
      <span class="glyphicon glyphicon-chevron-down" style="color: #000;"></span>
    </button>
    <criteria-paged :model="model"  v-ref:paged  @sort="sort">
      <criteria partial='criteria' v-show="$parent.criteriaShow" @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-4" style="width: 20%">
              <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-4" style="width: 20%">
              <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-4" style="width: 20%">
              <label class="font_normal_body"> &nbsp;&nbsp;&nbsp;小区&nbsp;&nbsp;&nbsp;</label>
              <input type="text" class="input_search" v-model="model.f_residential_area" id="f_residential_area" style="width:60%;"
                     placeholder="小区" condition="f_residential_area like '%{}%'">
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body"> &nbsp;&nbsp;&nbsp;地址&nbsp;&nbsp;&nbsp;</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-4" style="width: 20%">
              <label class="font_normal_body">所属区域</label>
              <v-select
                placeholder='所属区域'
                :value-single="true"
                v-model='model.street'
                :value.sync="model.street"
                class="select select_list"
                :options='$parent.$parent.streets'
                condition="f_street ='{}'"
                close-on-select clear-button> </v-select>
            </div>
            <!--<div class="col-sm-3 form-group form-input-group" style="width: 20%">-->
            <!--<label class="control-label">用户类型</label>-->
            <!--<v-select id="f_usertype"-->
            <!--placeholder='用户类型'-->
            <!--:value.sync="model.f_usertype"-->
            <!--:value-single="true"-->
            <!--:options='$parent.$parent.usertypes'-->
            <!--v-model="model.f_usertype"-->
            <!--condition="f_user_type = '{}'"-->
            <!--close-on-select clear-button> </v-select>-->
            <!--</div>-->
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body" style="color: red;">安检筛选</label>
              <v-select
                placeholder='安检筛选'
                :value-single="true"
                class="select select_list"
                :value.sync="$parent.$parent.SafeCheckXZ"
                :options='$parent.$parent.SafeCheckXZs'
                v-model="$parent.$parent.SafeCheckXZ"
                close-on-select clear-button> </v-select>
            </div>
            <div class="col-sm-4" style="width: 20% " v-show="$parent.$parent.SafeCheckXZ=='未入户'">
              <label class="font_normal_body">安检状态</label>
              <v-select id="f_entry"
                        placeholder='安检状态'
                        :value.sync="model.f_check_state"
                        :value-single="true"
                        class="select select_list"
                        :options='$parent.$parent.checkstatus'
                        v-model="model.f_check_state"
                        close-on-select clear-button> </v-select>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">安检起始</label>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='最后安检时间起始'
                :disabled-days-of-week="[]"
                class="select select_list"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "model.f_check_start">
              </datepicker>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">安检结束</label>
              <datepicker
                :value.sync="model.f_check_end"
                placeholder='最后安检时间结束'
                :disabled-days-of-week="[]"
                class="select select_list"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "model.f_check_end">
              </datepicker>
            </div>

            <!--<div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">安检状态</label>
              <v-select id="f_entry"
                        placeholder='安检状态'
                        :value.sync="model.f_last_check_state"
                        :value-single="true"
                        class="select select_list"
                        :options='$parent.$parent.checkstatus'
                        v-model="model.f_last_check_state"
                        condition="f_last_check_state = '{}'"
                        close-on-select clear-button> </v-select>
            </div>-->
            <div  class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">隐患情况</label>
              <v-select
                placeholder='隐患情况'
                :value-single="true"
                v-model='model.f_check_result'
                class="select select_list"
                :value.sync="model.f_check_result"
                :options='$parent.$parent.f_check_results'
                condition="f_last_check_result  like '%{}%'"
                close-on-select clear-button> </v-select>
            </div>
            <!--<div  class="col-sm-4" style="width: 20%" v-if="$parent.$parent.orgstrs.length > 1">
              <label class="font_normal_body">县域公司</label>
              <v-select
                placeholder='县域分公司'
                :value-single="true"
                v-model='model.f_orgstr'
                :value.sync="model.f_orgstr"
                class="select select_list"
                :options='$parent.$parent.orgstrs'
                condition="f_orgstr like '%{}%'"
                close-on-select clear-button> </v-select>
            </div>-->

            <div class="row">
              <div class="col-sm-4" style="width: 20%">
                <label class="font_normal_body">开户起始</label>
                <datepicker
                  :value.sync="model.f_createfile_start"
                  placeholder='开户起始时间'
                  :disabled-days-of-week="[]"
                  class="select select_list"
                  style="width: 60%"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  condition="f_createfile_date > '{} 00:00:00'"
                  v-model = "model.f_createfile_start">
                </datepicker>
              </div>
              <div class="col-sm-4" style="width: 20%">
                <label class="font_normal_body">开户结束</label>
                <datepicker
                  :value.sync="model.f_createfile_end"
                  placeholder='开户结束时间'
                  :disabled-days-of-week="[]"
                  class="select select_list"
                  style="width: 60%"
                  :format="'yyyy-MM-dd'"
                  condition="f_createfile_date < '{} 23:59:00'"
                  :show-rest-button="reset"
                  v-model = "model.f_createfile_end">
                </datepicker>
              </div>
              <div class="col-sm-4" style="width: 20%">
                <label class="font_normal_body">是否入户</label>
                <v-select
                  placeholder='今年是否入户'
                  :value-single="true"
                  class="select select_list"
                  :value.sync="$parent.$parent.hasHousehold"
                  :options='$parent.$parent.safe_rhs'
                  v-model="$parent.$parent.hasHousehold"
                  close-on-select clear-button> </v-select>
              </div>
              <div class="col-sm-4" style="width: 20%">
                <label class="font_normal_body">地址类型:</label>
                <v-select
                  class="select select_list"
                  :value.sync="model.f_address_type"
                  v-model="model.f_address_type"
                  :options='$parent.$parent.addresstypes'
                  placeholder='请选择'
                  condition="f_address_type='{}'"
                  :search="false"
                  close-on-select
                  value-single
                >
                </v-select>
              </div>
              <div class="col-sm-4" style="width: 20%">
                <label class="font_normal_body">入户次数:</label>
                <v-select
                  class="select select_list"
                  :value.sync="model.f_ruhu"
                  v-model="model.f_ruhu"
                  :options='$parent.$parent.ruhus'
                  placeholder='请选择'
                  condition="r >= '{}'"
                  :search="false"
                  close-on-select
                  value-single
                >
                </v-select>
              </div>
              <div class="col-sm-8"></div>
              <div style="float: right;margin-right: 10px">
                <export-excel-safe   :data="$parent.$parent.searchData"
                                     :field="$parent.$parent.excelHeaders"
                                     sqlurl="rs/logic/SafeExportExcel" sql-name="根据安检员查询用户档案" template-name='用户安检情况'></export-excel-safe>
                <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>
              <div  class="span" style = "float:right;margin-right:10px">
                <button class="btn btn-primary width-80" @click="search()">查询</button>
              </div>
              <div  class="span" style = "float:right;margin-right:10px">
                <button class="btn btn-primary width-80" @click="$parent.$parent.show1()">农村年度安检率查看</button>
              </div>
              <div  class="span" style = "float:right;margin-right:10px">
                <button class="btn btn-primary width-80" @click="$parent.$parent.show2()">城市年度安检率查看</button>
              </div>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial="list" class="table table-bordered table table-hover" v-ref:grid>
        <template partial='head'>
          <tr>
            <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_residential_area" name="小区名称"></data-order></th>
            <th><nobr>地址类型</nobr></th>
            <th><nobr>地址</nobr></th>
            <th><data-order field="f_createfile_date" name="建档日期"></data-order></th>
            <th><data-order field="f_last_check_date" name="安检日期"></data-order></th>
            <th><nobr>安检状态</nobr></th>
            <th><nobr>安检结果</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_userinfo_code}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_user_name}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_user_phone}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.rhcon?row.rhcon:0}}</td>
          <td v-bind:class="{newcolor:row.code=='1'}" style="text-align: center">{{row.f_user_type}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_residential_area}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_address_type}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_address}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_createfile_date}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_last_check_date}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_last_check_state}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{$parent.$parent.$parent.getDefect(row.f_last_check_result)}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal :show.sync="showModal" v-ref:modal backdrop="false">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        农村年度安检率查看
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div>
        <form class="form-inline">
          <div class="row form-group">
            <div class="col-sm-4">
              <label class="font_normal_body" >起始时间</label>
              <datepicker
                :value.sync="y_check_start"
                placeholder='安检时间起始'
                :disabled-days-of-week="[]"
                class="select select_list"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "y_check_start">
              </datepicker>
            </div>
            <div class="col-sm-4">
              <label class="font_normal_body" >结束时间</label>
              <datepicker
                :value.sync="y_check_end"
                placeholder='安检时间截止'
                :disabled-days-of-week="[]"
                class="select select_list"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "y_check_end">
              </datepicker>
            </div>
            <button type="button" style="margin-left: 10px" class="button_search" @click="y_search()">查询</button>
          </div>
          <div class="row form-group">
            <div class="col-sm-4">
              <label class="font_normal_body">所属区域</label>
              <v-select
                placeholder='所属区域'
                :value-single="true"
                v-model='yearStreet'
                :value.sync="yearStreet"
                class="select select_list"
                :options='streets'
                close-on-select clear-button> </v-select>
            </div>
          </div>


          <div style="width: 65%;height:100%; display: inline-block">
          </div>

        </form>
        <hr>
        <table class="table table_sy">
          <thead>
          <tr>
            <th>地址类型</th>
            <th>总户数</th>
            <th>安检总入户数</th>
            <th>安检一次入户数</th>
            <th>安检二次入户数</th>
            <th>入户一次安检率</th>
            <th>入户二次安检率</th>
          </tr>
          </thead>
          <tbody>
          <tr v-for="row in yearmodel">
            <td   style="text-align: center;">{{row.f_address_type}}</td>
            <td  style="text-align: center;">{{row.con}}</td>
            <td  style="text-align: center;">{{row.rh_total}}</td>
            <td  style="text-align: center;">{{row.rh_once}}</td>
            <td v-if="row.f_address_type != '城市'" style="text-align: center;">{{row.rh_twice}}</td>
            <td v-else style="text-align: center;"></td>
            <td  style="text-align: center;">{{row.f_check_bv_once}}</td>
            <td v-if="row.f_address_type != '城市'"  style="text-align: center;">{{row.f_check_bv_twice}}</td>
            <td v-else  style="text-align: center;"></td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer" style="text-align: center">
      <!--<button  class="button_search button_spacing" @click="ok()">确认</button>-->
      <button  class="button_clear button_spacing" @click="cancel()">取消</button>
    </div>
  </modal>
  <modal :show.sync="showModal2" v-ref:modal backdrop="false">
    <div slot="modal-header" class="modal-header">
      <h4 class="modal-title">
        城市年度安检率查看
      </h4>
    </div>
    <div slot="modal-body" class="modal-body">
      <div>
        <form class="form-inline">
          <div class="row form-group">
            <div class="col-sm-4">
              <label class="font_normal_body" >起始时间</label>
              <datepicker
                :value.sync="y_check_start"
                placeholder='安检时间起始'
                :disabled-days-of-week="[]"
                class="select select_list"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "y_check_start">
              </datepicker>
            </div>
            <div class="col-sm-4">
              <label class="font_normal_body" >结束时间</label>
              <datepicker
                :value.sync="y_check_end"
                placeholder='安检时间截止'
                :disabled-days-of-week="[]"
                class="select select_list"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "y_check_end">
              </datepicker>
            </div>
            <button type="button" style="margin-left: 10px" class="button_search" @click="y_searchold()">查询</button>
          </div>
          <div class="row form-group">
            <div class="col-sm-4">
              <label class="font_normal_body">所属区域</label>
              <v-select
                placeholder='所属区域'
                :value-single="true"
                v-model='yearStreet'
                :value.sync="yearStreet"
                class="select select_list"
                :options='streets'
                close-on-select clear-button> </v-select>
            </div>
          </div>
          <div style="width: 65%;height:100%; display: inline-block">
          </div>
        </form>
        <hr>
        <table class="table table_sy">
          <thead>
          <tr>
            <th></th>
            <th>总户数</th>
            <th>安检入户数</th>
            <th>一次安检率</th>
          </tr>
          </thead>
          <tbody>
          <tr v-for="row in yearmodelold">
            <td></td>
            <td  style="text-align: center;">{{row.con}}</td>
            <td  style="text-align: center;">{{row.rh_once}}</td>
            <td  style="text-align: center;">{{row.f_check_bv_once}}</td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
    <div slot="modal-footer" class="modal-footer" style="text-align: center">
      <button  class="button_clear button_spacing" @click="cancel()">取消</button>
    </div>
  </modal>
</template>

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

// let select = function * (self,userid) {
//   let http = new HttpResetClass()
//   let getGasman = yield http.load('POST','/rs/search', {
//     source: 'this.getChildByName($安检员$).getUsers()',
//     userid: userid
//   }, {resolveMsg: null, rejectMsg: null})
//   console.log('获取安检员', getGasman)
//   getGasman.data.forEach((checker)=>{
//     self.checkersid.push({label:checker.name,value:checker.id})
//   })
//   self.checkersid.push({label:'全部',value:''})
// }


export default {
  title: '非民用用户安检情况',
  data() {
    let options = []
    let year = (new Date()).getFullYear()
    for (let i = year; i <= year + 3; i++)
      options.push({label: i + '', value: i + ''})
    let moptions = []
    for (let i = 1; i <= 12; i++)
      moptions.push({label: i + '', value: i + ''})

    return {
      yearmodel:[],
      yearmodelold:[],
      y_check_start:`${new Date().getFullYear()}-01-01`,
      y_check_end:`${new Date().getFullYear()}-12-31`,
      searchData: {
        condition: '1=1',
        orderitem: "f_userinfo_code",

        timetype:"dd" ,
        f_filialeids:`(${this.$login.f.orgid})`
      },
      excelHeaders: {
        //用户编号	用户名称	用户电话	安检次数	用户类型	小区名称	地址	安检日期	安检状态	安检结果

        'f_userinfo_code': '用户编号',
        'f_user_name': '用户名称',
        'f_user_phone': '用户电话',
        /*'count_item':'安检次数',*/
        'f_user_type': '用户类型',
        'f_residential_area': '小区名称',
        'f_address':'地址',
        'f_last_check_date':'安检日期',
        'f_last_check_state': '安检状态',
        'f_last_check_result':'安检结果'
      },
      model: new PagedList('rs/sql/根据安检员查询用户档案', 20, {orderitem: "'f_userinfo_code'",timetype:"'dd'" ,con1:"this.con1",con2:"this.con2",f_itemname:'this.check_item',f_itemvalue:'this.check_itemValue',f_filialeids:`'(${this.$login.f.orgid})'`}),
      orgstrs:[{label: '全部', value: ''}],
      checkersid:[],
      SafeCheckXZ:'',
      civil:'',   //民用安检周期
      civilian:'',      //非民用安检周期
      SafeCheckXZs: [{label: '全部', value: ''},{label: '已入户', value: '已入户'}, {label: '未入户', value: '未入户'}], // 安检筛选选项
      SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''},],
      IsShares: [{label: '是', value: '是'}, {label: '否', value: '否'}],
      addresstypes:[{label:"全部",value:""},{label: '城市',value:"城市"},{label: '农村',value:"农村"}],
      ruhus:[{label:"全部",value:""},{label: 1,value:1},{label:2,value:2}],
      IsShare:'否',
      checker: {},
      NoBuys:[{label: '是', value: '是'},{label: '否', value: '否'}],
      criteriaShow: true,
      checkers: [],
      chosenOrg: {id: 0},
      showModal: false,
      showModal2: false,
      checkedAll: false,
      streets:[],
      checkrows: [],
      adjustables: [],
      f_plan_year: year + '',
      f_plan_month: moptions[new Date().getMonth()].value,
      f_effective_start_time:'',  //计划有效起始时间
      f_effective_end_time:'',    //计划有效结束时间
      checkboxModel: {},
      c_year_list: options,
      c_month_list: moptions,
      areas: this.areas(),
      checkstatus: [{label: '全部', value: ''},{label: '到访不遇', value: '到访不遇'}, {label: '拒检', value: '拒检'}],
      usertypes: this.usertypes(),
      userstates: this.userstates(),
      sqlname:'',
      f_check_results:  [{label: '全部', value: ''}, {label: '正常', value: '正常'},{label: '有隐患', value: '有隐患'}],
      creatPlanWay:'',
      yearStreet:'',
      safe_rhs: [{label: '全部', value: ''},{label: '今年已入户', value: '今年已入户'}, {label: '今年未入户', value: '今年未入户'}], // 安检筛选选项
      hasHousehold:'',
      check_item:'',
      check_itemValue:''
    }
  },
  props: {
    checkplan: { // 传入一条安检计划信息
      type: Object
    },
    additemshow:{
      type:Boolean,
      default:false
    }
  },
  ready() {
    // 获取分公司信息
    this.getfengongsi()
    this.model.chosenOrg = {id: 0}
    this.model.f_filialeids = this.$login.f.f_orgids
    this.model.f_filiale = this.$login.f.f_fengongsi
    this.model.f_OrgStr = this.$login.f.orgpathstr
    this.initstreets()
  },
  methods: {
    sort (field, rule) {
      debugger
      // 将所有排序方式设为不排序，实现相互排斥
      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.search2()
    },
    search2() {
      this.$refs.paged.$refs.criteria.search()
    },
    show1(){
      this.showModal=true
    },
    show2(){
      this.showModal2=true
    },
    y_search(){
      let condition=''
      if(!this.y_check_start || !this.y_check_end){
        this.$showMessage("请选择开始和结束时间")
      }
      condition += `and f_offsite_time > '${this.y_check_start}' and f_offsite_time < '${this.y_check_end}' `
      new HttpResetClass().load('POST', 'rs/sql/FetchYearCheckRatio', {
        data: {
          condition: condition,
          usertype:'非民用',
          f_address_type:'农村',
          f_createfile_date: `${new Date().getFullYear()}-01-01 00:00:00`,
          f_street:this.yearStreet
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'}).then((res)=>{
        console.log('---'+JSON.stringify(res))
        this.yearmodel=res.data
      })
    },
    y_searchold(){
      let condition=''
      if(!this.y_check_start || !this.y_check_end){
        this.$showMessage("请选择开始和结束时间")
      }
      condition += `and f_onsite_time > '${this.y_check_start} 00:00:00' and f_onsite_time < '${this.y_check_end} 23:59:59'`
      new HttpResetClass().load('POST', 'rs/sql/FetchYearCheckRatio', {
        data: {
          condition: condition,
          f_createfile_date: `${new Date().getFullYear()}-01-01 00:00:00`,
          usertype:'非民用',
          f_address_type:'城市',
          f_street:this.yearStreet
        }
      }, {resolveMsg: null, rejectMsg: '获取地址失败!'}).then((res)=>{
        this.yearmodelold=res.data
      })
    },
    //初始化街道 添加小区
    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
    },
    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    // 获取县域分公司内容
    getfengongsi(){
      let val = {source: 'this.getParentByType($organization$).getSpecialResByType($organization$)', userid: `${this.$login.f.id}`}
      let http = new HttpResetClass()
      http.load('POST', '/rs/search', {data: val}, {resolveMsg: null, rejectMsg: null}).then((res) => {
        res.data.forEach((item) => {
          this.orgstrs.push({label: item.name, value: item.id})
        })
        console.log(this.orgstrs.length)
      })
    },
    // 县域分公司发生改变
    // orgstrchange(val){
    //   if(val == undefined || val == ''){
    //     return
    //   }else {
    //     this.checkersid = []
    //     let gen = select(this,val)
    //     return co(gen)
    //   }
    // },
    getDefect(val){
      if(val){
        try {
          var defect = JSON.parse(val)
          return defect.result
        }catch (e) {
          console.log(val)
          return '正常'
        }
      }
      return '正常'
    },
    checkerchange(val) {
      this.checkboxModel.f_checker = val.name
      this.checkboxModel.f_checker_id = val.id
    },
    search(args) {
      if(this.SafeCheckXZ && (args.model.f_check_start == '' || args.model.f_check_end == '')){
        this.$showMessage('如果选择 已安检/未安检 选项，需要选择 安检起始时间！')
        return
      }
      let con1='1=1 '
      let con2='1=1 '
      if(this.SafeCheckXZ == '已入户'){
        args.condition += " and r > 0"
        con1 += ` and  f_offsite_time > '${args.model.f_check_start}' and f_offsite_time < '${args.model.f_check_end}'`
        con2 += ` and  f_offsite_time > '${args.model.f_check_start}' and f_offsite_time < '${args.model.f_check_end}'`
        //args.condition += " and ( f_last_check_date > '"+ args.model.f_check_end + " 23:59:00' or  f_last_check_date < '"+ args.model.f_check_start + " 00:00:00' or f_last_check_date is null)"
      } else if(this.SafeCheckXZ == '未入户') {
        args.condition += " and r < 1"
        con1 += ` and f_offsite_time > '${args.model.f_check_start}' and f_offsite_time < '${args.model.f_check_end}'`
        con2 += ` and f_offsite_time > '${args.model.f_check_start}' and f_offsite_time < '${args.model.f_check_end}'`
        if(args.model.f_check_state=='到访不遇'){
          args.condition += " and d > 0"
        }else if(args.model.f_check_state=='拒检'){
          args.condition += " and j > 0"
        }
      }
      this.model.check_item=this.check_item
      this.model.check_itemValue=this.check_itemValue
      args.condition += " and f_filialeid =  '" + this.$login.f.orgid + "' and f_user_type='非民用'"
      this.searchData.condition=args.condition
      this.searchData.f_itemname=this.check_item
      this.searchData.f_itemvalue=this.check_itemValue
      this.searchData.f_filialeids= `(${this.$login.f.orgid})`
      this.searchData.con1=con1
      this.searchData.con2=con2
      this.model.con1=con1
      this.model.con2=con2
      return this.model.search( args.condition, args.model)
    },
    checkstatus() {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')]
    },
    usertypes() {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
    },
    userstates() {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')]
    },
    show() {
      this.criteriaShow = true
    },
    confirm() {
      if (!this.checkboxModel.f_plan_name) {
        this.$showMessage('请填写安检计划名称!')
        return
      }
      // if(this.f_effective_start_time == ''){
      //   this.$showMessage('请选择有效起始日期！')
      //   return
      // }
      // if(this.f_effective_end_time == ''){
      //   this.$showMessage('请选择有效结束日期！')
      //   return
      // }
      if(this.IsShare == '否'){
        if (!this.checkboxModel.f_checker_id) {
          this.$showMessage('请选择安检员！')
          return
        }
      }
      let gen = saveGen(this)
      return co(gen)
    },
    changeStates() {
      if (this.checkedAll) {//实现反选/
        this.checkrows = [];
        for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
          this.$set('$refs.paged.model.rows[' + i + '].checked', false)
        }
      } else {//实现全选
        for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
          this.$set('$refs.paged.model.rows[' + i + '].checked', true)
        }
        let _this = this
        let condition = this.$refs.paged.$refs.criteria.condition
        let url = this.model.url
        this.$resetpost(`${url}?pageSize=9999999`, {
          data: {
            condition: condition,
            groupitem: '',
            orderitem: 'f_residential_area',
            f_usertype:this.model.f_usertype,
            f_filialeids: this.model.f_filialeids,
            month: this.model.month,
            safeCycle:this.model.safeCycle,
            f_checktime_start:this.model.f_checktime_start,
            f_checktime_end:this.model.f_checktime_end,
            SafeCheckSX: this.model.SafeCheckSX,
            f_last_check_state: this.model.f_last_check_state
          },
        },{resolveMsg: null, rejectMsg: null}, -1).then(
          (respanse) => {
            if (respanse.data.length >= 5000) {
              this.$showMessage("数据量太大，请重新选择")
            } else {
              _this.checkrows = []
              for (let j = 0; j < respanse.data.length; j++) {
                _this.checkrows.push(respanse.data[j])
              }
              console.log(_this.checkrows);
            }
          })
      }
    },
    addChecked(item) {
      console.log(item);
      if (!item.checked) {
        this.checkrows.push(item);
        console.log(this.checkrows);
      } else {
        for (let i = 0; i < this.checkrows.length; i++) {
          if (item.f_userinfo_id == this.checkrows[i].f_userinfo_id) {
            this.checkrows.splice(i, 1)
          }
        }
      }
    },
    ToshowModal() {
      this.creatPlanWay = 'single'
      if (this.checkrows.length > 0) {
        this.showModal = true
      } else {
        this.$showMessage("请选择需要安检的用户!")
      }
    },
    FiltrationPlan(){
      if(this.model.rows.length == 0){
        this.$showMessage("暂无可生成的计划！")
        return
      }
      this.creatPlanWay = 'filtration'
      this.showModal = true
    },
    AllPlan() {
      if(this.model.rows.length == 0){
        this.$showMessage("暂无可生成的计划！")
        return
      }
      this.creatPlanWay = 'all'
      this.showModal = true
    },
    cancel() {
      this.showModal2=false
      this.showModal = false
    },
    areas() {
      let rs = []
      for (let i = 0; i < this.$login.f.f_allArea.length; i++) {
        let temp = {
          label: this.$login.f.f_allArea[i].label,
          value: this.$login.f.f_allArea[i].label
        }
        rs.push(temp)
      }
      return [{label: '全部', value: ''}, ...rs]
    },
    initAdjustables() {
      console.log('初始化调压箱', this.$GetSaleParam)
      let arr = []
      let filter = this.$login.f.f_orgids
      this.$GetSaleParam.getAdjustable(filter).forEach((item) => {
        let temp = {}
        temp.label = `[${item.value.f_adjustable_id}]-${item.label}`
        temp.value = `${item.value.id}`
        arr.push(temp)
      })
      this.adjustables = [{label: '全部', value: ''}, ...arr]
    },
  },

  watch: {
    'model.f_usertype'(val){
      if(val == '民用'){
        this.model.safeCycle = this.civil
      }else if(val == '非民用'){
        this.model.safeCycle = this.civilian
      }
    },
    'model.SafeCheckXZ'(val) {
      this.model.SafeCheckSC = ''
      if (val == '已安检') {
        this.model.SafeCheckCQ = ''
        this.model.SafeCheckSX = {
          f_check_end: '', // 安检时间  查询起始条件
          f_check_start: ''// 安检时间  查询终止条件
        }
      } else {
        // 当使用筛选条件时，清空不需要的条件选项
        this.model.f_issue_start = ''
        this.model.f_issue_end = ''
        this.$refs.paged.$refs.criteria.model.f_check_start = ''
        this.$refs.paged.$refs.criteria.model.f_check_end = ''
        this.$refs.paged.$refs.criteria.model.f_last_check_state = ''
        this.model.month = ''
        if(val == '应安检'){
          this.model.SafeCheckSC = '否'

          this.model.f_issue_start = Util.toStartDateString()
          this.model.f_issue_end = Util.toStandardDateString()
        }
        // this.model.f_checktime_start = ''
        // this.model.f_checktime_end = ''
      }
    },
    'model.SafeCheckSC'(val) {
      if (val == '') {
        this.model.f_issue_start = ''
        this.model.f_issue_end = ''
      }
    },
    // 'checker'(val){
    //   console.log("checker",this.checker)
    //   if(val){
    //     this.checkboxModel.f_checker = this.checker[0].name
    //     this.checkboxModel.f_checker_id = this.checker[0].id
    //   }
    // },
    'model.rows'() {
      // if (!this.checkedAll) {//实现反选/
      // this.checkrows = [];
      for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
        var k = false
        for (let j = 0; j < this.checkrows.length; j++) {
          if (this.$refs.paged.model.rows[i].f_userinfo_id == this.checkrows[j].f_userinfo_id) {
            this.$set('$refs.paged.model.rows[' + i + '].checked', true)
            k = true
            continue
          }
        }
        if (!k) {
          this.$set('$refs.paged.model.rows[' + i + '].checked', false)
        }
      }
      // } else {//实现全选
      //   // this.checkboxModel = {};
      //   for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
      //     this.$set('$refs.paged.model.rows[' + i + '].checked', true)
      //   }
      // }
    }
  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>
<style scoped>
.newcolor{
  color:red;
}
.table th{
  background-color: #f2f6fa;
  color: black;
}
</style>
