<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="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">街&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="ua.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_address" id="f_address"
                     style="height:34px;margin-top: 8px"
                     placeholder="地址" condition="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 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_unit" id="f_unit" style="height:34px;margin-top: 8px"
                                 placeholder="单元" condition="f_unit 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_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>
              <v-select style="margin-top: 8px"
                        :value.sync="model.f_area"
                        v-model="model.f_area"
                        :options='$parent.$parent.areas'
                        placeholder='片区/管理站'
                        condition="f_slice_area like '%{}%'"
                        close-on-select>
              </v-select>
            </div>
            <!--            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
                          <label class="control-label">调&nbsp;&nbsp;压&nbsp;箱</label>
                          <v-select :value.sync="model.f_adjustable_id" :options='$parent.$parent.adjustables' placeholder='调压箱' close-on-select
                                    style="margin-top: 8px"   v-model='model.f_adjustable_id'   condition="ui.f_adjustable_id = '{}'" :search='true'></v-select>
                        </div>-->
            <!--            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
                          <label class="control-label">用户类型</label>
                          <v-select id="f_usertype"
                                    placeholder='用户类型' style="margin-top: 8px"
                                    :value.sync="$parent.$parent.model.f_usertype"
                                    :value-single="true"
                                    :options='$parent.$parent.usertypes'
                                    v-model="$parent.$parent.model.f_usertype"
                                    close-on-select clear-button> </v-select>
                        </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_checktime_start"-->
            <!--placeholder='应检时间起始'-->
            <!--:disabled-days-of-week="[]"-->
            <!--:format="'yyyy-MM-dd 00:00:00'"-->
            <!--:show-rest-button="reset"-->
            <!--v-model = "$parent.$parent.model.f_checktime_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_checktime_end"-->
            <!--placeholder='应检时间结束'-->
            <!--:disabled-days-of-week="[]"-->
            <!--:format="'yyyy-MM-dd 23:59:59'"-->
            <!--:show-rest-button="reset"-->
            <!--v-model = "$parent.$parent.model.f_checktime_end">-->
            <!--</datepicker>-->
            <!--</div>-->
            <!--            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
                          <label class="control-label" style="color: red;">安检筛选</label>
                          <v-select
                            placeholder='安检筛选'
                            :value-single="true" style="margin-top: 8px"
                            :value.sync="$parent.$parent.model.SafeCheckXZ"
                            :options='$parent.$parent.SafeCheckXZs'
                            v-model="$parent.$parent.model.SafeCheckXZ"
                            close-on-select clear-button> </v-select>
                        </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>-->
            <!--<v-select-->
            <!--placeholder='是否超期'-->
            <!--:value-single="true"-->
            <!--:value.sync="$parent.$parent.model.SafeCheckCQ"-->
            <!--:options='$parent.$parent.SafeCheckSXs'-->
            <!--v-model="$parent.$parent.model.SafeCheckCQ"-->
            <!--close-on-select clear-button> </v-select>-->
            <!--</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="model.f_check_start"
                            placeholder='最后安检时间起始' style="margin-top: 8px"
                            :disabled-days-of-week="[]"
                            :format="'yyyy-MM-dd'"
                            :show-rest-button="reset"
                            v-model = "model.f_check_start"
                            condition="nvl(f_last_check_date,f_createfile_date) > ='{} 00:00:00'">
                          </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="model.f_check_end"
                            placeholder='最后安检时间结束'
                            :disabled-days-of-week="[]"
                            :format="'yyyy-MM-dd'" style="margin-top: 8px"
                            :show-rest-button="reset"
                            v-model = "model.f_check_end"
                            condition="nvl(f_last_check_date,f_createfile_date) <=  '{} 23:59:59'">
                          </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>
              <v-select id="f_entry"
                        placeholder='安检状态'
                        :value.sync="$parent.$parent.model.f_last_check_state"
                        :value-single="true" style="margin-top: 8px"
                        :options='$parent.$parent.checkstatus'
                        v-model="$parent.$parent.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%"  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%">
              <label class="control-label">是否生成</label>
              <v-select
                placeholder='是否已生成'
                :value-single="true" style="margin-top: 8px"
                :value.sync="$parent.$parent.model.SafeCheckSC"
                :options='$parent.$parent.SafeCheckSXs'
                v-model="$parent.$parent.model.SafeCheckSC"
                close-on-select clear-button></v-select>
            </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.SafeCheckSX.f_check_start"
                placeholder='最后安检时间起始' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 00:00:00'"
                :show-rest-button="reset"
                v-model="$parent.$parent.model.SafeCheckSX.f_check_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.SafeCheckSX.f_check_end"
                placeholder='最后安检时间结束' style="margin-top: 8px"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd 23:59:59'"
                :show-rest-button="reset"
                v-model="$parent.$parent.model.SafeCheckSX.f_check_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 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_usegas_area" id="f_usegas_area"
                     style="height:34px;margin-top: 8px"
                     placeholder="用气区域" condition="f_usegas_area = '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">用&ensp;气&ensp;点</label>
              <input type="text" class="form-control" v-model="model.f_usegas_point" id="f_usegas_point"
                     style="height:34px;margin-top: 8px"
                     placeholder="用气点" condition="f_usegas_point = '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">安&ensp;检&ensp;员</label>
              <v-select id="checker" v-model="model.f_inputtor"
                        :value.sync="model.f_inputtor"
                        :value-single="true"
                        placeholder="安检员" :options='$parent.$parent.checkerList'
                        condition="f_inputtor = '{}'" 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.f_residential_area" id="f_residential_area"
                     style="height:34px;margin-top: 8px"
                     placeholder="单位名称" condition="f_residential_area = '{}'">
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">表具现状</label>
              <v-select :value.sync="model.f_meter_state" v-model="model.f_meter_state"
                        :options='$parent.$parent.tableStates' placeholder='表具现状'
                        condition="f_meter_state in {} "
              ></v-select>
            </div>
            <!--<div class="col-sm-6  form-group form-fix-width">-->
            <!--<label class="control-label">安检员</label>-->
            <!--<v-select id="checker"-->
            <!--placeholder='是否已生成'-->
            <!--:value.sync="model."-->
            <!--v-on:change="$parent.$parent.checkerchange" :value-single="true"-->
            <!--:options='$parent.$parent.checkers' close-on-select clear-button> </v-select>-->
            <!--</div>-->
            <!--</div>-->
            <!-- <chooser :userid.sync='$parent.$parent.$parent.f.id' resource-type="user" :width='300' :select-data.sync='$parent.$parent.model.chosenOrg'></chooser> -->
            <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>
            <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 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.f_user_type }}</td>
          <td v-bind:class="{newcolor:row.code=='1'}" style="text-align: center">{{ row.f_card_id }}</td>
          <td v-bind:class="{newcolor:row.code=='1'}" style="text-align: center">{{ row.f_meternumber }}</td>
          <td v-bind:class="{newcolor:row.code=='1'}" style="text-align: center">{{ row.f_usegas_area }}</td>
          <td v-bind:class="{newcolor:row.code=='1'}" style="text-align: center">{{ row.f_usegas_point }}</td>
          <td v-bind:class="{newcolor:row.code=='1'}" style="text-align: center">{{ row.f_inputtor }}</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_residential_area }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_building }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_unit }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_floor }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_room }}</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_last_check_date }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_last_check_state }}</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 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.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/busi_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/busi_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/ic_FetchUserFileByOrgChecker', 50, {
      orderitem: '"f_residential_area,f_address"',
      f_filialeids: 'this.f_filialeids',
      month: 'this.month',
      SafeCheckSX: 'this.SafeCheckSX',
      f_usertype: 'this.f_usertype',
      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_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.f_shouldcheck_start = Util.toStartDateString(),
      model.f_shouldcheck_end = Util.toEndDateString(),
      // 安检筛选所用时间
      model.SafeCheckSX = {
        f_check_end: '', // 安检时间  查询起始条件
        f_check_start: ''// 安检时间  查询终止条件
      }
    return {
      civil: '',   //民用安检周期
      civilian: '',      //非民用安检周期
      SafeCheckXZs: [{label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'}, {
        label: '应安检',
        value: '应安检'
      }, {label: '超期安检', value: '超期安检'}], // 安检筛选选项
      SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''},],
      IsShares: [{label: '是', value: '是'}],
      IsShare: '是',
      checker: {},
      criteriaShow: true,
      model: model,
      checkers: [],
      checkerList: [{label: '全部', value: ''}],
      tableStates: [{label: '全部', value: ''},{label: '已拆', value: '已拆'}, {label: '关门', value: '关门'}, {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: ''
    }
  },
  props: {
    checkplan: { // 传入一条安检计划信息
      type: Object
    },
    additemshow: {
      type: Boolean,
      default: false
    }
  },
  ready() {
    console.log(this.$login.f.f_allArea, '片区')
    this.model.chosenOrg = {id: 0}
    console.log(this.$login.f)
    this.model.f_filialeids = ''
    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: {
    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.condition = `${args.condition} And f_special is not null`
      console.log(this.model)
      /* 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)
    },
    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
    }
  }
}
</script>
<style scoped>
.newcolor {
  color: red;
}

.table th {
  background-color: #f2f6fa;
  color: black;
}
</style>
