<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">用户编号</label>
              <input type="text" class="form-control" v-model="model.f_userinfo_code" id="f_userinfo_code" style="height:34px;margin-top: 8px"
                     placeholder="用户编号" condition="ui.f_userinfo_code like '{}%'">
            </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_user_name" id="f_user_name" style="height:34px;margin-top: 8px"
                     placeholder="用户名称" condition="f_user_name like '{}%'">
            </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_meter_number" id="f_meter_number" style="height:34px;margin-top: 8px"
                     placeholder="表号" condition="f_meternumber like '{}%'">
            </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" id="f_card_id" style="height:34px;margin-top: 8px"
                     placeholder="卡号" condition="f_card_id like '{}%'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">小区id</label>
              <input type="text" class="form-control" v-model="model.oldareaid" id="oldareaid" style="height:34px;margin-top: 8px"
                     placeholder="小区" condition="ua.oldareaid = '{}'">
            </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_residential_area" id="f_residential_area" style="height:34px;margin-top: 8px"
                     placeholder="小区" condition="ua.f_residential_area = '{}'">
            </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="ua.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" id="f_unit" style="height:34px;margin-top: 8px"
                     placeholder="小区" condition="ua.f_unit = '{}'">
            </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_floor" id="f_floor" style="height:34px;margin-top: 8px"
                     placeholder="小区" condition="ua.f_floor  = '{}'">
            </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_room" id="f_room" style="height:34px;margin-top: 8px"
                     placeholder="小区" condition="ua.f_room 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_address" id="f_address" style="height:34px;margin-top: 8px"
                     placeholder="地址" condition="ua.f_address 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="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" id="f_unit" style="height:34px;margin-top: 8px"
                     placeholder="单元" condition="f_unit = '{}%'">
            </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_floor" id="f_floor" style="margin-top: 8px"
                     placeholder="楼层" condition="f_floor 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_floor" id="f_floor" style="margin-top: 8px"
                     placeholder="门牌" condition="f_room like '%{}%'">
            </div>-->
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">行政区域</label>
              <v-select style="margin-top: 8px"
                        :value.sync="model.f_distinct"
                        v-model="model.f_distinct"
                        :options="$parent.$parent.getparams('行政区域')"
                        placeholder='行政区域'
                        condition="ui.f_distinct = '{}'"
                        close-on-select>
              </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_main_customers"
                        placeholder='重点用户' style="margin-top: 8px"
                        :value.sync="model.f_main_customers"
                        :value-single="true"
                        :options="$parent.$parent.getparams('重点用户')"
                        v-model="model.f_main_customers"
                        condition="f_main_customers = '{}'"
                        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_gasproperties"
                        placeholder='用气性质' style="margin-top: 8px"
                        :value.sync="model.f_gasproperties"
                        :value-single="true"
                        :options="$parent.$parent.getparams('用气性质')"
                        v-model="model.f_gasproperties"
                        condition="uf.f_gasproperties = '{}'"
                        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_meter_classify"
                        placeholder='气表类型' style="margin-top: 8px"
                        :value.sync="model.f_meter_classify"
                        :value-single="true"
                        :options="$parent.$parent.getparams('气表类型')"
                        v-model="model.f_meter_classify"
                        condition="f_meter_classify = '{}'"
                        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_meter_brand"
                        placeholder='气表品牌' style="margin-top: 8px"
                        :value.sync="model.f_meter_brand"
                        :value-single="true"
                        :options="$parent.$parent.f_meter_brands"
                        v-model="model.f_meter_brand"
                        condition="gb.f_meter_brand = '{}'"
                        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>
              <input type="text" class="form-control" v-model="model.start_no" id="start_no" style="height:34px;margin-top: 8px"
                     placeholder="开始卡号" condition="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.end_no" id="end_no" style="height:34px;margin-top: 8px"
                     placeholder="结束卡号" condition="f_userinfo_code <= {}">
            </div>-->
            <div class="col-sm-4 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.is_reuse_state"
                        :options='$parent.$parent.is_reuse_states'
                        v-model="model.is_reuse_state"
                        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>
              <input type="text" class="form-control" v-model="model.check_diff" id="check_diffcheck_diff" style="height:34px;margin-top: 8px"
                     placeholder="未安检时间>=">
            </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.gas_diff" id="gas_diff" style="height:34px;margin-top: 8px"
                     condition="TRUNC(MONTHS_BETWEEN(SYSDATE, f_meteread_date))>={}"
                     placeholder="未购气时间>=">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">小区性质</label>
              <v-select id="f_residential_properties"
                        placeholder='小区性质' style="margin-top: 8px"
                        v-model='model.f_residential_properties'
                        :value.sync="model.f_residential_properties"
                        :options="$parent.$parent.getparams('小区性质')"
                        condition="f_residential_properties = '{}'"
                        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>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='最后安检时间起始' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 00:00:00'"
                :show-rest-button="reset"
                condition="cp.f_offsite_time >= '{}'"
                v-model = "model.f_check_start">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">最后安检截止</label>
              <datepicker
                :value.sync="model.f_check_end"
                placeholder='最后安检时间结束' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 23:59:59'"
                :show-rest-button="reset"
                condition="cp.f_offsite_time <= '{}'"
                v-model = "model.f_check_end">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">最后安检状态</label>
              <v-select id="f_entry"
                        placeholder='安检状态'
                        :value.sync="model.f_last_check_state"
                        :value-single="true" style="margin-top: 8px"
                        :options="$parent.$parent.getparams('安检状态')"
                        v-model="model.f_last_check_state"
                        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>
              <datepicker
                :value.sync="model.f_create_start"
                placeholder='建档起始' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 00:00:00'"
                :show-rest-button="reset"
                condition="F_CREATEFILE_DATE >= to_date('{}','yyyy-mm-dd hh24:mi:ss')"
                v-model = "model.f_create_start">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">建档截止</label>
              <datepicker
                :value.sync="model.f_create_end"
                placeholder='建档截止' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 23:59:59'"
                :show-rest-button="reset"
                condition="F_CREATEFILE_DATE <= to_date('{}','yyyy-mm-dd hh24:mi:ss')"
                v-model = "model.f_create_end">
              </datepicker>
            </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.FiltrationPlan()" v-if="!$parent.$parent.checkplan">过滤生成</button>-->
                <button type="button" class="button_export button_spacing" @click="$parent.$parent.itemAddBack()" v-if="$parent.$parent.checkplan">返回</button>
                <button type="button" class="button_export button_spacing" @click="$parent.$parent.itemAdd('single')" v-if="$parent.$parent.checkplan">添加</button>
                <button type="button" class="button_export button_spacing" @click="$parent.$parent.itemAdd('all')" v-if="$parent.$parent.checkplan">批量添加</button>
                <button class="btn" @click="$parent.$parent.hidden()">
                  <span class="glyphicon glyphicon-chevron-up"></span>
                </button>
              </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>
          </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>全选<input type="checkbox" @click='$parent.$parent.$parent.changeStates'  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><nobr>重点用户</nobr></th>
            <th><nobr>用气性质</nobr></th>
            <th><nobr>气表类型</nobr></th>
            <th><nobr>气表品牌</nobr></th>
            <th><nobr>街道</nobr></th>
            <th><nobr>小区名称</nobr></th>
            <th><nobr>地址</nobr></th>
            <th><nobr>最后安检日期</nobr></th>
            <th><nobr>最后安检状态</nobr></th>
            <th><nobr>建档日期</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center"><nobr><input type="checkbox" v-model="row.checked" v-bind:checked="row.checked"  @click="$parent.$parent.$parent.addChecked(row)"></nobr></td>
          <td style="text-align: center;">{{row.f_userinfo_code}}</td>
          <td style="text-align: center;">{{row.f_user_name}}</td>
          <td style="text-align: center;">{{row.f_user_phone}}</td>
          <td  style="text-align: center">{{row.f_user_type}}</td>
          <td  style="text-align: center">{{row.f_card_id}}</td>
          <td  style="text-align: center">{{row.f_meternumber}}</td>
          <td  style="text-align: center">{{row.f_main_customers}}</td>
          <td  style="text-align: center">{{row.f_gasproperties}}</td>
          <td  style="text-align: center">{{row.f_meter_classify}}</td>
          <td  style="text-align: center">{{row.f_meter_brand}}</td>
          <td  style="text-align: center">{{row.f_street}}</td>
          <td style="text-align: center">{{row.f_residential_area}}</td>
          <td style="text-align: center">{{row.f_address}}</td>
          <td style="text-align: center">{{row.f_offsite_time}}</td>
          <td style="text-align: center">{{row.f_entry_status}}</td>
          <td style="text-align: center">{{row.f_createfile_date}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</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 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.f_plan_type = self.checkboxModel.f_checker?'工商预约安检':'工商集中安检'
    self.checkboxModel.f_plan_type = '重点用户查询跟进'
    self.checkboxModel.f_issued = '否'
    self.checkboxModel.f_end_type = '未完成'
    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 = ''
    var strids = ''
    for (var i in self.checkrows) {
      console.log("self.checkrows[i].f_userinfo_id",self.checkrows[i].f_userinfo_id)
      strids += `'${self.checkrows[i].f_userinfo_id}',`
    }
    self.checkboxModel.strids = strids.slice(0,strids.length-1)
    if(self.creatPlanWay == 'single'){
      yield self.$resetpost('rs/logic/imp_user_GenCallInPlan', {data: self.checkboxModel}).then((respanse)=>{
        console.log(respanse)
        self.showModal = false
        if(respanse.data.code == 200){
          self.$showMessage("重点用户跟进计划生成成功!")
          self.checkrows = []
          self.checker = null
          self.IsShare = '是',
            self.checkboxModel = {}
          self.creatPlanWay = ''
          self.f_effective_start_time = ''
          self.f_effective_end_time = ''
          self.$refs.paged.$refs.criteria.search()
        }else{
          self.$showMessage("重点用户跟进计划生成失败!")
        }
      })
    }else{
      if(self.creatPlanWay == 'filtration'){
        self.checkboxModel.nostrids = self.checkboxModel.strids
      }
      self.checkboxModel.planWay = 'create'
      yield self.$resetpost('rs/logic/imp_user_GenCallInAllPlan', {data: self.checkboxModel}).then((respanse)=>{
        console.log(respanse)
        self.showModal = false
        if(respanse.data.code == 200){
          self.$showMessage("重点用户跟进计划生成成功!")
          self.checkrows = []
          self.creatPlanWay = ''
          self.checker = null
          self.IsShare = '是',
          self.checkboxModel = {}
          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})
      self.checkerList.push({label: checker.name, value: checker.name})
    })
  }

  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/imp_FetchUserFileByOrgChecker', 50, {
        orderitem: '"f_residential_area,f_address"',
        con2: 'this.con2'
      })
      return {
        civil:'',   //民用安检周期
        civilian:'',      //非民用安检周期
        SafeCheckXZs: [{label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'},{label: '应安检', value: '应安检'},{label: '超期安检', value: '超期安检'}], // 安检筛选选项
        SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''},],
        IsShares: [{label: '是', value: '是'}],
        is_reuse_states: [{label: '全部', value: ''}, {label: '在用', value: '在用'}],
        IsShare:'是',
        checker: {},
        criteriaShow: true,
        model: model,
        checkers: [],
        checkerList:[{label:'全部',value:''}],
        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: this.areas(),
        checkstatus: this.checkstatus(),
        usertypes: this.usertypes(),
        userstates: this.userstates(),
        sqlname:'',
        creatPlanWay:'',
        f_meter_brands: []
      }
    },
    props: {
      checkplan: { // 传入一条安检计划信息
        type: Object
      },
      additemshow:{
        type:Boolean,
        default:false
      }
    },
    ready() {
      this.model.f_filiale = this.$login.f.f_fengongsi
      this.model.f_OrgStr = this.$login.f.orgpathstr
      this.$refs.paged.$refs.criteria.model.is_reuse_state = '在用'
    },
    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]
      })
    },
    methods: {
      selChecker(row){
        console.log(row)
        this.model.model.f_inputtor=row
      },
      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
        args.condValue = '1=1'
        if(this.$refs.paged.$refs.criteria.model.is_reuse_state === '在用'){
          args.condition += ` and (( ui.f_second_state is null and uf.f_table_state != '弃用')  or (ui.f_second_state is not null and uf.f_meternumber is not null)) `
        }
        if (args.model.check_diff){
          this.$showMessage('未安检时间筛选出的结果只查最后一次入户!!!')
          args.condValue += ` and TO_DATE(NVL(f_offsite_time, '1990-01-01 00:00:00'), 'YYYY-MM-DD HH24:MI:SS') >= TO_DATE('${args.model.check_diff}', 'YYYY-MM-DD')`
          args.condition += ` and TO_DATE(NVL(f_offsite_time, '1990-01-01 00:00:00'), 'YYYY-MM-DD HH24:MI:SS') >= TO_DATE('${args.model.check_diff}', 'YYYY-MM-DD')`
          args.model.f_last_check_state = '入户'
          this.$refs.paged.$refs.criteria.model.f_last_check_state = '入户'
        }
        if (args.model.f_last_check_state){
          args.condValue += ` and  f_entry_status = '${args.model.f_last_check_state}'`
          args.condition += ` and  cp.f_entry_status = '${args.model.f_last_check_state}'`
        }
        /*if(this.$refs.paged.$refs.criteria.model.gas_diff){
          this.model.con2 += ` and gas_diff>=${this.$refs.paged.$refs.criteria.model.gas_diff}`
        }
        if(this.$refs.paged.$refs.criteria.model.check_diff){
          this.model.con2 += ` and check_diff>=${this.$refs.paged.$refs.criteria.model.check_diff}`
        }*/
        /* 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/FetchUserFileByOrgNoRuHuSXQ'
          // }
        }*/
        this.model.search(args.condition, args.model, args.condValue)
      },
      getparams(data) {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam(data)]
      },
      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.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.showModal = false
      },
      areas() {
        console.log(this.$login.f.f_allArea,'片区')
        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
        }else{
          this.checkboxModel.f_checker = null
          this.checkboxModel.f_checker_id = null
        }
      },
      '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
      },
      getCondition () {
        return {
          condition: this.model.condition,
          con2: this.model.con2
        }
      },
      getfield () {
        let Config = {
          'f_card_id': '卡号',
          'f_meternumber': '表号',
          'f_user_name': '用户名称',
          'f_user_phone': '用户电话',
          'f_address': '档案地址',
          'oldareaid': '小区编号',
          'f_residential_area': '小区地址',
          'f_distinct': '行政区域',
          'f_user_state': '用户状态',
          'f_table_state': '气表状态',
          'f_user_type': '用户类型',
          "f_opera_area": "运营区域",
          "f_gasproperties": "用气性质",
        }
        return Config
      }
    }
  }
</script>
<style scoped>
  .newcolor{
    color:red;
  }
  .table th{
    background-color: #f2f6fa;
    color: black;
  }
</style>
