<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' 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-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">小&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;区</label>
              <input type="text" class="form-control" v-model="model.f_residential_area" style="height:34px;margin-top: 8px"
                     placeholder="小区" condition="tua.f_residential_area like '%{}%'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">街&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;道</label>
              <input type="text" class="form-control" v-model="model.f_street" id="f_street" style="height:34px;margin-top: 8px"
                     placeholder="街道" condition="tua.f_street like '%{}%'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
              <input type="text" class="form-control" v-model="model.f_building" id="f_building" style="height:34px;margin-top: 8px"
                     placeholder="楼号" condition="tua.f_building = '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;元</label>
              <input type="text" class="form-control" v-model="model.f_unit"  style="height:34px;margin-top: 8px"
                     placeholder="单元" condition="tua.f_unit = '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">用户状态</label>
              <v-select placeholder='用户状态'
                        :value-single="true" style="margin-top: 8px"
                        :value.sync="$parent.$parent.model.f_table_state"
                        :options='$parent.$parent.tableStates'
                        v-model="$parent.$parent.model.f_table_state"
                        close-on-select clear-button> </v-select>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-3 form-group form-input-group" style="width: 20%"  v-if="$parent.$parent.model.SafeCheckXZ == '应安检'">
              <label class="control-label">应检起始</label>
              <datepicker
                :value.sync="$parent.$parent.model.f_shouldcheck_start"
                placeholder='应检时间起始'
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'" style="margin-top: 8px"
                :show-rest-button="reset"
                v-model = "$parent.$parent.model.f_shouldcheck_start">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%" v-if="$parent.$parent.model.SafeCheckXZ == '应安检'">
              <label class="control-label">应检结束</label>
              <datepicker
                :value.sync="$parent.$parent.model.f_shouldcheck_end"
                placeholder='应检时间结束' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "$parent.$parent.model.f_issue_end"
              >
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%"  v-if="$parent.$parent.model.SafeCheckXZ != '未安检' && $parent.$parent.model.SafeCheckSC != ''">
              <label class="control-label">生成起始</label>
              <datepicker
                :value.sync="$parent.$parent.model.f_issue_start"
                placeholder='最后生成时间起始' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "$parent.$parent.model.f_issue_start">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%"v-if="$parent.$parent.model.SafeCheckXZ != '未安检' && $parent.$parent.model.SafeCheckSC != ''">
              <label class="control-label">生成结束</label>
              <datepicker  style="margin-top: 8px"
                           :value.sync="$parent.$parent.model.f_issue_end"
                           placeholder='最后生成时间结束'
                           :disabled-days-of-week="[]"
                           :format="'yyyy-MM-dd'"
                           :show-rest-button="reset"
                           v-model = "$parent.$parent.model.f_issue_end"
              >
              </datepicker>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">建档日期</label>
              <datepicker
                :value.sync="model.f_createfile_date"
                placeholder='建档日期'
                :disabled-days-of-week="[]"
                condition="ui.f_createfile_date >= '{}'"
                :format="'yyyy-MM-dd'"
                v-model="model.f_createfile_date">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">开始卡号</label>
              <input type="text" class="form-control" v-model="model.f_card_id_start"  style="height:34px;margin-top: 8px"
                     placeholder="开始卡号" condition="ui.f_userinfo_code >= '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">结束卡号</label>
              <input type="text" class="form-control" v-model="model.f_card_id_end"  style="height:34px;margin-top: 8px"
                     placeholder="结束卡号" condition="ui.f_userinfo_code <= '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">新档案</label>
              <v-select placeholder='是否第二套档案'
                        :value-single="true" style="margin-top: 8px"
                        v-model="model.f_second_state"
                        :value.sync="model.f_second_state"
                        condition="ui.f_second_state {} "
                        :options='$parent.$parent.is_to_userinfos'
                        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 placeholder='在用状态'
                        :value-single="true" style="margin-top: 8px"
                        :value.sync="$parent.$parent.is_reuse_state"
                        :options='$parent.$parent.is_reuse_states'
                        v-model="$parent.$parent.is_reuse_state"
                        close-on-select clear-button> </v-select>
            </div>
          </div>
          <div class="row">
            <div class="span" style = "float:right;margin-top:5px">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <button type="button" class="button_export button_spacing" @click="$parent.$parent.ToshowModal()" v-if="!$parent.$parent.checkplan">生成计划</button>
              <button type="button" class="button_export button_spacing" @click="$parent.$parent.AllPlan()" v-if="!$parent.$parent.checkplan">全部生成</button>
              <!--<button type="button" class="button_export button_spacing" @click="$parent.$parent.CreadteArea()" v-if="$parent.$parent.model.f_data_source == '自建小区'">创建小区</button>-->
              <!--<button class="btn" @click="$parent.$parent.hidden()">-->
              <!--<span class="glyphicon glyphicon-chevron-up"></span>-->
              <!--</button>-->
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">气表品牌</label>
              <v-select placeholder='气表品牌'
                        :value-single="true" style="margin-top: 8px"
                        :value.sync="model.f_meter_brand"
                        :options='$parent.$parent.f_meter_brands'
                        condition="gb.f_meter_brand = '{}'"
                        v-model="model.f_meter_brand"
                        close-on-select clear-button> </v-select>
            </div>

          </div>
          <modal :show.sync="$parent.$parent.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 class="row">
                <div class="col-sm-6  form-group form-fix-width">
                  <label class="control-label">计划名称</label>
                  <input class="form-control" type="text" v-model="$parent.$parent.checkboxModel.f_plan_name"  placeholder="计划名称(必填)">
                </div>
                <!--<div class="col-sm-6  form-group form-fix-width">-->
                <!--<label class="control-label">是否共享</label>-->
                <!--<v-select id="checker" :value="$parent.$parent.IsShare"-->
                <!--v-on:change="$parent.$parent.IsShareschange" :value-single="true"-->
                <!--:options='$parent.$parent.IsShares' close-on-select clear-button> </v-select>-->
                <!--</div>-->
                <!--<div class="col-sm-6  form-group form-fix-width" v-if="$parent.$parent.IsShare == '否'">-->
                <!--<label class="control-label">安检员</label>-->
                <!--<v-select id="checker" :value="$parent.$parent.checker"-->
                <!--v-on:change="$parent.$parent.checkerchange" :value-single="true"-->
                <!--:options='$parent.$parent.checkers' close-on-select clear-button> </v-select>-->
                <!--</div>-->
                <!--<div class="col-sm-6  form-group form-fix-width" v-if="$parent.$parent.IsShare == '是'">-->
                <!--<label class="control-label">站点</label>-->
                <!--<v-select id="checker" :value="$parent.$parent. "-->
                <!--v-on:change="$parent.$parent." :value-single="true"-->
                <!--:options='$parent.$parent.' close-on-select clear-button> </v-select>-->
                <!--</div>-->
                <div class="col-sm-6  form-group form-fix-width">
                  <label class="control-label">计划年份</label>
                  <v-select id="c_plan_year" :value.sync="$parent.$parent.f_plan_year"
                            :options='$parent.$parent.c_year_list' close-on-select clear-button> </v-select>
                </div>
                <div class="col-sm-6  form-group form-fix-width">
                  <label class="control-label">计划月份</label>
                  <v-select id="c_plan_month" :value.sync="$parent.$parent.f_plan_month"
                            :options='$parent.$parent.c_month_list' close-on-select clear-button> </v-select>
                </div>
                <!--<div class="col-sm-6  form-group form-fix-width">-->
                <!--<label class="control-label">有效起始</label>-->
                <!--<datepicker-->
                <!--:value.sync="$parent.$parent.f_effective_start_time"-->
                <!--placeholder='最后安检时间起始'-->
                <!--:disabled-days-of-week="[]"-->
                <!--:format="'yyyy-MM-dd'"-->
                <!--:show-rest-button="reset"-->
                <!--v-model = "$parent.$parent.f_effective_start_time">-->
                <!--</datepicker>-->
                <!--</div>-->
                <!--<div class="col-sm-6  form-group form-fix-width">-->
                <!--<label class="control-label">有效结束</label>-->
                <!--<datepicker-->
                <!--:value.sync="$parent.$parent.f_effective_end_time"-->
                <!--placeholder='最后安检时间起始'-->
                <!--:disabled-days-of-week="[]"-->
                <!--:format="'yyyy-MM-dd'"-->
                <!--:show-rest-button="reset"-->
                <!--v-model = "$parent.$parent.f_effective_end_time">-->
                <!--</datepicker>-->
                <!--</div>-->
              </div>
            </div>
            <div slot="modal-footer" class="modal-footer">
              <button type="button" class="button_spacing button_search" @click="$parent.$parent.confirm">生成</button>
              <button type="button" class="button_spacing button_clear" @click="$parent.$parent.cancel">取消</button>
            </div>
          </modal>
          <modal :show.sync="$parent.$parent.showCreate" 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 class="row">
                <div class="col-sm-6  form-group form-fix-width">
                  <label class="control-label">街道</label>
                  <input class="form-control" type="text" v-model="$parent.$parent.f_residential_area"  placeholder="街道">
                </div>
                <div class="col-sm-6  form-group form-fix-width">
                  <label class="control-label">小区名称</label>
                  <input class="form-control" type="text" v-model="$parent.$parent.f_street"  placeholder="小区名称">
                </div>
              </div>
            </div>
            <div slot="modal-footer" class="modal-footer">
              <button type="button" class="button_spacing button_search" @click="$parent.$parent.confirmCreate">生成</button>
              <button type="button" class="button_spacing button_clear" @click="$parent.$parent.cancelCreate">取消</button>
            </div>
          </modal>
        </div>
      </criteria>
      <data-grid :model="model" partial="list" class="table table-bordered table table-hover" v-ref:grid >
        <template partial='head'>
          <tr>
            <!--<th><nobr>全选<input style="width: 22px;height: 22px;" type="checkbox" @click='$parent.$parent.$parent.changeStates(row)'  v-model='$parent.$parent.$parent.checkedAll'></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 v-if="$parent.model.f_table_state != ''"><nobr>用户状态</nobr></th>
            <th v-if="$parent.model.f_data_source == '自建小区'"><nobr>操作</nobr></th>

          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center"><nobr><input style="width: 22px;height: 22px;" type="checkbox" v-model="row.checked" v-bind:checked="row.checked"  @click="$parent.$parent.$parent.addChecked(row)"></nobr></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_street}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_area}}</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_user_num}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.uad_meter_brand}}</td>
          <td v-if="$parent.model.f_table_state != ''" v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{row.f_table_state}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center" v-if="$parent.$parent.model.f_data_source == '自建小区'"><span @click="$parent.$parent.$parent.addBuilding(row.id)" style="color: #00A3F0">新增楼栋</span></td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <work-busy :is-busy="showWait"></work-busy>
</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'
import AppData from '../../stores/AppData'

let AddItem = function * (self,val) {
  self.checkboxModel.f_filialeids = self.$login.f.f_orgids
  self.checkboxModel.f_orgstr = self.$login.f.orgpathstr
  self.checkboxModel.planid = self.checkplan.id
  self.checkboxModel.rows = self.checkrows
  self.checkboxModel.model = self.model
  self.checkboxModel.sqlname = self.sqlname
  self.checkboxModel.nostrids = ''
  if(val == 'single'){
    yield self.$resetpost('rs/logic/GenPlanItemAdd', {data: self.checkboxModel}).then((res)=>{
      console.log(res.data)
      self.$showMessage(`共选择 ${self.checkboxModel.rows.length} 个用户，其中${res.data.existitem}个在${self.checkplan.f_plan_name}已存在，新增${res.data.updateitem}个！`)
      self.$emit('finish')
    })
  }else if (val == 'all'){
    console.log('self.model',self.model)
    if(self.model.rows == 0){
      self.$showMessage('暂无可下发用户，请重新查询！')
      return
    }
    self.checkboxModel.planWay = 'add'
    yield self.$resetpost('rs/logic/GenCallInAllPlan', {data: self.checkboxModel}).then((res)=>{
      console.log(res.data)
      self.$showMessage(`预计下发 ${self.checkboxModel.model.count} 个用户，其中${res.data.existitem}个在${self.checkplan.f_plan_name}已存在，新增${res.data.updateitem}个！`)
      self.$emit('finish')
    })
  }
}

let saveGen = function * (self) {
  self.checkboxModel.f_create_time = Util.toStandardTimeString()
  self.checkboxModel.isAll = self.isAll
  self.checkboxModel.f_end_type = '未完成'
  self.checkboxModel.f_plan_type = '偷盗气用户跟进计划'
  self.checkboxModel.f_issued = '否'
  self.checkboxModel.f_filialeids = self.$login.f.f_orgids
  self.checkboxModel.f_orgstr = self.$login.f.orgpathstr
  self.checkboxModel.f_plan_year = self.f_plan_year[0]
  self.checkboxModel.f_plan_month = self.f_plan_month[0]
  self.checkboxModel.f_subcompany = self.$login.f.f_fengongsi
  self.checkboxModel.f_create_operator = self.$login.f.name
  self.checkboxModel.f_effective_start_time = self.f_effective_start_time
  self.checkboxModel.f_effective_end_time = self.f_effective_end_time
  self.checkboxModel.model = self.model
  self.checkboxModel.sqlname = self.sqlname
  self.checkboxModel.nostrids = ''
  // self.checkboxModel.strids = self.areaname
  let f_residential_area = ''
  let street = ''
  let residentialAreaCondtion = ''
  for (let i in self.checkrows) {
    // f_residential_area += `'${self.checkrows[i].f_residential_area}',`
    // if(self.checkrows[i].f_street)
    //   street += `'${self.checkrows[i].f_street}',`
    if(self.checkrows[i].f_residential_area && self.checkrows[i].f_street){
      if(residentialAreaCondtion == ''){
        residentialAreaCondtion += `(f_residential_area = '${self.checkrows[i].f_residential_area}' and f_street = '${self.checkrows[i].f_street}')`
      }else{
        residentialAreaCondtion += `or (f_residential_area = '${self.checkrows[i].f_residential_area}' and f_street = '${self.checkrows[i].f_street}')`
      }

    }else if(self.checkrows[i].f_residential_area){
      if(residentialAreaCondtion == ''){
        residentialAreaCondtion += `(f_residential_area = '${self.checkrows[i].f_residential_area}')`
      }else{
        residentialAreaCondtion += ` or (f_residential_area = '${self.checkrows[i].f_residential_area}')`
      }

    }else if(self.checkrows[i].f_street){
      if(residentialAreaCondtion == ''){
        residentialAreaCondtion += `(f_street = '${self.checkrows[i].f_street}')`
      }else{
        residentialAreaCondtion += ` or (f_street = '${self.checkrows[i].f_street}')`
      }
    }
    console.log('residentialAreaCondtion==>',residentialAreaCondtion)
  }
  self.checkboxModel.residentialAreaCondtion = residentialAreaCondtion
  // self.checkboxModel.f_residential_areas = f_residential_area.slice(0,f_residential_area.length-1)
  // self.checkboxModel.f_streets = street.slice(0,street.length-1)
  // if(self.creatPlanWay == 'single'){
  self.$resetpost('rs/logic/GenCallInPlanByArea', {data: self.checkboxModel}).then((respanse)=>{
    console.log(respanse)
    self.showModal = false
    if(respanse.data.code == 200){
      self.$showMessage("偷盗气用户跟进计划生成成功!")
      self.checkrows = []
      self.checker = {}
      // self.IsShare = '否',
      self.checkboxModel = {}
      self.creatPlanWay = ''
      self.f_effective_start_time = ''
      self.f_effective_end_time = ''
      self.showWait = false
      self.$refs.paged.$refs.criteria.search()
    }else{
      self.$showMessage("偷盗气用户跟进计划生成失败!")
    }
  })
  // }

}

let seachData = function * (self) {
  let getParams = yield self.$resetpost('rs/logic/getSaleInitData', {data: {f_filialeids: self.$login.f.f_orgids}}, {
    resolveMsg: null,
    rejectMsg: '获取营收参数出错！！！'
  })
  console.log('获取营收参数', getParams)
  if (getParams.data) {
    let arr = []
    getParams.data.adjustable.forEach((item, index) => {
      let temp = {}
      temp.label = `[${item.f_adjustable_id}]-${item.f_adjustable_name}`
      temp.value = `${item.id}`
      arr.push(temp)
    })
    self.adjustables = [{label: '全部', value: ''}, ...arr]
  }
}
let select = function* (self) {
  console.log(3)
  let http = new HttpResetClass()
  let getGasman = yield http.load('POST', '/rs/search', {
    source: 'this.getParentByType($organization$).getChildByName($安检员$).getUsers()',
    userid: self.$login.f.id
  }, {resolveMsg: null, rejectMsg: null})
  console.log(4)
  console.log('获取安检员', getGasman)
  getGasman.data.forEach((checker) => {
    self.checkers.push({label: checker.name, value: checker})
  })
}

//   let searchSafeCycle= function* (self){
//     console.log('获取民用非民用安检周期')
//     let http = new HttpResetClass()
//     yield http.load('POST', 'rs/logic/getSafeCheckCycle', {},{resolveMsg: null, rejectMsg: null}).then((res)=>{
//       console.log('安检周期',res.data)
//       if(res.data.code == 200){
//         self.civil = res.data.civil.value
//         self.civilian = res.data.civilian.value
//         self.model.safeCycle = self.civil
//       }else{
//         self.$showMessage(res.data.msg)
//       }
//     })
// }
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('rs/sql/FetchUserFileByArea', 50, {
      orderitem: '"f_residential_area"',
      f_filialeids: 'this.f_filialeids',
      month: 'this.month',
      SafeCheckSX: 'this.SafeCheckSX',
      f_table_state:'this.f_table_state',
      f_data_source:'this.f_data_source',
      // f_last_check_state: 'this.f_last_check_state',
      // f_checktime_start: 'this.f_checktime_start',
      // f_checktime_end:  'this.f_checktime_end',
      // safeCycle: 'this.safeCycle',
      SafeCheckCQ: 'this.SafeCheckCQ',
      SafeCheckSC: 'this.SafeCheckSC',
      f_issue_start: 'this.f_issue_start',
      f_issue_end: 'this.f_issue_end',
      SafeCheckXZ: 'this.SafeCheckXZ',
      f_shouldcheck_start: 'this.f_shouldcheck_start',
      f_shouldcheck_end: 'this.f_shouldcheck_end'
    })
    model.month = ''
    model.f_table_state = ''
    model.f_data_source = '用户档案'
    // model.f_last_check_state = ''
    // model.f_checktime_start = ''
    // model.f_usertype = '家庭'
    // model.f_checktime_end = ''
    // model.safeCycle = ''
    model.SafeCheckCQ = ''   //安检筛选是否超期
    model.SafeCheckSC = '否',    //  安检筛选去除生成标记
      model.f_issue_start = Util.toStartDateYearString(),
      model.f_issue_end = Util.toStandardDateString(),
      // model.SafeCheckXZ = '应安检',  //  安检筛选标记
      model.SafeCheckXZ = '未安检',  //  安检筛选标记
      model.f_shouldcheck_start = Util.toStartDateString(),
      model.f_shouldcheck_end = Util.toEndDateString(),
      // 安检筛选所用时间
      model.SafeCheckSX = {
        f_check_end: '', // 安检时间  查询起始条件
        f_check_start: ''// 安检时间  查询终止条件
      }
    return {
      isAll:'',
      civil:'',   //民用安检周期
      civilian:'',      //非民用安检周期
      // SafeCheckXZs: [{label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'},{label: '应安检', value: '应安检'},{label: '超期安检', value: '超期安检'}], // 安检筛选选项
      SafeCheckXZs: [{label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'}], // 安检筛选选项
      SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''},],
      IsShares: [{label: '是', value: '是'}, {label: '否', value: '否'}],
      tableStates:[{label: '全部', value: ''}, {label: '正常', value: '正常'}, {label: '停用', value: '停用'}],
      dataSources:[{label: '用户档案', value: '用户档案'}, {label: '自建小区', value: '自建小区'}],
      f_meter_brands: [{label:'全部',value:''}],
      is_to_userinfos:[{label: '全部', value: ''},{label: '否', value: 'is null'}, {label: '是', value: 'is not null'}],
      is_reuse_states:[{label: '全部', value: ''},{label: '在用', value: '在用'}],
      is_reuse_state: '在用',
      // IsShare:'否',
      checker: {},
      criteriaShow: true,
      model: model,
      checkers: [],
      chosenOrg: {id: 0},
      showModal: false,
      showCreate:false,
      showWait: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: this.areas(),
      // checkstatus: this.checkstatus(),
      // usertypes: this.usertypes(),
      // userstates: this.userstates(),
      sqlname:'',
      creatPlanWay:'',
      areaname:'',
      f_residential_area:'',
      f_street:''
    }
  },
  props: {
    checkplan: { // 传入一条安检计划信息
      type: Object
    },
    additemshow:{
      type:Boolean,
      default:false
    }
  },
  created () {
    // 请求收费的数据
    this.$LoadSaleParams.loadSaleParams().then(res=>{
      let met = []
      this.$GetSaleParam.getGasbrand().forEach(item=>{
        met.push({label:item.label,value:item.value.f_meter_brand})
      })
      this.f_meter_brands = [{label:'全部',value: ''},...met]
    })
  },
  ready() {
    this.model.chosenOrg = {id: 0}
    console.log(this.$login.f)
    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
    // console.log(0)
    // let param = seachData(this)
    // console.log(1)
    // co(param)
    // console.log(2)
    // let gen = select(this)
    // co(gen)
    // let single = searchSafeCycle(this)
    // co(single)
  },
  methods: {
    itemAddBack(){
      this.$emit('finish')
    },
    itemAdd(val){
      let _gen = AddItem(this,val)
      return co(_gen)
    },
    // 选择安检员
    IsShareschange(val){
      this.IsShare = val
      if(val == '是'){
        this.checker = null
      }
    },
    checkerchange(val) {
      this.checkboxModel.f_checker = val.name
      this.checkboxModel.f_checker_id = val.id
    },
    search(args) {
      this.checkrows = []
      this.checkedAll = false
      // if (this.model.SafeCheckXZ != '未安检') {
      //   if(this.model.SafeCheckXZ == '已安检'){
      //     if(this.$refs.paged.$refs.criteria.model.f_check_start==''||this.$refs.paged.$refs.criteria.model.f_check_end==''){
      //       this.$showMessage("安检时间未选择，请重新选择")
      //       return
      //     }
      //     if(this.model.SafeCheckSC != ''){
      //       if (this.model.f_issue_start != '' || this.model.f_issue_end != '') {
      //       } else {
      //         this.$showMessage("生成时间未选择，请重新选择")
      //         return
      //       }
      //       if(this.model.SafeCheckCQ != ''){
      //         // if(this.model.f_usertype == ''){
      //         //   this.$showMessage('请选择用户类型')
      //         //   return
      //         //   if(this.model.safeCycle == ''){
      //         //     this.$showMessage('请配置安检周期')
      //         //     return
      //         //   }
      //         // }
      //       }
      //     }
      //   }else{
      //     if(this.model.SafeCheckXZ == '应安检'){
      //       if(this.model.f_shouldcheck_start == ''){
      //         this.$showMessage("应检起始时间未选择,请重新选择")
      //         return
      //       }
      //       if(this.model.f_shouldcheck_end == ''){
      //         this.$showMessage("应检结束时间未选择,请重新选择")
      //         return
      //       }
      //     }
      //     // if(this.model.f_usertype == ''){
      //     //   this.$showMessage('请选择用户类型')
      //     //   return
      //     //   if(this.model.safeCycle == ''){
      //     //     this.$showMessage('请配置安检周期')
      //     //     return
      //     //   }
      //     // }
      //     if(this.model.SafeCheckSC != ''){
      //       if (this.model.f_issue_start != '' || this.model.f_issue_end != '') {
      //       } else {
      //         this.$showMessage("生成时间未选择，请重新选择")
      //         return
      //       }
      //     }
      //   }
      //   this.sqlname = 'ByOrgChecker'
      //   console.log('查询结束')
      //   this.model.url = 'rs/sql/根据安检员查询小区档案'
      // } else {
      //   this.sqlname = 'ByOrgNoRuHuSXQ'
      //   if (this.model.SafeCheckSX.f_check_end != '' || this.model.SafeCheckSX.f_check_start != '') {
      //   } else {
      //     this.$showMessage("安检时间未选择，请重新选择")
      //     return
      //   }
      //   if(this.model.SafeCheckCQ != ''){
      //     if(this.model.SafeCheckSX.f_check_start == ''){
      //       this.$showMessage("安检起始时间未选择,请重新选择")
      //       return
      //     }
      //     if(this.model.SafeCheckSX.f_check_end == ''){
      //       this.$showMessage("安检结束时间未选择,请重新选择")
      //       return
      //     }
      //     // if (this.model.f_usertype == ''){
      //     //   this.$showMessage("用户类型未选择,请重新选择")
      //     //   return
      //     // }
      //   }
      //   // if (this.SafeCheckSC == '是') {
      //   //   this.model.url = 'rs/sql/FetchUserFileByOrgNoRuHuSX'
      //   // } else if (this.SafeCheckSC == '否') {
      //     // this.model.url = 'rs/sql/FetchUserFileByOrgNoSafeSX'
      //   // } else {
      //   this.model.url = 'rs/sql/FetchUserFileByOrgNoRuHuSXQByArea'
      //   // }
      // }
      if (this.model.f_data_source == '自建小区'){
        this.model.url = 'rs/sql/FetchCreateAreaByOrgCheckerByArea'
      }
      if (this.model.f_data_source == '用户档案'){
        this.model.url = 'rs/sql/FetchUserFileByArea'
        args.condition+="and ui.f_promise_user='是'"
      }
      if (this.is_reuse_state == '在用') {
        args.condition += ` and (( ui.f_second_state is null and f_user_state != '弃用')  or (ui.f_second_state is not null and uf.f_meternumber is not null)) `
      }
      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
    },
    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
      //   }
      // }
      this.showWait = true
      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_residential_area == this.checkrows[i].f_residential_area) {
            this.checkrows.splice(i, 1)
          }
        }
      }
    },
    ToshowModal(f_residential_area) {
      this.areaname=f_residential_area
      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.isAll = 'all'
      this.showModal = true
    },
    cancel() {
      this.showModal = false
    },
    // areas() {
    //   console.log('登陆人信息',this.$login.f)
    //   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]
    },
    CreadteArea(){
      this.showCreate = true
    },
    confirmCreate(){
      if(this.f_residential_area || this.f_street){
        let row = {
          f_residential_area : this.f_residential_area,
          f_street : this.f_street
        }
        this.$resetpost('rs/entity/t_create_area', row).then((res) => {
          console.log('res...===??..,,///]]]===---000999>',res)
          this.$showMessage('新增成功')
          this.model.url = 'rs/sql/FetchCreateAreaByOrgCheckerByArea'
          this.$refs.paged.$refs.criteria.search()
          this.showCreate = false
        })
      }

    },
    cancelCreate(){
      this.showCreate = false
    },
    addBuilding(){

    }
  },

  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>
