<template>
  <div style="flex:1;width: 100%" class="flex" id="charge-query" >
    <button class="btn btn-xs" v-show="!this.criteriaShow" @click="this.show()">
      <span class="glyphicon glyphicon-chevron-down" style="color: #000;"></span>
    </button>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri v-show="$parent.criteriaShow">
        <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"
                      condition="f_userinfo_code = '{}' " placeholder="用户编号"
                      :size="model.f_userinfo_code ? model.f_userinfo_code.length : 1">
            </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_olduserinfo_code"-->
            <!--                      condition="f_olduserinfo_code like '%{}%' " placeholder="旧用户编号"-->
            <!--                      :size="model.f_olduserinfo_code ? model.f_olduserinfo_code.length : 1">-->
            <!--            </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"
                      condition="f_user_name like '%{}%'" placeholder="用户姓名"
                      :size="model.f_user_name ? model.f_user_name.length : 1">
            </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_phone"
                      condition="f_user_phone like '%{}%'" placeholder="用户电话"
                      :size="model.f_user_phone ? model.f_user_phone.length : 1">
            </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_idnumber"-->
            <!--                     condition="f_idnumber like '%{}%'" placeholder="身份证号"-->
            <!--                     :size="model.f_idnumber ? model.f_idnumber.length * 2 : 1">-->
            <!--            </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_residential_area"
                        v-model="model.f_residential_area"
                        :options='$parent.$parent.residential_area' placeholder='请选择'
                        condition="f_residential_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">用户地址</label>
              <input  type="text" class="form-control" v-model="model.f_address"
                      condition="f_address like '%{}%'" placeholder='用户地址'
                      :size="model.f_address ? model.f_address.length * 2 : 1">
            </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_charge_type"
                        v-model="model.f_charge_type"
                        multiple
                        :options='$parent.$parent.chargetype' placeholder='请选择'
                        condition="f_charge_type in {}"
              ></v-select>
            </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_user_state"
                        v-model="model.f_user_state"
                        :options='$parent.$parent.user_state' placeholder='请选择'
                        condition="f_user_state = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">用户类型</label>
              <v-select :value.sync="model.f_user_type"
                        :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                        condition="f_user_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">用热性质</label>
              <v-select :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-3 form-group form-input-group" style="width: 20%">-->
            <!--              <label class="control-label">热价名称</label>-->
            <!--              <v-select :value.sync="model.f_price_name"-->
            <!--                        v-model="model.f_price_name"-->
            <!--                        :options='$parent.$parent.pricenames' placeholder='请选择'-->
            <!--                        condition="f_price_name = '{}'"-->
            <!--                        close-on-select></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_covered_area"-->
            <!--                     condition="f_covered_area = '{}'" placeholder="实用面积"-->
            <!--                     :size="model.f_covered_area ? model.f_covered_area.length * 2 : 1">-->
            <!--            </div>-->
            <!--            <div class="col-sm-3 form-group form-input-group" style="width: 20%">-->
            <!--              <label class="control-label"  title="付款方式查询专用">付款方式</label>-->
            <!--              <v-select :value.sync="model.f_payment"-->
            <!--                        v-model="model.f_payment"-->
            <!--                        multiple-->
            <!--                        :options='$parent.$parent.payments' placeholder='请选择'-->
            <!--                        condition="f_payment in {}"-->
            <!--              ></v-select>-->
            <!--            </div>-->
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label"  title="付款方式查询专用">付款方式</label>
              <v-select :value.sync="model.f_payment"
                        v-model="model.f_payment"
                        :options='$parent.$parent.payments' placeholder='请选择'
                        condition="f_payment in {}"
              ></v-select>
            </div>

            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="endDate" class="control-label">公司</label>
              <v-select :value.sync="model.f_filialeids"
                        v-model="model.f_filialeids"
                        :options='$parent.$parent.organization.company'
                        @change="$parent.$parent.getOrganization('t_department', model.f_filialeids[0])"
                        placeholder='请选择'
                        condition="f_filialeids like '%{}%'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="endDate" class="control-label">部门</label>
              <v-select :value.sync="model.f_orgstr"
                        v-model="model.f_orgstr"
                        :options='$parent.$parent.organization.department'
                        @change="$parent.$parent.getOrganization('t_user', model.f_orgstr[0])"
                        placeholder='请选择'
                        condition="f_orgstr like '%{}%'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="endDate" class="control-label">人员</label>
              <v-select :value.sync="model.f_operatorid"
                        v-model="model.f_operatorid"
                        :options='$parent.$parent.organization.personnel'
                        placeholder='请选择'
                        condition="f_operator = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label class="control-label">收费状态</label>
              <v-select :value.sync="model.f_charge_state"
                        v-model="model.f_charge_state"
                        :options='$parent.$parent.charge_state' placeholder='请选择'
                        condition="f_charge_state = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="startDate" class="control-label">收费日期</label>
              <datepicker id="startDate" placeholder="开始日期" width='100%'
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="true"
                          condition="f_delivery_date >= '{}'">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group form-input-group" style="width: 20%">
              <label for="endDate" class="control-label">收费日期</label>
              <datepicker id="endDate" placeholder="结束日期" width='100%'
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="true"
                          condition="f_delivery_date <= '{}'">
              </datepicker>
            </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_isbill"
                        v-model="model.f_isbill"
                        :options='$parent.$parent.isbills' placeholder='请选择'
                        condition="f_isbill {}"
                        close-on-select></v-select>
            </div>
            <!--            <div class="col-sm-3 form-group form-input-group" style="width: 20%">-->
            <!--              <label class="control-label">供暖开始</label>-->
            <!--              <datepicker placeholder="开始日期" width='100%'-->
            <!--                          v-model="model.f_input_date"-->
            <!--                          :value.sync="model.f_input_date"-->
            <!--                          :format="'yyyy-MM-dd 00:00:00'"-->
            <!--                          :show-reset-button="true"-->
            <!--                          condition="f_input_date >= '{}'">-->
            <!--              </datepicker>-->
            <!--            </div>-->
            <!--            <div class="col-sm-3 form-group form-input-group" style="width: 20%">-->
            <!--              <label class="control-label">供暖结束</label>-->
            <!--              <datepicker placeholder="结束日期" width='100%'-->
            <!--                          v-model="model.f_end_date"-->
            <!--                          :value.sync="model.f_end_date"-->
            <!--                          :format="'yyyy-MM-dd 23:59:59'"-->
            <!--                          :show-reset-button="true"-->
            <!--                          condition="f_end_date <= '{}'">-->
            <!--              </datepicker>-->
            <!--            </div>-->
          </div>
          <div class="row">
            <div class="span" style = "float:right;margin-top:10px">
              <button class="btn btn-success" style="border-radius: 2px;margin-right: 10px" @click="search()">查询</button>
              <button class="btn btn-success" style="border-radius: 2px;margin-right: 10px" @click="$parent.$parent.clear()">清空</button>
              <button class="btn btn-default" style="border-radius: 2px;margin-right: 10px"
                      type="button" @click="$parent.$parent.stamp()">打印</button>

              <export-excel :data="$parent.$parent.getCondition"
                            :field="$parent.$parent.getfield"
                            sqlurl="rs/logic/exportfile" sql-name="newsellQuery" template-name='收费查询导出'  :choose-col="true"></export-excel>

              <button class="btn" @click="$parent.$parent.hidden()" style="margin-left: 10px">
                <span class="glyphicon glyphicon-chevron-up"></span>
              </button>

              <button class="btn" @click="$launchFullscreen('charge-query')" style="padding-left: 10px">
                <span class="glyphicon glyphicon-fullscreen" style="color: #337ab7"></span>
              </button>
            </div>
          </div>
        </div>
      </criteria>

      <data-grid  :model="model" partial='list' v-ref:grid :classname="$parent.classname" @dblclick="$parent.dblclick">
        <template partial='head'>
          <tr>
            <th>
              <input type="checkbox" id="f_operator" v-model="$parent.$parent.$parent.all_select[model.pageIndex-1]"
                     @change="$parent.$parent.$parent.select()"/>
            </th>
            <th v-for="item in $parent.$parent.$parent.headData"><nobr>{{item}}</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center">
            <input :id="'body'+model.pageIndex" type='checkbox'
                   @change="$parent.$parent.$parent.selectOne($event,row,$index)"
                   :checked="$parent.$parent.$parent.ischecked(model.pageIndex-1,$index)"/>
          </td>

          <td style="text-align: center" v-for="item in $parent.$parent.$parent.bodyData">
            <nobr v-if="item !== '操作' && item !== 'f_isbill'">{{row[item]}}</nobr>
            <nobr v-if="item === 'f_isbill'">
              <span v-if="row[item] === '是'">{{row[item]}}</span>
              <button v-else style=" height: 28px;line-height: 16px;" class="button_search button_spacing width-60"
                      @click.stop="$parent.$parent.$parent.$parent.openBill(row)">开票</button>
            </nobr>
            <a @click="$parent.$parent.$parent.$parent.doShowUpdate(row)" v-if="item === '操作'">修&nbsp;&nbsp;改</a>
          </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">气量合计:&emsp;{{sumsmodel.f_pregas}}</td>-->
        <!--<td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">应交金额合计:&emsp;{{sumsmodel.f_preamount}}</td>-->
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">收款合计:&emsp;{{sumsmodel.f_collection}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">实用面积合计:&emsp;{{countmodel.coverd_area}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">应交金额合计:&emsp;{{sumsmodel.f_preamount}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">滞纳金合计:&emsp;{{sumsmodel.f_delay}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">减免金额合计:&emsp;{{sumsmodel.f_credit_amount}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">户数合计:&emsp;{{countmodel.user_count}}</td>
      </tr>
    </table>
    <!--<colligate-details :showinfo="showinfo" :businesstype="businesstype" :data="data" @close-info="showinfo=false"></colligate-details>-->
    <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>
    <modal :show.sync="updateShow" backdrop="false" width="1200px" align="center">
      <header slot="modal-header" class="modal-header text-center">
      </header>
      <article slot="modal-body">
        <form class="form-horizontal" style="margin-right:30px">
          <div class="row">
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">用户编号</label>
              <input type="text" v-model="currentRow.f_userinfo_code" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">用户姓名</label>
              <input type="text" v-model="currentRow.f_user_name" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">用户电话</label>
              <input type="text" v-model="currentRow.f_user_phone" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">层高费</label>
              <input type="text" v-model="currentRow.floor_height_fee" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">热辐射费</label>
              <input type="text" v-model="currentRow.f_thermal_radiation_fee" disabled=disabled
                     class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">供暖费</label>
              <input type="text" v-model="currentRow.f_preamount" disabled=disabled class="form-control">
            </div>

            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">应交金额</label>
              <input type="text" v-model="currentRow.f_collection" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">减免金额</label>
              <input type="text" v-model="currentRow.f_credit_amount" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">上期结余</label>
              <input type="text" v-model="currentRow.f_balance" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">本期结余</label>
              <input type="text" v-model="currentRow.f_curbalance" disabled=disabled class="form-control">
            </div>

            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">收费类型</label>
              <input type="text" v-model="currentRow.f_charge_type" disabled=disabled class="form-control">
            </div>

            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">用户类型</label>
              <input type="text" v-model="currentRow.f_user_type" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">用热性质</label>
              <input type="text" v-model="currentRow.f_gasproperties" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">供暖面积</label>
              <input type="text" v-model="currentRow.f_covered_area" disabled=disabled class="form-control">
            </div>

            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">类型</label>
              <input type="text" v-model="currentRow.f_expense_type" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">热价名称</label>
              <input type="text" v-model="currentRow.f_price_name" disabled=disabled class="form-control">
            </div>

            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">小区</label>
              <input type="text" v-model="currentRow.f_residential_area" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">用户地址</label>
              <input type="text" v-model="currentRow.f_address" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">营业网点</label>
              <input type="text" v-model="currentRow.f_outlets" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">分公司</label>
              <input type="text" v-model="currentRow.f_filiale" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label">流水号</label>
              <input type="text" v-model="currentRow.f_serial_id" disabled=disabled class="form-control">
            </div>
            <div class="col-sm-4 form-group form-input-group">
              <label class="control-label" style="color: #3c763d">付款方式</label>
              <v-select :value.sync="modifyData.f_payment"
                        v-model="modifyData.f_payment"
                        :options='changePayment'
                        :value-single="true"
                        close-on-select
              ></v-select>

              <!--<input type="text" v-model="currentRow.f_payment" disabled=disabled class="form-control">-->
            </div>
            <!--            <div class="col-sm-4 form-group form-input-group">-->
            <!--                <label class="control-label">是否供暖</label>-->
            <!--                <v-select-->
            <!--                  v-model="modifyData.f_heating"-->
            <!--                  placeholder='请选择'-->
            <!--                  :options='f_is_heating'-->
            <!--                  :value.sync="modifyData.f_heating"-->
            <!--                  close-on-select clear-button ></v-select>-->
            <!--            </div>-->
            <!--            <div class="col-sm-4 form-group form-input-group">-->
            <!--              <label class="control-label" style="color: #3c763d">供热开始</label>-->
            <!--              <datepicker placeholder="开始日期" width='100%'-->
            <!--                          v-model="modifyData.f_input_date"-->
            <!--                          :value.sync="modifyData.f_input_date"-->
            <!--                          :format="'yyyy-MM-dd 00:00:00'"-->
            <!--                          :show-reset-button="true">-->
            <!--              </datepicker>-->
            <!--            </div>-->
            <!--            <div class="col-sm-4 form-group form-input-group">-->
            <!--              <label class="control-label" style="color: #3c763d">供热结束</label>-->
            <!--              <datepicker placeholder="结束日期" width='100%'-->
            <!--                          v-model="modifyData.f_end_date"-->
            <!--                          :value.sync="modifyData.f_end_date"-->
            <!--                          :format="'yyyy-MM-dd 23:59:59'"-->
            <!--                          :show-reset-button="true">-->
            <!--              </datepicker>-->
            <!--            </div>-->
          </div>
        </form>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-success" @click='doSaveUpdate()'>确定</button>
        <button type="button" class="btn btn-default" @click='closeUpdate()'>取消</button>
      </footer>
    </modal>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import defaultPrint from './config/DefaultPrint'
import {HttpResetClass} from 'vue-client'

let readySomething = async function (self) {
  // self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString() + ' 00:00:00'
  self.$refs.paged.$refs.cri.model.startDate = new Date().getFullYear() - 1 + '-09-15 00:00:00'
  self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString() + ' 23:59:59'
  self.$refs.paged.$refs.cri.model.f_charge_state = ['有效']

  await self.$refs.paged.$refs.cri.search()
  self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
}
export default {
  data() {
    return {
      showinfo: false,
      businesstype: '收费查询',
      data: {},
      model: new PagedList('rs/sql/newsellQuery', 20,{},{f_collection: 0,f_preamount :0, f_credit_amount :0}),
      criteriaShow: true,
      classname: 'table table-bordered table table-hover',
      headData: [],
      bodyData: [],
      tableData: [
        ["f_userinfo_code", "用户编号"], ["f_user_name", "用户姓名"], ["f_user_phone", "用户电话"],["f_covered_area","供热面积"], ["f_preamount", "应交金额"],
        ["f_delay","滞纳金"], ["f_collection", "收款"], ["f_credit_amount", "减免金额"], ["f_balance", "上期结余"], ["f_curbalance", "本期结余"], ["f_delivery_date", "收费日期"], ["f_mark", "费用区间"],
        ["f_operator", "操作员"], ["f_charge_state", "状态"], ["f_charge_type", "收费类型"], ["f_user_type", "用户类型"],
        ["f_gasproperties", "供暖性质"], ["f_price_name", "名称"], ["f_payment", "付款方式"], ["f_residential_area", "小区"],
        ["f_address", "用户地址"], ["f_outlets", "营业网点"], ["f_filiale", "分公司"],["f_isbill", "电子票已开"],["操作", "操作"]
      ],
      filialeNameStr: null,
      filialeCodeStr: this.$login.f.f_orgids,
      userid: this.$login.f.id,
      source:`tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() != $role$))`,

      modelval: [],
      printshow: false,
      all: false,
      fields: {},
      thead: '',
      tfoot: '',
      //合计数据
      sumsmodel: {},
      countmodel: {},
      currentRow: {},
      f_operators: [],
      updateShow: false,
      // 要修改的值
      modifyData: {
        f_payment: '',
        f_charge_state: '', // 状态
        f_operator: '',
        f_delivery_date: '', // 收费时间
        f_input_date: '',
        f_end_date: '',
        sellid: '',
        f_mark: '',
        f_userinfo_id: '',
        username: '',
        filialeCodeStr: '',
        f_heating:''
      },
      //选择的用户
      rowsdata: [],
      //控制全选
      all_select: [],
      isbills: [{label: '全部', value: ''}, {label: '是', value: `= '是'`}, {label: '否', value: `is null`}],
      //控制单选
      radio: [],
      organization: {
        company: [],
        department: [],
        personnel: []
      }
    }
  },
  ready(){
    const map = new Map(this.tableData)
    for (let [key, value] of map) {
      this.bodyData.push(key)
      this.headData.push(value)
    }
    this.initOperator('1=1')
    this.getOrganization('t_organization', null)
    readySomething(this).then(() => {
      this.$emit('ready')
    }).catch((error) => {
      this.$emit('error', error)
    })
  },
  methods: {
    async getOrganization(tableName, parentId) {
      console.log('方法参数', tableName, parentId)
      tableName = tableName === null ? 't_organization' : tableName
      if(tableName !== 't_organization' && parentId === null && parentId === '' && parentId === undefined) {
        console.log('>>>>>>', 1)
        self.$showMessage(tableName === 't_department' ? '必须选择一个公司' : '必须选择一个部门')
      }

      const params = {
        tableName: tableName,
        parentId: parentId
      }

      await this.$resetpost('rs/logic/getOrganization', {data: params}, {resolveMsg: null, rejectMsg: null}).then(res => {
        const tData = []
        if(tableName==='t_user'){
          res.data.forEach(i => {
            tData.push({
              label: i.name,
              value: i.name
            })
          })
        }else{
          res.data.forEach(i => {
            tData.push({
              label: i.name,
              value_name: i.name,
              value: i.id
            })
          })
        }

        switch(tableName) {
          case 't_organization':
            this.organization.company = tData
            break
          case 't_department':
            this.organization.department = tData
            break
          case 't_user':
            this.organization.personnel = tData
        }
      })

    },
    openBill(row){
      console.log('点击开票了')
      this.$showMessage('您确定为当前收费记录开具电子发票吗？', ['confirm', 'cancel']).then(async (res) => {
        if (res === 'confirm') {
          let HttpReset = new HttpResetClass()
          let data = {
            id: row.id
          }
          await HttpReset.load('POST', 'rs/logic/heat_changeBillState', {data: data}, {resolveMsg: '开票成功！！！', rejectMsg: '开票失败！！！'})
          this.$refs.paged.$refs.cri.search()
        }
      })
    },
    selectInit() {
      this.rowsdata = []
      this.all_select = []
      this.radio = []
    },
    dblclick(obj) {
      this.data = obj
      this.showinfo = true
    },
    async selfSearch (args) {
      this.selectInit()
      let f_orgstr = this.filialeCodeStr
      console.log('xxxx',f_orgstr)
      args.condition =  `${args.condition} and f_orgstr like '${f_orgstr}%'`
      console.log('我的阐述',JSON.stringify(args.condition))
      await this.model.search(args.condition, args.model)

      this.sumsmodel = this.$refs.paged.$refs.grid.model.sums
      await this.$resetpost('rs/sql/sellUserQuery',{data:{condition:args.condition}},{resolveMsg: null, rejectMsg: null}).then((res) => {
        this.countmodel = res.data.length > 0 ? res.data[0] : {}
      })
      console.log('合计字段',this.sumsmodel)
    },
    clear(){
      Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
        this.$refs.paged.$refs.cri.model[key] = []
      })

    },
    show(){
      this.criteriaShow = true
    },
    hidden(){
      this.criteriaShow = false
    },
    getRes(obj) {
      this.filialeNameStr = obj.res
      this.filialeCodeStr = obj.resids
    },
    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
    },
    // 对选择的列进行排序
    sortModelval () {
      let sortModel = []
      Object.keys(this.fields).forEach((key) => {
        if (this.modelval.includes(key)) {
          sortModel.push(key)
        }
      })
      this.modelval = sortModel
      console.log('选择的打印的字段', this.modelval)
    },
    closeUpdate() {
      this.updateShow = false
    },
    doSaveUpdate() {
      this.modifyData.f_payment = this.modifyData.f_payment.toString()
      this.modifyData.f_mark = this.modifyData.f_input_date.toString().substring(0,10) +'到'+ this.modifyData.f_end_date.toString().substring(0,10)
      debugger
      let data = {
        modifyData: this.modifyData,
        f_outlets: this.$login.f.f_parentname,
        f_filiale: this.$login.f.f_fengongsi,
        operatorname: this.$login.f.name,
        f_orgstr: this.$login.f.orgpathstr,
        f_filialeids : this.$login.f.f_orgids
      }
      this.$resetpost('rs/logic/updateSellinggas', {data: data}, {resolveMsg: '修改成功', rejectMsg: '修改失败'})
      this.updateShow = false
    },
    doShowUpdate(row) {
      this.currentRow = row
      this.modifyData.f_charge_state = row.f_charge_state
      this.modifyData.f_delivery_date = row.f_delivery_date
      this.modifyData.f_payment = row.f_payment
      this.modifyData.f_operator = row.f_operator
      this.modifyData.f_input_date = row.f_input_date
      this.modifyData.f_end_date = row.f_end_date
      this.modifyData.sellid = row.id
      this.modifyData.f_userinfo_id = row.f_userinfo_id
      this.modifyData.username = row.f_user_name
      this.modifyData.filialeCodeStr = this.filialeCodeStr
      this.updateShow = true
    },
    selectOne(event, row, i) {
      console.log("单选", event.target.checked)
      console.log("event",JSON.stringify(event))
      console.log("row",JSON.stringify(row))

      let index = this.model.pageIndex - 1
      console.log("index===>",index)
      if (!this.rowsdata[index]) {
        this.rowsdata[index] = []
      }
      if (!this.radio[index]) {
        this.radio.$set(index, [])
      }
      if (event.target.checked) {
        //数据
        this.rowsdata[index][i] = row
        //勾选
        this.radio[index].$set(i, true)
        //判断是否全部选中
        var allState = true
        if (this.model.rows.length != this.radio[index].length) {
          allState = false
        }
        for (var state of this.radio[index]) {
          if (!state) {
            allState = false
          }
        }
        if (allState) {
          this.all_select.$set(index, true)
        } else {
          this.all_select.$set(index, false)
        }
      } else {
        //数据
        this.rowsdata[index][i] = []
        //不勾选
        this.radio[index].$set(i, false)
        //任意取消一个则全选状态设为false
        this.all_select.$set(index, false)
      }
    },
    ischecked() {
      return function (index, i) {
        // console.log("计算属性")
        if (!this.radio[index]) {
          return false
        }
        return this.radio[index][i]
      }
    },
    async initOperator (pconditon) {
      this.f_operators = []
      let HttpReset = new HttpResetClass()
      let req = await HttpReset.load('POST', 'rs/sql/manageSingleTable', {
        data: {
          items: '*',
          tablename: 't_user',
          orderitem: 'id',
          condition: pconditon
        }
      },{resolveMsg: null, rejectMsg: null})
      let redata = []
      req.data.forEach((row, n) => {
        redata[n] = {
          label: row.name,
          value: row.name,
        }
      })
      this.f_operators = redata
    }
  },
  watch:{
    'all' (val) {
      if (val) {
        this.modelval = this.bodyData
      } else {
        this.modelval = defaultPrint.config
        this.put()
      }
    },
    'modelval.length' () {
      this.put()
    },
    'model.f_payment': {
      handler(newValue) {
        console.log('变化:', newValue);
      },
      deep: true
    }
  },
  computed:{
    residential_area () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('小区')]
    },
    getCondition(){
      return {condition: `${this.$refs.paged.$refs.cri.condition}  and f_orgstr like '${this.filialeCodeStr}%'`}
    },
    getfield(){
      let data = {}
      this.bodyData.forEach((value, index)=>{
        if(this.headData[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
    },
    usertypes () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
    },
    user_state () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')]
    },
    gasproperties () {
      let rs = []
      if (this.$refs.paged.$refs.cri.model.f_user_type.length === 1) {
        rs = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
      }
      return [{label: '全部', value: ''}, ...rs]
    },
    pricenames () {
      let arr = []
      this.$GetSaleParam.getOnlyPrice().forEach((item) => {
        console.log('看看气价的分公司..', item.value, this.$login.f.f_filiale)
        if (item.value) {
          if (this.$login.f.f_fengongsi === item.value.f_filiale) {
            let temp = {}
            temp.label = item.label
            temp.value = item.value.f_price_name
            arr.push(temp)
          }
        }
      })
      return [{label: '全部', value: ''}, ...arr]
    },
    metertypes () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
    },
    meterbrands () {
      let arr = []
      this.$GetSaleParam.getGasbrand().forEach((item) => {
        let temp = {}
        temp.label = item.label
        temp.value = item.value.f_meter_brand
        arr.push(temp)
      })
      return [{label: '全部', value: ''}, ...arr]
    },
    tablestate () {
      return [{label: '全部', value: ''}, {label: '正常', value: '正常'}, {label: '停用', value: '停用'}]
    },
    chargetype () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('收费类型')]
    },

    payments () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('付款方式')]
    },

    charge_state(){
      return [{label: '全部', value: ''},...this.$appdata.getParam('收费状态')]
    },
    modify_charge_state(){
      return [...this.$appdata.getParam('收费状态')]
    },
    changePayment() {
      return [...this.$appdata.getParam('付款方式')]
    },
    f_is_heating(){
      return [...this.$appdata.getParam('是否')]
    },
  }
}
</script>
