<template>
  <div class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row" v-show="!$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">模糊查询</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_userinfo"
                     id="f_userinfo"
                     placeholder="编号 名称 电话 表号 地址"
                     condition="(f_userinfo_code like '%{}%' or f_user_name like '%{}%' or f_user_phone like '%{}%' or f_meternumber like '%{}%' or f_address like '%{}%' or f_zuhu_phone like '%${}%' or f_rent_phone like '%${}%')">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户编号</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_userinfo_code"
                     id="f_userinfo_code"
                     placeholder="用户编号" condition="f_userinfo_code like '%{}%'">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户姓名</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_user_name" id="f_user_name"
                     placeholder="用户姓名" condition="f_user_name like '%{}%'">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">小&emsp;&emsp;区</label>
              <v-select id="f_residential_area"
                        placeholder='小区'
                        class="select select_list"
                        :value.sync="model.f_residential_area"
                        :options='$parent.$parent.residentialareas'
                        :multiple='true'
                        v-model="model.f_residential_area"
                        condition="f_residential_area in {}"
                        ></v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">地&emsp;&emsp;址</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_address" id="f_address"
                     placeholder="地址" condition="f_address like '%{}%'">
            </div>
            <div :class="$parent.$parent.style" style="width: auto;margin-top:8px;float: right">
              <export-excel-safe
                                 v-if="$parent.$parent.excelStart"
                                 :data="$parent.$parent.searchData"
                                 :field="$parent.$parent.excelHeaders"
                                 :choose-col="true"
                                 sqlurl="rs/logic/SafeExportExcel" sql-name="根据安检员查询用户档案"
                                 template-name='用户安检情况'></export-excel-safe>
              <button type="button" class="button_search button_spacing" @click="search()">查询</button>
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                   @click="$parent.$parent.hiddenr()"></div>
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                   @click="$parent.$parent.hidden()">

              </div>
            </div>


          </div>
          <div class="row" v-show="!$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">用户类型</label>
              <v-select id="f_usertype"
                        placeholder='用户类型'
                        class="select select_list"
                        :value.sync="model.f_usertype"
                        :value-single="true"
                        :options='$parent.$parent.usertypes'
                        v-model="model.f_usertype"
                        condition="f_user_type = '{}'"
                        close-on-select clear-button></v-select>
            </div>
            <!--            <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow && !$parent.$parent.$parent.showItem"></div>-->

            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body" style="color: red;">安检筛选</label>
              <v-select
                placeholder='安检筛选'
                :value-single="true"
                class="select select_list"
                :value.sync="$parent.$parent.SafeCheckXZ"
                :options='$parent.$parent.SafeCheckXZs'
                v-model="$parent.$parent.SafeCheckXZ"
                close-on-select clear-button></v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检起始</label>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='最后安检时间起始'
                style="width: 60%"
                :format="'yyyy-MM-dd 00:00:00'"
                :show-rest-button="reset"
                v-model="model.f_check_start">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检结束</label>
              <datepicker
                :value.sync="model.f_check_end"
                placeholder='最后安检时间结束'
                style="width: 60%"
                :format="'yyyy-MM-dd 23:59:59'"
                :show-rest-button="reset"
                v-model="model.f_check_end">
              </datepicker>
            </div>

            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检状态</label>
              <v-select id="f_entry"
                        placeholder='安检状态'
                        :multiple="true"
                        class="select select_list"
                        :value.sync="$parent.$parent.checkStates"
                        :options='$parent.$parent.checkstatus'
                        ></v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">隐患情况</label>
              <v-select
                placeholder='隐患情况'
                class="select select_list"
                :value-single="true"
                v-model='model.f_check_result'
                :value.sync="model.f_check_result"
                :options='$parent.$parent.f_check_results'
                condition="f_defect_content  like '%{}%'"
                close-on-select clear-button></v-select>
            </div>
            <!--            <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow && !$parent.$parent.$parent.showItem"></div>-->
          </div>
          <div class="row" v-show="!$parent.$parent.$parent.showItem">

            <div class="col-sm-4 form-group" v-show="$parent.$parent.criteriaShow" style="margin: 0">
              <role-selector-safe
                role-name="安检员"
                role-lable="安&nbsp;检&nbsp;员&nbsp;"
                @re-res="$parent.$parent.getRes"
                :value.sync="model.f_checker_id"
                v-model="model.f_checker_id"
                :value-multiple="true"
                condition=" f_checker_name in {}">
              </role-selector-safe>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
            <label class="font_normal_body">片&emsp;&emsp;区</label>
            <v-select class="select_list select"
                      placeholder='片区/管理站' style="width: 60%"
                      :value.sync="model.f_slice_area" v-model="model.f_slice_area"
                      :options='$parent.$parent.sliceArea'
                      filer-key="name"
                      close-on-select clear-button
                      condition="f_slice_area='{}'"
                      @change="$parent.$parent.getmeterbook(model.f_slice_area)"
                      :value-single="true">
            </v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">抄&ensp;表&ensp;册</label>
              <v-select class="select_list select"
                        placeholder='抄表册' style="width: 60%"
                        :value.sync="model.f_meter_book_num" v-model="model.f_meter_book_num"
                        :options='$parent.$parent.cbc'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_meter_book_num={}"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">省&ensp;市&ensp;区</label>
              <v-select class="select_list select"
                        placeholder='请选择' style="width: 60%"
                        :value.sync="model.f_pcd" v-model="model.f_pcd"
                        :options='$parent.$parent.pcds'
                        filer-key="name"
                        close-on-select clear-button
                        condition="f_pcd='{}'"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">用户状态</label>
              <v-select class="select_list select"
                        placeholder='用户状态' style="width: 60%"
                        :value.sync="model.f_user_state" v-model="model.f_user_state"
                        :options='$parent.$parent.userstates'
                        close-on-select clear-button
                        condition="f_user_state = '{}'"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">首次通气开始</label>
              <datepicker
                :value.sync="model.f_gas_start"
                placeholder='首次通气开始'
                :disabled-days-of-week="[]"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_gas_start"
                condition="f_uservent_date  >= '{}'"
              >
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">首次通气结束</label>
              <datepicker
                :value.sync="model.f_gas_end"
                placeholder='首次通气结束'
                style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                condition="f_uservent_date  <= '{}'"
                v-model="model.f_gas_end">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">建档起始</label>
              <datepicker
                :value.sync="model.f_createfile_start"
                placeholder='建档时间起始'
                :disabled-days-of-week="[]"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_createfile_start"
                condition="f_createfile_date  >= '{}'"
              >
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">建档结束</label>
              <datepicker
                :value.sync="model.f_createfile_end"
                placeholder='建档时间结束'
                style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                condition="f_createfile_date  <= '{}'"
                v-model="model.f_createfile_end">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安&ensp;检&ensp;册</label>
              <v-select id="f_check_book_name"
                        placeholder='安检册'
                        class="select select_list"
                        :value.sync="model.f_check_book_name"
                        :options='$parent.$parent.checkbooknames'
                        :multiple='true'
                        v-model="model.f_check_book_name"
                        condition="f_check_book_name in {}"
              ></v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">用气性质</label>
              <v-select class="select_list select"
                        placeholder='用气性质' style="width: 60%"
                        :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                        :options='$parent.$parent.gasproperties'
                        close-on-select clear-button
                        condition="f_gasproperties = '{}'"
                        :value-single="true">
              </v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">表具状态</label>
              <v-select class="select_list select"
                        placeholder='表具状态' style="width: 60%"
                        :value.sync="model.f_table_state" v-model="model.f_table_state"
                        :options='$parent.$parent.table_states'
                        close-on-select clear-button
                        condition="f_table_state = '{}'"
                        :value-single="true">
              </v-select>
            </div>
          </div>

          <div class="row" v-show="$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户编号</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_userinfo_code"

                     placeholder="用户编号" condition="f_userinfo_code like '%{}%'">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户姓名</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_user_name"
                     placeholder="用户姓名" condition="f_user_name like '%{}%'">
            </div>
            <div :class="$parent.$parent.style" style="width: auto;margin-top:8px;float: right">
              <export-excel-safe :data="$parent.$parent.searchData"
                                 :field="$parent.$parent.excelHeaders"
                                 sqlurl="rs/logic/SafeExportExcel" sql-name="根据安检员查询用户档案"
                                 template-name='用户安检情况'></export-excel-safe>
              <button type="button" class="button_search button_spacing" @click="search()">查询</button>
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                   @click="$parent.$parent.hiddenr()"></div>
              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                   @click="$parent.$parent.hidden()">

              </div>
            </div>

          </div>
          <div class="row" v-show="$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">地&emsp;&emsp;址</label>
              <input style="width: 60%" type="text" class="input_search" v-model="model.f_address"

                     placeholder="地址" condition="f_address like '%{}%'">
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">用户类型</label>
              <v-select
                placeholder='用户类型'
                class="select select_list"

                :value.sync="model.f_usertype"
                :value-single="true"
                :options='$parent.$parent.usertypes'
                v-model="model.f_usertype"
                condition="f_user_type = '{}'"
                close-on-select clear-button></v-select>
            </div>
            <!--            <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow && !$parent.$parent.$parent.showItem"></div>-->

            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body" style="color: red;">安检筛选</label>
              <v-select
                placeholder='安检筛选'
                :value-single="true"

                class="select select_list"
                :value.sync="$parent.$parent.SafeCheckXZ"
                :options='$parent.$parent.SafeCheckXZs'
                v-model="$parent.$parent.SafeCheckXZ"
                close-on-select clear-button></v-select>
            </div>

          </div>
          <div class="row" v-show="$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检起始</label>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='最后安检时间起始'
                :disabled-days-of-week="[]"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_check_start">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检结束</label>
              <datepicker
                :value.sync="model.f_check_end"
                placeholder='最后安检时间结束'
                style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_check_end">
              </datepicker>
            </div>

            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">安检状态</label>
              <v-select
                placeholder='安检状态'
                class="select select_list"
                :value.sync="$parent.$parent.checkStates"
                :options='$parent.$parent.checkstatus'
                :multiple="true"
                close-on-select clear-button></v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">隐患情况</label>
              <v-select
                placeholder='隐患情况'
                class="select select_list"
                :value-single="true"
                v-model='model.f_check_result'
                :value.sync="model.f_check_result"
                :options='$parent.$parent.f_check_results'
                condition="f_defect_content  like '%{}%'"
                close-on-select clear-button></v-select>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">首次通气开始</label>
              <datepicker
                :value.sync="model.f_gas_start"
                placeholder='首次通气开始'
                :disabled-days-of-week="[]"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_gas_start"
                condition="f_uservent_date  >= '{}'"
              >
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">首次通气结束</label>
              <datepicker
                :value.sync="model.f_gas_end"
                placeholder='首次通气结束'
                style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                condition="f_uservent_date  <= '{}'"
                v-model="model.f_gas_end">
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">建档起始</label>
              <datepicker
                :value.sync="model.f_createfile_start"
                placeholder='建档时间起始'
                :disabled-days-of-week="[]"
                style="width: 60%"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_createfile_start"
                condition="f_createfile_date  >= '{}'"
              >
              </datepicker>
            </div>
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">建档结束</label>
              <datepicker
                :value.sync="model.f_createfile_end"
                placeholder='建档时间结束'
                style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                condition="f_createfile_date  <= '{}'"
                v-model="model.f_createfile_end">
              </datepicker>
            </div>
          </div>
          <!--<div class="row" v-show="$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style" v-show="$parent.$parent.criteriaShow">
              <label class="font_normal_body">公&emsp;&emsp;司</label>
              <right-tree @re-res="$parent.$parent.getRes" :initresid="$parent.$parent.$login.f.orgid">
              </right-tree>
            </div>

          </div>-->
        </div>
      </criteria>
      <data-grid :model="model" partial="list" class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th>
              <nobr>用户编号</nobr>
            </th>
            <th>
              <nobr>用户名称</nobr>
            </th>
            <th>
              <nobr>用户电话</nobr>
            </th>
            <th>
              <nobr>用户表号</nobr>
            </th>
            <th>
              <nobr>用气性质</nobr>
            </th>
            <th>
              <nobr>表具状态</nobr>
            </th>
<!--            <th>-->
<!--              <nobr>气表品牌</nobr>-->
<!--            </th>-->
            <th>
              <nobr>用户类型</nobr>
            </th>
<!--            <th>-->
<!--              <nobr>壁挂炉</nobr>-->
<!--            </th>-->
<!--            <th>-->
<!--              <nobr>灶具</nobr>-->
<!--            </th>-->
            <th>
              <nobr>片区</nobr>
            </th>
            <th>
              <nobr>小区名称</nobr>
            </th>
            <th style="padding: 0 40px">
              <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 v-show="$parent.$parent.$parent.showcode">
              <nobr>二维码</nobr>
            </th>
          </tr>
        </template>
        <template partial='body'>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{ row.f_userinfo_code }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{ row.f_user_name }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{ row.f_user_phone }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_meternumber}}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center;">{{row.f_gasproperties}}</td>
          <td 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;">{{row.f_meter_brand}}</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_safe_hasfurnace }}</td>-->
<!--          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_safe_haskitchen }}</td>-->
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_slice_area }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_residential_area }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_address }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_check_book_name }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_checker_name }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_last_check_date }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_last_check_state }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">
            {{row.f_last_check_state!='入户' ? '': (row.f_last_check_result == '无隐患' ? '无问题' : row.f_last_check_result) }}
          </td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_createfile_date }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center">{{ row.f_uservent_date }}</td>
          <td v-bind:class="{newcolor:row.code==1}" style="text-align: center" v-show="$parent.$parent.$parent.showcode">
            <button class="button_spacing button_search-1" @click.stop='$parent.$parent.$parent.searchInfo(row.f_userinfo_code)' >点击</button>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
    <modal :show.sync="dialogVisible" style="text-align: center"  destroyOnClose={true} v-ref:modal v-if="dialogVisible">
      <div slot="modal-header" class="modal-header">
        <h4 class="modal-title">
          二维码
        </h4>
      </div>
      <div slot="modal-body" class="modal-body" >
        <div id="dd" ></div>
      </div>
      <div slot="modal-footer" class="modal-footer">
        <print-element class="btn btn-success width-80" id="dd" styleid='style1' top='40' left='60' width='100%' height='100%' v-ref:printelement>打印</print-element>
        <button type="button" class="btn btn-success width-80" @click="dialogVisible = false">确认</button>
        <button type="button" class="btn btn-success width-80" @click="dialogVisible = false"  >取消</button>
      </div>
    </modal>
  </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 select = function * (self,userid) {
//   let http = new HttpResetClass()
//   let getGasman = yield http.load('POST','/rs/search', {
//     source: 'this.getChildByName($安检员$).getUsers()',
//     userid: userid
//   }, {resolveMsg: null, rejectMsg: null})
//   //tag
//   getGasman.data.forEach((checker)=>{
//     self.checkersid.push({label:checker.name,value:checker.id})
//   })
//   self.checkersid.push({label:'全部',value:''})
// }


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

    return {
      dialogVisible: false,
      searchData: {
        condition: '1=1',
        orderitem: "f_last_check_date",
        timetype: "dd",
        f_defect_content: "CASE WHEN CHARINDEX( '\"result\":\"正常\"', tp.f_defect_content ) > 0 THEN '正常' ELSE replace(replace(replace( replace( RIGHT ( tp.f_defect_content, len( tp.f_defect_content ) - 26 ), substring('{}',2,1), '' ), substring('{}',1,1), '' ),']',''),'\"','') END"
      },
      excelHeaders: {
        //用户编号	用户名称	用户电话	安检次数	用户类型	小区名称	地址	安检日期	安检状态	安检结果

        'f_userinfo_code': '用户编号',
        'f_user_name': '用户名称',
        'f_user_phone': '用户电话',
        'f_meternumber': '用户表号',
        'f_user_type': '用户类型',
        'f_checker_name': '安检员',
        'f_slice_area': '片区',
        'f_residential_area': '小区名称',
        'f_address': '地址',
        'f_last_check_date': '安检日期',
        'f_last_check_state': '安检状态',
        'f_last_check_result': '安检结果',
        'f_createfile_date': '建档日期',
        'f_uservent_date': '首次通气日期'
      },
      model: new PagedList('rs/sql/根据安检员查询用户档案', 20, {
        orderitem: "'f_last_check_date'",
        timetype: "'dd'",
        f_defect_content: 'this.f_defect_content'
      }),
      f_defect_content:"CASE WHEN CHARINDEX( '\"result\":\"正常\"', tp.f_defect_content ) > 0 THEN '无隐患' ELSE replace(replace(replace( replace( RIGHT ( tp.f_defect_content, len( tp.f_defect_content ) - 26 ), substring('{}',2,1), '' ), substring('{}',1,1), '' ),']',''),'\"','') END",
      orgstrs: [{label: '全部', value: ''}],
      checkersid: [],
      checkStates:[],
      SafeCheckXZ: '',
      civil: '',   //民用安检周期
      civilian: '',      //非民用安检周期
      SafeCheckXZs: [{label: '全部', value: ''}, {label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'}], // 安检筛选选项
      SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''}],
      table_states: this.getTableStates(),
      gasproperties: this.getGasproperties(),
      // user_states:[{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')],
      IsShares: [{label: '是', value: '是'}, {label: '否', value: '否'}],
      IsShare: '否',
      checker: {},
      NoBuys: [{label: '是', value: '是'}, {label: '否', value: '否'}],
      criteriaShow: false,
      checkers: [],
      showcode:false,
      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: '',
      f_check_results: [{label: '全部', value: ''}, {label: '正常', value: '正常'}, {label: '有隐患', value: '有隐患'}],
      creatPlanWay: '',
      sliceArea: [],
      residentialareas: [],
      checkbooknames: [],
      cbcs:[],
      cbc:[],
      pcds:[]
    }
  },
  props: {
    style: {
      type: String,
      default: 'col-sm-2 form-group'
    },
    style2: {
      type: String,
      default: 'col-sm-4 form-group'
    },
    checkplan: { // 传入一条安检计划信息
      type: Object
    },
    additemshow: {
      type: Boolean,
      default: false
    }
  },
  ready() {
    // 获取分公司信息
    this.model.f_defect_content=this.f_defect_content
    this.showcode=this.$appdata.getSingleValue('用户安检情况二维码')
    //this.getfengongsi()
    this.model.chosenOrg = {id: 0}
    this.model.f_filialeids = this.$login.f.f_orgids
    this.model.f_filiale = this.$login.f.f_fengongsi
    this.model.f_OrgStr = this.$login.f.orgpathstr
    this.Mreadibook(`('${this.$login.f.orgid}')`)
    this.getAllMeterBook(`('${this.$login.f.orgid}')`)
    this.getresidentialarea()
    this.getcheckbookname()
  },
  methods: {
    //查询二维码
     searchInfo(val){
      this.dialogVisible = true
      //tag
       new HttpResetClass().load('POST','rs/logic/QrcodeUtil', {
        data: {
          id:val
        }
      },{resolveMsg: null, rejectMsg: null}).then(res=>{
         //tag
         //tag
         let imageer=new Image()
         imageer.src="data:image/jpg;base64,"+res.data.result
         document.getElementById("dd").appendChild(imageer);
         //tag
      })

    },
    //获取省市区列表
    getPcd(val){
      this.pcds = [{label:'全部',value:''}]
      new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_OrderBy`,
        {data:{items:"*",tablename:"t_pcd",orderitem:"id",condition:`f_orgid in ${val}`}},
        {resolveMsg: null, rejectMsg: null}).then((pcdlist)=>{
        pcdlist.data.forEach((result)=>{
          this.pcds.push({label:result.f_pcd,value:result.f_pcd})
        })
      })
    },
    getmeterbook(val){

      //tag
      this.cbc=[]
      this.cbc.push({
        label:'全部',
        value:''
      })
      if (val==''){

        this.cbcs.forEach(res=>{
          this.cbc.push({
            label:res.f_book_name,
            value:res.id
          })
        })
      }else{
        this.cbcs.forEach(res=>{
          if (res.f_book_slice_area==val){
            this.cbc.push({
              label:res.f_book_name,
              value:res.id
            })
          }
        })
      }
    },
    Mreadibook(val){
      ////tag
      ////tag
      if (val){
        new HttpResetClass().load('POST',`/rs/sql/tel_singleTable_OrderBy`, {data: {
            items: 'name',
            tablename: 't_zone',
            condition: `parentid  in ${val}`,
            orderitem: 'id'
          }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          this.sliceArea=[]
          this.sliceArea.push({
            label:'全部',
            value:''
          })
          res.data.forEach(ress=>{
            this.sliceArea.push({
              label:ress.name,
              value:ress.name
            })
          })

        })
      }
    },
    getresidentialarea(){
        new HttpResetClass().load('POST',`/rs/sql/tel_singleTable_GroupBy`, {data: {
            items: 'f_residential_area',
            tablename: 't_user_address',
            condition: `f_residential_area is not null and f_orgid = '${this.$login.f.orgid}'`,
            groupitem: 'f_residential_area',
          }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          this.residentialareas=[]
          this.residentialareas.push({
            label:'全部',
            value:''
          })
          res.data.forEach(ress=>{
            this.residentialareas.push({
              label:ress.f_residential_area,
              value:ress.f_residential_area
            })
          })

        })
    },
    getcheckbookname(){
      new HttpResetClass().load('POST',`/rs/sql/tel_singleTable_GroupBy`, {data: {
          items: 'f_check_book_name',
          tablename: 't_check_book',
          condition: ` f_orgid = '${this.$login.f.orgid}'`,
          groupitem: 'f_check_book_name',
        }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
        this.checkbooknames=[]
        this.checkbooknames.push({
          label:'全部',
          value:''
        })
        res.data.forEach(ress=>{
          this.checkbooknames.push({
            label:ress.f_check_book_name,
            value:ress.f_check_book_name
          })
        })

      })
    },
    // 获取县域分公司内容
    getfengongsi() {
      let val = {
        source: 'this.getParentByType($organization$).getSpecialResByType($organization$)',
        userid: `${this.$login.f.id}`
      }
      let http = new HttpResetClass()
      http.load('POST', '/rs/search', {data: val}, {resolveMsg: null, rejectMsg: null}).then((res) => {
        res.data.forEach((item) => {
          this.orgstrs.push({label: item.name, value: item.id})
        })
        //tag
      })
    },
    // 县域分公司发生改变
    // orgstrchange(val){
    //   if(val == undefined || val == ''){
    //     return
    //   }else {
    //     this.checkersid = []
    //     let gen = select(this,val)
    //     return co(gen)
    //   }
    // },
    getDefect(val) {
      if (val) {
        try {
          var defect = JSON.parse(val)
          return defect.result
        } catch (e) {
          //tag
          return '正常'
        }
      }
      return '正常'
    },
    checkerchange(val) {
      this.checkboxModel.f_checker = val.name
      this.checkboxModel.f_checker_id = val.id
    },
    search(args) {
      if (this.SafeCheckXZ && (args.model.f_check_start == '' || args.model.f_check_end == '')) {
        this.$showMessage('如果选择 已安检/未安检 选项，需要选择 安检起始时间！')
        return
      }
      if ((args.model.f_check_start  || args.model.f_check_end ) && !this.SafeCheckXZ) {
        this.$showMessage('如果录入 安检起始时间，需要选择 安检筛选条件！')
        return
      }
      /*if (this.SafeCheckXZ == '未安检') {
        args.condition += " and ( f_last_check_date >= '" + args.model.f_check_start + "' or  f_last_check_date <= '" + args.model.f_check_end + "' or f_last_check_date is null)"
      } else {
        if (args.model.f_check_start) {
          args.condition += " and f_last_check_date >= '" + args.model.f_check_start + "'"
        }
        if (args.model.f_check_end) {
          args.condition += " and f_last_check_date <= '" + args.model.f_check_end + "'"
        }
      }*/
      args.condition += " and f_filialeid in  " + (this.model.f_filialeids ? this.model.f_filialeids : `(${this.$login.f.orgid})`)
      let con = ' f_filialeid in  ' + (this.model.f_filialeids ? this.model.f_filialeids : `(${this.$login.f.orgid})`)
      con += args.model.f_userinfo_code ? ` and f_userinfo_code like '%${args.model.f_userinfo_code}%'`:''
      /*con += args.model.f_user_name ? ` and f_user_name like '%${args.model.f_user_name}%'` : ''
      con += args.model.f_residential_area ? ` and f_residential_area like '%${args.model.f_residential_area}%'` : ''
      con += args.model.f_address ? ` and f_address like '%${args.model.f_address}%'` : ''
      con += args.model.f_usertype ? ` and f_check_type = '${args.model.f_usertype}'` : ''*/
      if (this.SafeCheckXZ) {
        con += ` and f_offsite_time >= '${args.model.f_check_start}' and f_offsite_time <= '${args.model.f_check_end}' `
        if (this.SafeCheckXZ == '未安检'){
          args.condition += ' and ruhuid is null'
        }else{
          args.condition += ' and ruhuid is not null'
        }
      }
      let states = ` (`
      if (this.checkStates.length > 0 ){
        for (let i = 0; i < this.checkStates.length; i++) {
          if (this.checkStates[i]){
            states += `'${this.checkStates[i]}',`
          }else {
            states = ''
            break
          }
        }
        if (states){
          states=states.substring(0,states.length-1)
          states += `) `
          args.condition += ` and f_last_check_state in ${states}`
        }
      }else {
        states = ''
      }
      con += states ? ` and f_entry_status in ${states}` : ''
      con += args.model.f_checker_id ? ` and f_checker_name in ${args.model.f_checker_id}` : ' and 1=1'
      let condition = {
        condition1: args.condition,
        condition2: con
      }
      this.searchData.condition = condition
      return this.model.search(condition, args.model)
    },
    checkstatus() {
      return this.$appdata.getParam('安检状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('安检状态')] : [{label: '全部', value: ''}]
    },
    getTableStates(){
      return this.$appdata.getParam('表具状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('表具状态')] : [{label: '全部', value: ''}]
    },
    getGasproperties(){
      return this.$appdata.getParam('用气性质') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用气性质')] : [{label: '全部', value: ''}]
    },
    usertypes() {
      return this.$appdata.getParam('用户类型') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用户类型')] : [{label: '全部', value: ''}]
    },
    userstates() {
      return this.$appdata.getParam('用户状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用户状态')] : [{label: '全部', value: ''}]
    },
    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    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])
              }
              //tag;
            }
          })
      }
    },
    addChecked(item) {
      //tag;
      if (!item.checked) {
        this.checkrows.push(item);
        //tag;
      } 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() {
      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() {
      //tag
      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]
    },
    getAllMeterBook(val){
      ////tag
      ////tag
      this.cbcs=[]
      if (val){
        new HttpResetClass().load('POST',`/rs/sql/tel_singleTable_OrderBy`, {data: {
            items: 'f_book_name,f_book_slice_area,id',
            tablename: 't_meter_book',
            condition: `f_filiale_id  in ${val}`,
            orderitem: 'id'
          }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          res.data.forEach(ress=>{
            this.cbcs.push({
              id:ress.id,
              f_book_name:ress.f_book_name,
              f_book_slice_area:ress.f_book_slice_area
            })
          })
          this.cbc=[]
          this.cbc.push({
            label:'全部',
            value:''
          })
          this.cbcs.forEach(res=>{
            this.cbc.push({
              label:res.f_book_name,
              value:res.id
            })
          })
        })
      }
    },
    getRes(obj) {
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
      this.Mreadibook(this.model.f_filialeids)
      this.getAllMeterBook(this.model.f_filialeids)
      this.getPcd(this.model.f_filialeids)
    }
  },

  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){
    //   //tag
    //   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
    },
    excelStart () {
      return this.$login.r.includes('用户安检情况导出')
    }
  }
}
</script>
<style scoped>
.newcolor {
  color: red;
}

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