<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex">
        <div style="flex:1;" class="flex" v-if="!show">
          <criteria-paged :model="model" v-ref:paged>
            <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
              <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
                <div class="row">
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户编号</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                           condition="f_userinfo_code = '{}' " placeholder="客户编号">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户名称</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                           condition="f_user_name like '%{}%'" placeholder="客户名称">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户电话</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_user_phone"
                           condition="f_user_phone like '%{}%'" placeholder="客户电话">
                  </div>
                  <div class="span" style="float:right;">
                    <button class="button_search button_spacing" v-show="false" @click="$parent.$parent.ReadIDCard()">读取身份证</button>
                    <read-card v-if="!$filialeInfo || $filialeInfo!=='rongcheng'" :is-single.sync="$parent.$parent.isSingleUser" @read-info="$parent.$parent.cardBtn"  v-ref:readcard></read-card>
                    <button class="button_search button_spacing" @click="search()">查询</button>
                    <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
                    <!--<button class="btn btn-default" @click="$parent.$parent.stamp()">打印</button>-->

                    <export-excel :data="$parent.$parent.getCondition"
                                  :field="$parent.$parent.getExportField"
                                  :footer="$parent.$parent.footer"
                                  :header="$parent.$parent.other"
                                  v-if="$parent.$parent.authArr.includes('档案查询导出')"
                                  sqlurl="rs/logic/exportfile" sql-name="meterQuery" template-name='汽车查询导出'
                                  :choose-col="true"></export-excel>
                    <print-data :sum-field="$parent.$parent.getExportField" :model="$parent.model" :field="$parent.$parent.getExportField"
                                :defaultfield="$parent.$parent.defaultfield"
                                titletable="客户查询"
                                :sumsmodel="$parent.$parent.sumsmodel"></print-data>


                    <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.criteriaShow">
                  <res-select-group :initres="$parent.$parent.initres" @re-res="$parent.$parent.getRes"></res-select-group>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户地址</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                           condition="f_address like '%{}%'" placeholder='客户地址'>
                  </div>
<!--                  <div class="col-sm-2 form-group" v-if="!$filialeInfo || $filialeInfo!=='rongcheng'">-->
<!--                    <label class="font_normal_body">用气点</label>-->
<!--                    <input type="text" style="width:60%" class="input_search" v-model="model.f_userfiles_address"-->
<!--                           condition="f_userfiles_address like '%{}%'" placeholder='用气点'>-->
<!--                  </div>-->
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">&nbsp;&nbsp;&nbsp;车牌号&nbsp;&nbsp;&nbsp;</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_meternumber"
                           condition="f_meternumber like '%{}%'" placeholder='车牌号'>
                  </div>

                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">&nbsp;&nbsp;&nbsp;卡号&nbsp;&nbsp;&nbsp;</label>-->
                    <!--<input type="text" style="width:60%" class="input_search" v-model="model.f_card_id"-->
                           <!--condition="f_card_id like '%{}%'" placeholder='卡号'>-->
                  <!--</div>-->

                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户类型</label>
                    <v-select :value.sync="model.f_user_type"
                              :options='$parent.$parent.usertypes'
                              @change="$parent.$parent.userTypeChange()"
                              placeholder='请选择' v-model="model.f_user_type"
                              condition="f_user_type = '{}'"
                              close-on-select></v-select>
                  </div>
                  <!--<div class="col-sm-2 form-group" >-->
                    <!--<label for="f_usetype" class="font_normal_body">二次挂表</label>-->
                    <!--<v-select :value.sync="model.issecondtype" v-model="model.issecondtype"-->
                              <!--condition="f_usetype {}"-->
                              <!--:options='$parent.$parent.issecond' placeholder='请选择'-->
                              <!--close-on-select></v-select>-->
                  <!--</div>-->
                  <!--<div class="col-sm-2 form-group" >-->
                    <!--<label for="f_usetype" class="font_normal_body"  title="参数:使用类型">使用类型</label>-->
                    <!--<v-select :value.sync="model.f_usetype" v-model="model.f_usetype"-->
                              <!--condition="f_usetype = '{}'"-->
                              <!--:options='$parent.$parent.usetype' placeholder='请选择'-->
                              <!--close-on-select></v-select>-->
                  <!--</div>-->
                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">用气性质</label>-->
                    <!--<v-select :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"-->
                              <!--:options='$parent.$parent.gasproperties' placeholder='请选择'-->
                              <!--condition="f_gasproperties = '{}'"-->
                              <!--close-on-select></v-select>-->
                  <!--</div>-->
                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">气价类型</label>-->
                    <!--<v-select :value.sync="model.pricetype" v-model="model.pricetype"-->
                              <!--placeholder='气价类型' :options="$parent.$parent.pricetypes"-->
                              <!--condition="f_price_type = '{}'"-->
                              <!--close-on-select v-ref:type>-->
                    <!--</v-select>-->
                  <!--</div>-->
                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">气价名称</label>-->
                    <!--<v-select :value.sync="model.f_price_name"-->
                              <!--v-model="model.f_price_name"-->
                              <!--:options="$parent.$parent.getPricenames"-->
                              <!--placeholder='请选择'-->
                              <!--condition="f_price_name = '{}'"-->
                              <!--close-on-select></v-select>-->
                  <!--</div>-->
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">汽车分类</label>
                    <v-select :value.sync="model.f_meter_classify"
                              v-model="model.f_meter_classify"
                              :options='$parent.$parent.metertypes' placeholder='请选择'
                              condition="f_meter_classify = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">汽车品牌</label>
                    <v-select :value.sync="model.f_meter_brand"
                              v-model="model.f_meter_brand"
                              :options='$parent.$parent.meterbrands' placeholder='请选择'
                              condition="f_meter_brand = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">汽车型号</label>
                    <v-select :value.sync="model.f_meter_style"
                              v-model="model.f_meter_style"
                              :options='$parent.$parent.meterstyle[model.f_meter_brand]' placeholder='请选择'
                              condition="f_meter_style = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">汽车状态</label>
                    <v-select :value.sync="model.f_table_state"
                              v-model="model.f_table_state"
                              :options='$parent.$parent.tablestate' placeholder='请选择'
                              condition="f_table_state = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">使用状态</label>
                    <v-select :value.sync="model.f_usestate"
                              v-model="model.f_usestate"
                              :options='$parent.$parent.usestate' placeholder='请选择'
                              condition="f_usestate = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label for="startDate" class="font_normal_body">建档日期</label>
                    <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                                v-model="model.startDate"
                                :value.sync="model.startDate"
                                :format="'yyyy-MM-dd'"
                                :show-reset-button="true"
                                condition="f_input_date >= '{} 00:00:00'">
                    </datepicker>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label for="endDate" class="font_normal_body">建档日期</label>
                    <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                                v-model="model.endDate"
                                :value.sync="model.endDate"
                                :format="'yyyy-MM-dd'"
                                :show-reset-button="true"
                                condition="f_input_date <= '{} 23:59:59'">
                    </datepicker>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label for="startDate" class="font_normal_body">加气日期</label>
                    <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                                v-model="model.startTQDate"
                                :value.sync="model.startTQDate"
                                :format="'yyyy-MM-dd'"
                                :show-reset-button="true"
                                condition="f_gas_date >= '{} 00:00:00'">
                    </datepicker>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label for="endDate" class="font_normal_body">加气日期</label>
                    <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                                v-model="model.endTQDate"
                                :value.sync="model.endTQDate"
                                :format="'yyyy-MM-dd'"
                                :show-reset-button="true"
                                condition="f_gas_date <= '{} 23:59:59'">
                    </datepicker>
                  </div>
                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">&nbsp;&nbsp;&nbsp;壁挂炉</label>-->
                    <!--<v-select :value.sync="model.isbgl" v-model="model.isbgl"-->
                              <!--:options='$parent.$parent.bgl' placeholder='请选择'-->
                              <!--condition="isbgl = '{}'"-->
                              <!--close-on-select></v-select>-->
                  <!--</div>-->
                  <!--<div class="col-sm-2 form-group" v-if="!$filialeInfo || $filialeInfo!=='rongcheng'">-->
                    <!--<label class="font_normal_body">用户等级</label>-->
                    <!--<v-select :value.sync="model.f_user_grade"-->
                              <!--v-model="model.f_user_grade"-->
                              <!--:options='$parent.$parent.usergrade' placeholder='请选择'-->
                              <!--condition="f_user_grade = '{}'"-->
                              <!--close-on-select></v-select>-->
                  <!--</div>-->
                  <!--表册片区-->
                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">表册片区</label>-->
                    <!--<v-select :value.sync="model.f_book_slice_area" v-model="model.f_book_slice_area"-->
                              <!--:options='$parent.$parent.bookSlice' placeholder='片区/表册'-->
                              <!--style="width:60%"-->
                              <!--close-on-select-->
                              <!--condition="f_book_slice_area = '{}'"></v-select>-->
                  <!--</div>-->
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body" >加&nbsp;&nbsp;气&nbsp;员</label>
                    <v-select :value.sync="model.f_inputtor"
                              v-model="model.f_inputtor"
                              :options='$parent.$parent.inputtores' placeholder='请选择'
                              condition="f_inputtor = '{}'"
                              close-on-select :value-single="true" :search="false">
                    </v-select>
                  </div>
                  <!--<div class="col-sm-2 form-group">-->
                    <!--<label class="font_normal_body">抄&ensp;表&ensp;册</label>-->
                    <!--<v-select :value.sync="model.f_meter_book" v-model="model.f_meter_book"-->
                              <!--:options='$parent.$parent.meterbooks' placeholder='抄表册'-->
                              <!--style="width:60%"-->
                              <!--close-on-select-->
                              <!--condition="f_meter_book_num = '{}'"></v-select>-->
                  <!--</div>-->

                </div>
              </div>
            </criteria>

            <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy" :classname="$parent.classname">
              <template partial='head'>
                <tr>
                  <th>
                    <nobr>客户编号</nobr>
                  </th>
                  <th>
                    <nobr>客户名称</nobr>
                  </th>
                  <th>
                    <nobr>客户电话</nobr>
                  </th>
                  <th>
                    <nobr>身份证号</nobr>
                  </th>
                  <th>
                    <nobr>客户地址</nobr>
                  </th>
                  <!--<th>-->
                    <!--<nobr>表册片区</nobr>-->
                  <!--</th>-->
                  <th>
                    <nobr>账号余额</nobr>
                  </th>
                  <!--<th>-->
                    <!--<nobr>客户类型</nobr>-->
                  <!--</th>-->
                  <!--<th>-->
                    <!--<nobr>使用类型</nobr>-->
                  <!--</th>-->
                  <!--<th>-->
                    <!--<nobr>用气性质</nobr>-->
                  <!--</th>-->
                  <!--<th>-->
                    <!--<nobr>表号</nobr>-->
                  <!--</th>-->
                  <!--<th>-->
                    <!--<nobr>卡号</nobr>-->
                  <!--</th>-->


<!--                  <th>-->
<!--                    <nobr>气价名称</nobr>-->
<!--                  </th>-->
<!--                  <th>-->
<!--                    <nobr>气价详情</nobr>-->
<!--                  </th>-->
                  <th>
                    <nobr>汽车品牌</nobr>
                  </th>
                  <th>
                    <nobr>汽车型号</nobr>
                  </th>
                  <!--<th>-->
                    <!--<nobr>户管员</nobr>-->
                  <!--</th>-->
                  <th>
                    <nobr>加气员</nobr>
                  </th>
                  <th>
                    <nobr>加气时间</nobr>
                  </th>
                  <!--<th>-->
                    <!--<nobr>建表时间</nobr>-->
                  <!--</th>-->
                  <th>
                    <nobr>汽车状态</nobr>
                  </th>
                  <!--<th>-->
                    <!--<nobr>是否壁挂炉</nobr>-->
                  <!--</th>-->
                </tr>
              </template>
              <template partial='body'>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;"><nobr>
                  <span @click="$parent.$parent.$parent.showmsg(row)"><a>{{row.f_userinfo_code}}</a></span>
                </nobr> </td>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_user_name}}</nobr>
                </td>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_user_phone}}</nobr>
                </td>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.idnumber}}</nobr>
                </td>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_address}}</nobr>
                </td>
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_book_slice_area}}</nobr>-->
                <!--</td>-->
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_balance_amount}}</nobr>
                </td>
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_user_type}}</nobr>-->
                <!--</td>-->
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_usetype}}</nobr>-->
                <!--</td>-->
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_gasproperties}}</nobr>-->
                <!--</td>-->
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_meternumber}}</nobr>-->
                <!--</td>-->
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_card_id}}</nobr>-->
                <!--</td>-->


<!--                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
<!--                  <nobr>{{row.f_price_name}}</nobr>-->
<!--                </td>-->
                <th :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.value}}</nobr>
                </th>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_meter_brand}}</nobr>
                </td>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_meter_style}}</nobr>
                </td>
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_inputtor}}</nobr>-->
                <!--</td>-->
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_gas_person}}</nobr>
                </td>
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_gas_date}}</nobr>
                </td>
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.f_input_date}}</nobr>-->
                <!--</td>-->
                <td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">
                  <nobr>{{row.f_table_state}}</nobr>
                </td>
                <!--<td :class="row.f_table_state !== '正常'? 'back-red' : 'back-blue'" style="text-align: center;">-->
                  <!--<nobr>{{row.isbgl}}</nobr>-->
                <!--</td>-->
              </template>
              <template partial='foot'>
              </template>
            </data-grid>
          </criteria-paged>

          <table class="table-hover">
            <tr style="position: relative" class="table-bordered">
              <td
                style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">
                汇总信息
              </td>
              <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
                该车余额合计&emsp;{{sumsmodel.f_balance_amount}}
              </td>
            </tr>
          </table>

          <!--<modal :show.sync="printshow" v-ref:modal backdrop="false">-->
          <!--<header slot="modal-header" class="modal-header text-center">-->
          <!--<h4 class="modal-title">打印列选择</h4>-->
          <!--<input type="checkbox" class="" id="f_generations" v-model="all">-->
          <!--<label for="f_generations" class="font-size">全选</label>-->
          <!--</header>-->
          <!--<article slot="modal-body">-->
          <!--<div class="auto col-sm-11 col-md-offset-1"  style="margin-top: 10px;">-->
          <!--<div class="col-sm-3" v-for="f in fields">-->
          <!--<input type="checkbox" class="" :id="'water-owe-details-'+$index" v-model="modelval" :value="$key">-->
          <!--<label :for="'water-owe-details-'+$index" class="font-size">{{f}}</label>-->
          <!--</div>-->
          <!--</div>-->
          <!--</article>-->
          <!--<footer slot="modal-footer" class="modal-footer">-->
          <!--<center>-->
          <!--<button v-show="printshow" type="button" class="btn btn-default" @click='close()'>取消</button>-->
          <!--<button v-show="printshow" type="button" class="btn btn-success" @click='print()'>打印</button>-->
          <!--<print-table :model='model' v-show="false" v-ref:print-->
          <!--:top='40' :left='60' :right='40' :bottom='60'-->
          <!--:thead="thead" :tfoot='tfoot' :attach="yangsen"-->
          <!--:fields="modelval" :printpage="true">-->
          <!--</print-table>-->
          <!--</center>-->
          <!--</footer>-->
          <!--</modal>-->
        </div>
        <div class="flex" v-if="show">
          <user-info-detail-manage-new :f_userinfo_id="rowdata.f_userinfo_id" @cancel-main="cancel"></user-info-detail-manage-new>
        </div>
      </div>
    </div>
  </div>
  <high-meter-idcard :show.sync="false"  v-ref:highcard  ></high-meter-idcard>
</template>

<script>
  import {PagedList} from 'vue-client'
  import exportConfig from '../config/exportConfig'
  let cardBtnGen = async function (self, val) {
    self.cardInfo = val.data

    // 判断读卡是否需要卡密码
    console.log('读卡上的信息', self.cardInfo)

    if (self.cardInfo.NewParam) {
      if (self.cardInfo.NewParam.error) {
        if (self.cardInfo.NewParam.error === '0001') {
          // 需要重新读卡并传卡密码
          if (self.model.rows.length == 1 && self.model.rows[0].f_alias === self.cardInfo.Factory) {
            self.readCardParam = self.model.rows[0].f_card_password
            self.cardInfo = await self.$refs.paged.$refs.cri.$refs.readcard.readCard2(self.model.rows[0].f_card_password)
          } else {
            self.$showAlert('此卡需要先获取客户信息。请通过条件查询该客户信息之后进行读卡！！', 'warning', 2000)
            return
          }
        }
      }
    }
    self.card=self.cardInfo.CardID
    self.search()
  }

  let readySomething = async function (self) {
    self.$MagGetSaleParam.initinputtor();
    self.getinputtores();
    self.initmeterbook();
    // self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
    // self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
    // await self.$refs.paged.$refs.cri.search()
    await self.$MagLoadParams.loadParam()
    self.initParams()
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
    self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
  }

  export default {
    title: '汽车查询',
    data() {
      return {
        IdCardInfo:'',
        card:'',
        isSingleUser: null,
        other:[],
        footer:[],
        model: new PagedList('rs/sql/meterQuery', 20, {}, {f_balance_amount: 0}),
        criteriaShow: false,
        orgCondtionStr: '',

        modelval: [],
        printshow: false,
        all: false,
        fields: {},
        thead: '',
        tfoot: '',
        initres: {
          org:[this.$login.f.orgid],
          dep:[],
          user:[],
        },
        show:false,
        rowdata:{},
        meterbrands: [],
        // 汽车型号
        meterstyle: {},
        //默认打印列
        defaultfield: [],
        config: {
          defaultPrint: ['f_userinfo_code', 'f_user_name', 'f_user_phone']
        },
        pricenames: [],
        gasproperties:[],
        inputtouPerson: [],
        meterbooks:[{label: '全部',value: ''}],  //抄表册
        inputtores:[{label: '全部',value: ''}],
        prices: [],
        //合计数据
        sumsmodel: {},
        //表册片区
        bookSlice:[{label: '全部',value: ''}],
        inputtores:[{label: '全部',value: ''}],  //抄表员
        f_filialeid: this.$login.f.f_orgid,
        allorgid:[],
        tempfalg :false,
        lastorgstr:'',
        // issecond: [{label:'是',value:" = '二次挂表'"},{label:'否',value:" <> '二次挂表'"}],
        usetype:this.$appdata.getParam('使用类型')
      }
    },
    ready() {
      console.log("===========",this.$filialeInfo)
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      ReadIDCard(){
        this.$refs.highcard.sendMsg(this.$refs.highcard.CLT_MSG.READ_IDCARD, (msg) => {
          console.log('======',msg)
          if(msg.err !== 0){ return}
          this.IdCardInfo=msg.strID
        })
        console.log(this.IdCardInfo)
        if(this.IdCardInfo) {
          this.search()
        }else{
          alert("读取失败，找不到用户信息")
        }
      },
      cardBtn (val) {
        // this.clear()
        cardBtnGen(this, val)
      },
      async initmeterbook(orgstr){
        if(orgstr == null ){
          orgstr = this.f_filialeid;
        }
        //获取新的抄表册,先去清理所有的抄表册
        this.$GetSaleParam.meterbooks = [];
        //开始加载新的抄表册
        await this.$LoadParams.loadMeterBook(orgstr)
        this.meterbooks = [{label: '全部', value: ''}, ...this.$GetSaleParam.getMeterBooks()]
      },
      async getinputtores () {
        // 获取抄表员
        let rs = []
        if (this.$login.f.f_gasman.length > 0) {
          for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
            let temp = {
              label: this.$login.f.f_gasman[i].name,
              value: this.$login.f.f_gasman[i].name
            }
            rs.push(temp)
          }
        }
        this.inputtores = [{label: '全部', value: ''}, ...rs]
      },
      getotherfooter () {
        // this.$refs.paged.$refs.cri.$refs.exports.otherData = [];
        // this.$refs.paged.$refs.cri.$refs.exports.footerData = [];
        this.other = [];
        this.footer = [];
        let exportdata = this.getCondition;
        let otherInData = [];
        otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`);
        let footerData = [], exportfield = this.getExportField;
        footerData.push("合计");
        let self = this;
        for (var field in self.sumsmodel) {
          footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`);
        }
        this.footer.push(footerData);
        this.other.push(otherInData);
      },
      search(){
        this.$refs.paged.$refs.cri.search()
      },
      cancel() {
        this.show = false
      },
      showmsg(obj){
        this.rowdata=obj
        this.show=true
      },
      selfSearch(args) {
        //抄表员查询条件
        this.inputtouPerson = this.$refs.paged.$refs.cri.model.f_inputtor
        if(this.inputtouPerson.length !== 0){
          let str = JSON.stringify(this.inputtouPerson)
          str = str.replace(/"/g,`'`)
          str = str.replace(/\[/g,``)
          str = str.replace(/\]/g,``)
          console.log("=====抄表员model22222222222绑定====",str)
          //查询多个抄表员时条件
          args.condition += ` and f_inputtor in  ( ${str} )`
        }
        if (!this.orgCondtionStr) {
          args.condition = `${args.condition}` + " and f_orgid = " + this.$login.f.orgid
        } else {
          args.condition = `${args.condition}` + this.orgCondtionStr
        }
        if(this.card!=''){
          args.condition +=` and f_card_id='${this.card}'`
        }
        if(this.IdCardInfo!=''){
          args.condition+=` and f_idnumber='${this.IdCardInfo}'`
        }
        this.model.search(args.condition, args.model)
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums;
        this.card=''
        this.IdCardInfo=''
      },
      clear() {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      async getRes(condition) {
        this.orgCondtionStr = condition

      },
      stamp() {
        this.all = false
        //默认选择要打印的列
        this.modelval = defaultPrint.config
        this.fields = this.getfield
        console.log('所有打印字段', this.fields)
        this.printshow = true
        this.put()
      },
      put() {
        // 对Modelval进行排序
        this.sortModelval()
        this.thead = `<tr><th colspan=${this.modelval.length}>车具查询统计报表</th></tr><tr>`
        for (let key of this.modelval) {
          this.thead += '<th>' + this.fields[key] + '</th>'
        }
        this.thead += '</tr>'
      },
      print() {
        this.$refs.print.PrintAsFile()
        this.printshow = false
      },
      close() {
        this.printshow = false
        this.all = false
      },
      userTypeChange () {
        this.gasproperties=[]
        if(this.$refs.paged.$refs.cri.model !==null) {
          this.$refs.paged.$refs.cri.model.f_gasproperties=''
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        else{
          this.gasproperties =[{label: '全部', value: ''}]
        }
      },
      initParams() {
        // 初始化汽车品牌
        let brandArr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          brandArr.push(temp)
          // 取出对应汽车型号
          let styleArr = []
          for (let row of item.value.gasmodel) {
            styleArr.push({label: row.label,value: row.value.f_meter_style})
          }
          this.meterstyle[temp.value] = styleArr
        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
        //初始化汽车价格
        this.prices = this.$MagGetSaleParam.getPrices();
      },
      // 对选择的列进行排序
      sortModelval() {
        let sortModel = []
        Object.keys(this.fields).forEach((key) => {
          if (this.modelval.includes(key)) {
            sortModel.push(key)
          }
        })
        this.modelval = sortModel
        console.log('选择的打印的字段', this.modelval)
      },
      async updateParams() {
        await this.$MagLoadParams.loadParam(this.f_filialeid)
        this.inputtores = [];
        this.inputtores.push({label: "全部", value: ""})
        this.initSlice(this.f_filialeid)
        if(this.allorgid!=null){
          this.allorgid.forEach((res)=>{
            this.inputtores = this.inputtores.concat(this.$MagGetSaleParam.getresinputtor(res));
          })
        }
      },
      async initSlice (val) {
        if (val) {
          let getAllArea = await this.$resetpost('/rs/search', {
            source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
            userid: this.$login.f.id
          }, {resolveMsg: null, rejectMsg: '获取片区出错！！！'})
          let arr = getAllArea.data.filter((res) => {
            return res.parentid == val
          })
          this.bookSlice = []
          console.log('过滤之后的片区-------------------', arr)
          arr.forEach((res) => {
            this.bookSlice.push({label: res.name, value: res.name})
          })
        }
      },
    },
    watch: {
      'model.rows.length' () {
        this.isSingleUser = this.model.rows
      },
      'all'(val) {
        if (val) {
          this.modelval = this.bodyData
        } else {
          this.modelval = defaultPrint.config
          this.put()
        }
      },
      sumsmodel:{
        handler: function(val) {
          this.getotherfooter();
        },
        deep: true
      },
      'modelval.length'() {
        this.put()
      },
      async 'orgCondtionStr'(val) {
        //更新抄表册
        this.meterbooks = [{label: '全部',value: ''}];
        if(this.lastorgstr != val){
          this.tempfalg = true;
          this.lastorgstr = val;
        }
        if(this.tempfalg && val != null && val!=''  && val.indexOf("(")>-1){
          this.tempfalg = false;
          let a = val.substring(val.indexOf("(")+2)
          await this.initmeterbook(a.substring(0,a.indexOf(")")-1));
        }
        let res = val.match(/'(.*?)'/)
        console.log('正则提取:',res && res[1])
        if (res) {
          this.f_filialeid = res[1]
          if(res.input !=null){
            let resorgid = res.input.substring(res.input.indexOf("'"));
            if(resorgid!= null && resorgid!=''){
              resorgid = resorgid.substring(0,resorgid.lastIndexOf("'")+1);
              // resorgid = resorgid.replaceAll("'","");
              resorgid = resorgid.replace(/'/g,"");
              this.allorgid = resorgid.split(",")
            }
          }
          this.updateParams()
        }
      },
    },
    computed: {
      authArr () {
        return this.$login.r ? this.$login.r : []
      },
      getPricenames() {
        let f_user_type = this.$refs.paged.$refs.cri.model.f_user_type;
        let f_gasproperties = this.$refs.paged.$refs.cri.model.f_gasproperties;
        let pricetype = this.$refs.paged.$refs.cri.model.pricetype;
        // console.log("打印一下:",f_user_type,f_gasproperties,pricetype,this.f_filialeid,this.prices)
        if(this.$refs.paged.$refs.cri.model !==null) {
          let rs = []
          let priceArr = []
          if ( pricetype.length >0) {
            let params = {
              f_price_type: pricetype[0],
              filter: this.f_filialeid,
              prices: this.prices
            }
            this.$MagGetSaleParam.getPrice(params).forEach((item) => {
              let temp = {}
              temp.label = item.label
              temp.value = item.value.f_price_name
              priceArr.push(temp)
            })
            rs = [{label: '全部', value: ''}, ...priceArr]
          }
          if (rs.length === 0) {
            console.log('rs读出来是空')
            this.$refs.paged.$refs.cri.model.f_price_name = ''
          }
          return rs
        }
      },
      getCondition() {
        return {condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr}
      },
      getfield() {
        let data = {}
        this.bodyData.forEach((value, index) => {
          data[this.bodyData[index]] = this.headData[index]
        })
        //合计字段打印
        this.tfoot = `<tr><th colspan=${this.modelval.length}>全表汇总信息: `
        if (this.sumsmodel) {
          Object.keys(this.sumsmodel).forEach((key) => {
            this.tfoot += this.fields[key] + '合计: ' + `<font color="blue">${this.sumsmodel[key]} </font>`
          })
        } else {
          this.tfoot += '暂无'
        }
        this.tfoot += '</th></tr>'
        return data
      },
      getExportField() {
        return exportConfig.meterConfig
      },
      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]
      },
      sliceArea() {
        let rs = []
        if (this.$refs.paged.$refs.cri.model.f_area.length > 0) {
          for (let i = 0; i < this.$login.f.f_allArea.length; i++) {
            if (this.$login.f.f_allArea[i].label === this.$refs.paged.$refs.cri.model.f_area[0]) {
              rs = this.$login.f.f_allArea[i].value
            }
          }
        }
        return [{label: '全部', value: ''}, ...rs]
      },
      usertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      // gasproperties() {
      //   return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      // },

      metertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('汽车类型')]
      },
      // meterbrands() {
      //   let arr = []
      //   this.$MagGetSaleParam.getGasbrand().forEach((item) => {
      //     let temp = {}
      //     temp.label = item.label
      //     temp.value = item.value.f_meter_brand
      //     arr.push(temp)
      //   })
      //   return [{label: '全部', value: ''}, ...arr]
      // },
      pricetypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气价类型')]
      },
      tablestate() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('汽车状态')]
      },
      bgl(){
        return [{label: '全部', value: ''}, {label: '是', value: '是'}, {label: '否', value: '否'}]
      },
      usergrade(){
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户等级')]
      },
      usestate(){
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('汽车状态')]
      }
    }
  }
</script>
<style>
  .back-red{		/* 红色背景 */
    background-color: #F6C6CE;
  }
  .back-blue{		/* 蓝色背景 */

  }
</style>
