<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>
      <criteria partial='criteria' class="search_area" 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="ui.f_userinfo_code = '{}'">
            </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="ui.f_user_name = '{}'">
            </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%;margin-left: 2px"
                     placeholder="小区" condition="ua.f_residential_area = '{}'">
            </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%;margin-left: 2px"
                     placeholder="地址" condition="ua.f_address like '%{}%'">
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">用户类型</label>
              <v-select id="f_usertype"
                        placeholder='用户类型'
                        class="select select_list"
                        style="width: 60%"
                        :value.sync="model.f_usertype"
                        :value-single="true"
                        :options='$parent.$parent.usertypes'
                        v-model="model.f_usertype"
                        condition="uf.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"
                style="width: 60%"
                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%">
              <label class="font_normal_body">安检起始</label>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='最后安检时间起始'
                :disabled-days-of-week="[]"
                style="width: 60%"
                :format="'yyyy-MM-dd 00:00:00'"
                :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='最后安检时间结束'
                style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 23:59:59'"
                :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='安检状态'
                        class="select select_list"
                        style="width: 60%"
                        :value.sync="model.f_last_check_state"
                        :value-single="true"
                        :options='$parent.$parent.checkstatus'
                        v-model="model.f_last_check_state"
                        condition="f_entry_status = '{}'"
                        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='隐患情况'
                class="select select_list"
                style="width: 60%"
                :value-single="true"
                v-model='model.f_check_result'
                :value.sync="model.f_check_result"
                :options='$parent.$parent.f_check_results'
                condition="f_defect_content  like '%{}%'"
                close-on-select clear-button> </v-select>
            </div>
            <div class="col-sm-8" style="width: 40%" v-if="$parent.$parent.criteriaShow">
              <role-selector
                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>
            </div>
<!--            <div class="col-sm-4" style="width: 20%">-->
<!--              <label class="font_normal_body">下发次数</label>-->
<!--              <input type="text" class="input_search" v-model="model.sendnum_start" id="sendnum_start" style="width:60%;margin-left: 2px"-->
<!--                     placeholder="下发次数(>=)" condition="send_num>={}">-->
<!--            </div>-->
<!--            <div class="col-sm-4" style="width: 20%">-->
<!--              <label class="font_normal_body">下发次数</label>-->
<!--              <input type="text" class="input_search" v-model="model.sendnum_end" id="sendnum_end" style="width:60%;margin-left: 2px"-->
<!--                     placeholder="下发次数(<=)" condition="send_num<={}">-->
<!--            </div>-->
            <div  class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">下发次数</label>
              <v-select
                placeholder='下发次数'
                class="select select_list"
                style="width: 60%"
                :value-single="true"
                v-model='model.send_num'
                :value.sync="model.send_num"
                :options='$parent.$parent.send_nums'
                condition="{}"
                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='当前到访次数'
                class="select select_list"
                style="width: 60%"
                :value-single="true"
                v-model='model.f_check_version'
                :value.sync="model.f_check_version"
                :options='$parent.$parent.checkversion'
                condition="{}"
                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='是否当年新增'
                class="select select_list"
                style="width: 60%"
                :value-single="true"
                v-model='model.f_is_now_year'
                :value.sync="model.f_is_now_year"
                :options='$parent.$parent.is_now_years'
                close-on-select clear-button> </v-select>
            </div>
          </div>
            <div class="row">
              <div class="col-sm-8"></div>
              <div class="span" style = "float:right;margin-right:10px">
                <div class="button_spacing" style="float: right; margin-right: 10px;"
                     :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                     @click="$parent.$parent.hiddenr()">
                </div>
                <button type="button" class="button_search button_spacing" @click="$parent.$parent.openYearPlan()">年度计划查看</button>
              </div>
              <div style="float: right;margin-right: 10px">
<!--                <export-excel-plus   :data="$parent.$parent.searchData"
                                :field="$parent.$parent.excelHeaders"
                                :exportprogress="true" :choose-col="true"
                                sqlurl="api/af-safecheck/logic/exportfileplus" sql-name="FetchUserFileByOrgChecker"
                                :template-name='$parent.$parent.excelTitle'></export-excel-plus>-->

<!--                <easy-excel-export :data="$parent.$parent.searchData"-->
<!--                                   :field="$parent.$parent.excelHeaders"-->
<!--                                   :exportprogress="true" v-ref:exports-->
<!--                                   sqlurl="rs/easyexcel/export" sql-name="FetchUserFileByOrgChecker" :template-name="$parent.$parent.excelTitle"-->
<!--                                   :choose-col="true">-->
<!--                </easy-excel-export>-->
                <export-excel   :data="$parent.$parent.searchData" :choose-col="true"
                                :field="$parent.$parent.excelHeaders"
                                sqlurl="api/af-safecheck/logic/exportfile" sql-name="FetchUserFileByOrgChecker"
                                :template-name="$parent.$parent.excelTitle"></export-excel>

<!--                <export-excel   :data="$parent.$parent.searchData"-->
<!--                                :field="$parent.$parent.excelHeaders"-->
<!--                                sqlurl="api/af-safecheck/logic/exportfile" sql-name="根据安检员查询用户档案" :template-name='$parent.$parent.excelTitle'></export-excel>-->

              </div>

              <div class="span" style = "float:right;margin-right:10px">
                <button type="button" class="button_search button_spacing" @click="search()">查询</button>
              </div>
            </div>

            <div class="row">
              <label class="font_normal_body">安检总数:{{$parent.$parent.planItemCount.total}}&nbsp;&nbsp;&nbsp;  民用户:{{$parent.$parent.planItemCount.civilCount}}&nbsp;&nbsp;&nbsp;  非民用户:{{$parent.$parent.planItemCount.noCivilCount}}&nbsp;&nbsp;&nbsp;  其他:{{$parent.$parent.planItemCount.elseCount}}</label>
              <label class="font_normal_body" style="float: right">&nbsp;&nbsp;&nbsp;  已下发户数:{{$parent.$parent.planItemCount.yxf}}&nbsp;&nbsp;&nbsp;  未下发户数:{{$parent.$parent.planItemCount.wxf}}&nbsp;&nbsp;&nbsp;  已安检户数:{{$parent.$parent.planItemCount.yaj}}&nbsp;&nbsp;&nbsp;  未安检户数:{{$parent.$parent.planItemCount.waj}}
              </label>
            </div>
          </div>

      </criteria>
      <data-grid :model="model" partial="list" class="list_area table_sy" 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><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 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.count_item?row.count_item:0}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.send_num?row.send_num: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}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_open_date}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_checker_name}}</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>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_check_version}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_plan_name}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.reshuiqi}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.bigualu}}</td>
<!--          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_repair_approved_note}}</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">
        <div  class="row">
          <div class="col-sm-8" style="width: 30%">
            <label class="font_normal_body" style="margin-right: 2px">&nbsp;&nbsp;&nbsp;公司&nbsp;&nbsp;&nbsp;</label>
            <right-tree @re-res="getRes1" :initresid="$login.f.orgid" >
            </right-tree>
          </div>
          <div class="span" style = "float:right;margin-right:10px">
            <button type="button" class="button_search button_spacing" @click="searchYearPlan()">查询</button>
          </div>
        </div>
        <div style="text-align: center;margin-top: 10px;background-color: #6aa6e2;padding: 5px 0;color: white;">民用户年度安检计划</div>
        <div id="yearPlan_civil" style="width:400px; height: 300px;margin: 0 auto"></div>
        <div style="text-align: center;margin-top: 10px;background-color: #6aa6e2;padding: 5px 0;color: white;">工商户年度安检计划</div>
        <div id="yearPlan_nocivil" style="width:400px; height: 300px;margin: 0 auto"></div>
      </div>
      <div slot="modal-footer" class="modal-footer" style="text-align: center">

      </div>
    </modal>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  import { HttpResetClass } from 'vue-client'
  import co from 'co'
  import echarts from 'echarts'
  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:''})
  // }
  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})
    console.log('获取安检员', getGasman)
    self.checkersid.push({label: '全部', value: ''})
    getGasman.data.forEach((checker) => {
      self.checkersid.push({label: checker.name, value: checker.id})
    })
  }

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

      let model=new PagedList('api/af-safecheck/sql/FetchUserFileByOrgChecker', 20)
      model.f_filialeid = `('${this.$login.f.orgid}')`
      return {
        //excelTitle:'用户安检情况导出'+Util.toStandardTimeString().substring(11,19).replace(new RegExp( ':' , "g" ),""),
        excelTitle:'用户安检情况导出1' + new Date().getTime(),
        searchData: {
          condition: '1=1',
          papercondition:'1=1',
          itemcondition:'1=1'
        },
        excelHeaders: {
          //用户编号	用户名称	用户电话	安检次数	用户类型	小区名称	地址	安检日期	安检状态	安检结果

          'f_userinfo_code': '用户编号',
          'f_user_name': '用户名称',
          'f_user_phone': '用户电话',
          'count_item':'安检次数',
          'send_num':'下发次数',
          'f_user_type': '用户类型',
          'f_residential_area': '小区名称',
          'f_address':'地址',
          'f_open_date':'开户日期',
          'f_checker_name':'安检员',
          'f_last_check_date':'安检日期',
          'f_last_check_state':'安检状态',
          'f_last_check_result':'安检结果',
          'f_check_version':'当前到访次数',
          'f_plan_name': '计划名称',
          'bigualu': '壁挂炉',
          'reshuiqi': '热水器'
        },
        f_filialeids1:`(${this.$login.f.orgid})`,
        model: model,
        orgstrs:[{label: '全部', value: ''}],
        checkersid:[],
        SafeCheckXZ:'已安检',
        civil:'',   //民用安检周期
        civilian:'',      //非民用安检周期
        SafeCheckXZs: [{label: '全部', value: ''},{label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'}], // 安检筛选选项
        SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''},],
        is_now_years: [ {label: '全部', value: ''},{label: '是', value: '是'}, {label: '否', value: '否'}],
        IsShares: [{label: '是', value: '是'}, {label: '否', value: '否'}],
        IsShare:'否',
        checker: {},
        NoBuys:[{label: '是', value: '是'},{label: '否', value: '否'}],
        send_nums:[{label: '全部', value: ''},{label: '0', value: "send_num is null"},{label: '1', value: "send_num = 1"},{label: '2', value:  "send_num = 2"},{label: '3及以上', value:  "send_num >= 3"}],
        checkversion:[{label: '全部', value: ''},{label: '1', value:  "cp.f_check_version  = '1'"},{label: '2', value:  "cp.f_check_version  = '2'"},{label: '3及以上', value:  "cp.f_check_version >= '3'"}],
        criteriaShow: true,
        checkers: [],
        chosenOrg: {id: 0},
        showModal: false,
        checkedAll: false,
        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: [],
        checkstatus: [],
        usertypes: [],
        userstates: [],
        sqlname:'',
        f_check_results:  [{label: '全部', value: ''}, {label: '正常', value: '正常'},{label: '有隐患', value: '有隐患'}],
        creatPlanWay:'',
        yearplan:'',
        starttime1:'',
        endtime1:'',
        planItemCount:{
          total:0,
          civilCount:0,
          noCivilCount:0,
          elseCount:0,
          yxf:0,
          wxf:0,
          yaj:0,
          waj:0,
        }
      }
    },
    props: {
      checkplan: { // 传入一条安检计划信息
        type: Object
      },
      additemshow:{
        type:Boolean,
        default:false
      }
    },
    ready() {
      // 获取分公司信息
      this.$refs.paged.$refs.criteria.model.f_check_end=Util.toStandardTimeString().substring(0,10)+' 23:59:59'

      this.$refs.paged.$refs.criteria.model.f_check_start=Util.getPreMonth(this.$refs.paged.$refs.criteria.model.f_check_end).substring(0,10)+' 00:00:00'

      // 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.checkstatus= this.checkstatusList()
      this.usertypes= this.usertypesList()
      this.userstates= this.userstatesList()
      // let gen = select(this)
      // co(gen)
    },
    methods: {
      getaaaa(row){
        if(row){
          return row
        }
        return 0
      },
      hiddenr() {
        this.$parent.showItem = !this.$parent.showItem
      },
      searchYearPlan(){
        this.setSafe()
        this.setSafeNoClvil()
      },
      openYearPlan(){
        this.showModal=true
        this.setSafe()
        this.setSafeNoClvil()
      },
      //年度计划饼状图
      async setSafe(){
        let result=await new HttpResetClass().load('post', `api/af-safecheck/sql/getYearPlanStatistics`, {data:{condition:`f_plan_type='民用' and ycp.f_filialeid in ${this.f_filialeids1}`,year:new Date().getFullYear()}}, {resolveMsg: null, rejectMsg: null})
        console.log("--------"+JSON.stringify(result))
        this.yearplan = echarts.init(document.getElementById('yearPlan_civil'))
        this.yearplan.setOption({
          series : [
            {
              name: '民用户年度安检计划',
              type: 'pie',    // 设置图表类型为饼图
              radius: '60%',  // 饼图的半径，外半径为可视区尺寸（容器高宽中较小一项）的 55% 长度。
              data:[          // 数据数组，name 为数据项名称，value 为数据项值
                {value:result.data[0].total, name:'未检居民户数:'+(result.data[0].total-result.data[0].rh-result.data[0].df-result.data[0].jj)},
                {value:result.data[0].rh, name:'入户数:'+result.data[0].rh},
                {value:result.data[0].df, name:'到访不遇户数:'+result.data[0].df},
                {value:result.data[0].jj, name:'拒检户数:'+result.data[0].jj}
              ]
            }
          ]
        })
      },
      //非民用年度计划
      async setSafeNoClvil(){
        let result=await new HttpResetClass().load('post', `api/af-safecheck/sql/getYearPlanStatistics`, {data:{condition:`f_plan_type='非民用' and ycp.f_filialeid in ${this.f_filialeids1}`,year:new Date().getFullYear()}}, {resolveMsg: null, rejectMsg: null})
        console.log("--------"+JSON.stringify(result))
        this.yearplan = echarts.init(document.getElementById('yearPlan_nocivil'))
        this.yearplan.setOption({
          series : [
            {
              name: '工商户年度安检计划',
              type: 'pie',    // 设置图表类型为饼图
              radius: '60%',  // 饼图的半径，外半径为可视区尺寸（容器高宽中较小一项）的 55% 长度。
              data:[          // 数据数组，name 为数据项名称，value 为数据项值
                {value:result.data[0].total, name:'未检工商户数:'+(result.data[0].total-result.data[0].rh-result.data[0].df-result.data[0].jj)},
                {value:result.data[0].rh, name:'入户数:'+result.data[0].rh},
                {value:result.data[0].df, name:'到访不遇户数:'+result.data[0].df},
                {value:result.data[0].jj, name:'拒检户数:'+result.data[0].jj}
              ]
            }
          ]
        })
      },
      // 获取县域分公司内容
      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) {
        let papercondition='1=1'
        let itemcondition='1=1'
        let condition=''
        console.log("979797")
        console.log("args:"+JSON.stringify(args))
        if (this.SafeCheckXZ=='已安检'){
          if (args.model.f_check_start){
            papercondition+=` and f_offsite_time>='${args.model.f_check_start}'`
            itemcondition+=` and f_create_time>='${args.model.f_check_start}'`
            condition+=` and f_offsite_time>='${args.model.f_check_start}'`
          }
          if (args.model.f_check_end){
            papercondition+=` and f_offsite_time<='${args.model.f_check_end}'`
            itemcondition+=` and f_create_time<='${args.model.f_check_end}'`
            condition+=` and f_offsite_time<='${args.model.f_check_end}'`
          }
          // if (args.model.f_checker_id){
          //   papercondition+=` and f_checker_name='${args.model.f_checker_id}'`
          // }
          // if (args.model.f_entry_status){
          //   papercondition+=` and f_entry_status='${args.model.f_entry_status}'`
          // }
        }else if(this.SafeCheckXZ=='未安检'){
        if (args.model.f_check_start&&args.model.f_check_end){
          papercondition+=` and (f_offsite_time>='${args.model.f_check_start}' and f_offsite_time<='${args.model.f_check_end}')`
          itemcondition+=` and (f_create_time>='${args.model.f_check_start}' and f_create_time<='${args.model.f_check_end}')`
          condition+=` and  f_offsite_time is null`
        }else{
          this.$showMessage('选择安检筛选后必须选择安检起始时间以及安检结束时间')
          return
        }
        }
        if (this.model.f_filialeid){
          papercondition+=` and f_filialeid in ${this.model.f_filialeid}`
          itemcondition+=` and f_filialeid in ${this.model.f_filialeid}`
          condition+=` and ui.f_filialeid in ${this.model.f_filialeid}`
        }
        if (args.model.f_is_now_year == '是'){
          condition+=` and  year(ui.f_open_date)=year(GETDATE()) `
        }
        if (args.model.f_is_now_year == '否'){
          condition+=` and  year(ui.f_open_date)!=year(GETDATE()) `
        }
        this.model.params.papercondition =papercondition
        this.model.params.itemcondition  =itemcondition
        args.condition+=condition
        this.searchData.papercondition=papercondition
        this.searchData.itemcondition=itemcondition
        this.searchData.condition=args.condition
        this.excelTitle = '用户安检情况导出1' + new Date().getTime()
        // this.model.params.entrystatus=args.model.f_last_check_state
        new HttpResetClass().load("post","api/af-safecheck/sql/getPlanItemCountByChecker",{data:{
            condition:args.condition,
            papercondition:papercondition,
            itemcondition: itemcondition
          }}, {resolveMsg: null, rejectMsg: null}).then((res)=>{
          console.log("res:"+JSON.stringify(res))
          this.planItemCount.total=res.data[0].total
          this.planItemCount.civilCount=res.data[0].civilcount
          this.planItemCount.noCivilCount=res.data[0].nocivilcount
          this.planItemCount.elseCount=res.data[0].total-res.data[0].civilcount-res.data[0].nocivilcount
          this.planItemCount.yxf=res.data[0].yxf
          this.planItemCount.wxf=res.data[0].wxf
          this.planItemCount.yaj=res.data[0].yaj
          this.planItemCount.waj=res.data[0].waj
        })
         return this.model.search( args.condition, args.model)
      },
      checkstatusList() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')]
      },
      usertypesList() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      userstatesList() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')]
      },
      show() {
        this.criteriaShow = true
      },
      hidden() {
        this.criteriaShow = false
      },
      confirm() {
        if (!this.checkboxModel.f_plan_name) {
          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.showModal = false
      },
      areasList() {
        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]
      },
      getRes(obj){
        this.model.f_filialeid = this.$login.convertToIn(obj.resids);
        console.log("f_filialeid值发生改变："+this.model.f_filialeid)
      },
      getRes1(obj){
        this.f_filialeids1 = this.$login.convertToIn(obj.resids);
        console.log("打嗝日志----："+'-----'+this.f_filialeids1)
      }
    },

    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>
