<template>
  <div class="flex-row">
    <work-busy :is-busy="seaching" v-show="seaching"></work-busy>
    <div class="basic-main">
      <div  class="form-horizontal select-overspread container-fluid auto" >
        <div class="row">
          <div class="col-sm-3" style="width: 20%">
            <label class="font_normal_body">&nbsp;公&nbsp;&nbsp;&nbsp;&nbsp;司&nbsp;</label>
            <right-tree :userid.sync='userid' style="width: 60%;"
                        :source.sync='source' @re-res="getRes" ></right-tree>
          </div>
          <div class="col-sm-3" style="width: 20%">
            <label class="font_normal_body">统计年份</label>
            <datepicker  placeholder="结束日期" style="width:60%"
                         v-model="yearDate"
                         :value.sync="yearDate"
                         :format="'yyyy'"
                         :show-reset-button="true"
                         :select-year="true">
            </datepicker>
          </div>
          <div class="col-sm-3" style="width: 20%">
            <label class="font_normal_body">用户编号</label>
            <input type="text" class="input_search" v-model="searchModel.f_userinfo_code"
                   style="width: 60%" placeholder="用户编号">
          </div>
          <div class="col-sm-3" style="width: 20%">
            <label class="font_normal_body">地&emsp;&emsp;址</label>
            <input type="text" class="input_search" v-model="searchModel.f_address"
                   style="width: 60%" placeholder="地址">
          </div>


          <div class="col-sm-3" style="width: 20%">
            <div class="span" style="text-align: center;">
              <button class="button_search" @click="search()">查询</button>
              <export-excel   :data="searchData"
                              :field="excelHeaders"
                              sqlurl="api/af-safecheck/logic/exportfile" sql-name="MonthlyMeterReadingStatisticsExcel"
                              :template-name='excelTitle'></export-excel>
            </div>
          </div>
        </div>
        <div class="row">
          <div  class="col-sm-3" style="width: 20%">
            <label class="font_normal_body">用气性质</label>
            <v-select
              placeholder='用气性质'
              class="select select_list"
              style="width:60%"
              :value-single="true"
              v-model='searchModel.f_gasproperties'
              :value.sync="searchModel.f_gasproperties"
              :options='f_gaspropertieses'
              v-next-el="cx" v-el:qjmc
              close-on-select clear-button> </v-select>
          </div>
        </div>
      </div>

      <div class="table-responsive" style="width:100%; height:82%; overflow:scroll;">
        <table class="table diy-table " style="text-align:center">
          <thead>
          <tr>
            <th colspan="259" class="tableinfo">{{thisOrgName}}{{thisYear}}年度工商业抄表情况统计表</th>
          </tr>
          <tr>
            <th colspan="19" style="background-color: #e5e5e5;">用户基本信息</th>
            <template v-for="index in 12">
              <th colspan="20" class="tablerowclass">{{index+1}}月</th>
            </template>
          </tr>
          <tr>
            <th class="borderleftright"><nobr>序号</nobr></th>
            <th class="borderleftright"><nobr>公司</nobr></th>
            <th class="borderleftright"><nobr>用户名称</nobr></th>
            <th class="borderleftright"><nobr>用户编号</nobr></th>
            <th class="borderleftright"><nobr>用气性质</nobr></th>
            <th class="borderleftright"><nobr>用户地址</nobr></th>
            <th class="borderleftright"><nobr>表具类型</nobr></th>
            <th class="borderleftright"><nobr>远传站点编号</nobr></th>
            <th class="borderleftright"><nobr>仪表品牌（厂家）</nobr></th>
            <th class="borderleftright"><nobr>计量类型</nobr></th>
            <th class="borderleftright"><nobr>仪表型号</nobr></th>
            <th class="borderleftright"><nobr>仪表编号</nobr></th>
            <th class="borderleftright"><nobr>仪表口径</nobr></th>
            <th class="borderleftright"><nobr>铅封编号</nobr></th>
            <th class="borderleftright"><nobr>准确度等级</nobr></th>
            <th class="borderleftright"><nobr>量程下限</nobr></th>
            <th class="borderleftright"><nobr>量程上限</nobr></th>
            <th class="borderleftright"><nobr>流量计投运时间</nobr></th>
            <th class="borderleftright"><nobr>计量方式</nobr></th>
            <template v-for="index in 12">
              <th class="borderleftright"><nobr>上期标况累计（抄表）</nobr></th>
              <th class="borderleftright"><nobr>上期表剩余（抄表）</nobr></th>
              <th class="borderleftright"><nobr>上期抄表时间（抄表）</nobr></th>
              <th class="borderleftright"><nobr>本期标况累计（抄表）</nobr></th>
              <th class="borderleftright"><nobr>本期表剩余（抄表）</nobr></th>
              <th class="borderleftright"><nobr>本期抄表时间（抄表）</nobr></th>
              <th title="本期标况累计减上期标况累计；如存在换流量计，（旧流量计标况累计减旧流量计上期标况累计）加新流量计本期标况累计" class="borderleftright"><nobr>期间用气量1(抄表)</nobr></th>
              <th title="用上期抄表剩余加上期间充值量减去本期剩余量" class="borderleftright"><nobr>期间用气量2(抄表)</nobr></th>
              <th title="期间充值量" class="borderleftright"><nobr>期间充值量(收费)</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>上期标况累计（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>上期表剩余（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>上期上报时间（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>上期数据是否异常（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>本期标况累计（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>本期表剩余（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>本期上报时间（远传）</nobr></th>
              <th title="调取每月25日早8点数据" class="borderleftright"><nobr>本期数据是否异常（远传）</nobr></th>
              <th title="本期标况累计减去上期标况累计" class="borderleftright"><nobr>期间用气量3（远传）</nobr></th>
              <th title="期间用气量1减去期间用气量2（流量计计数用量与充值器扣数差值）" class="borderleftright"><nobr>气量差值1</nobr></th>
              <th title="期间用气量1减去期间用气量3（实际抄表用量与远传用量差值）" class="borderleftright"><nobr>气量差值2</nobr></th>
            </template>
          </tr>
          </thead>
          <tbody id="manbody">
          </tbody>
        </table>
      </div>

      <pager :page-index="pageIndex" :page-size.sync="pageSize"
             @page-changed='search' :count='count'>
      </pager>
    </div>
  </div>
</template>

<script>
import {HttpResetClass, PagedList} from "vue-client";
import Datepicker from 'vue-client/src/vue-strap/src/Datepicker'
import * as Util from '../Util'
import Pager from 'vue-client/src/components/Pager'
import Vue from "vue";
import XLSX from "xlsx";


export default {
  title:'月度抄表报表（年度）',
  data() {
    return {
      f_gaspropertieses:[{label:"全部",value:""},{label:"商业用气",value:"商业用气"},{label:"工业用气",value:"工业用气"}],
      searchModel: {
        f_userinfo_code: '',
        f_address: '',
      },
      seaching: false,
      userid: this.$login.f.id,
      body:'',
      source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
      f_filialeids:`('${this.$login.f.orgid}')`, //分公司id
      yearDate: (new Date()).getFullYear().toString(), //统计年份
      resData: [],
      baseData: [],
      thisOrgName: '',
      thisYear: '',
      f_orgname: '',
      count: 0, //总数据数
      pageIndex: 1, //当前页
      pageSize: 20, //页大小
      condition: '1=1', //请求条件
      searchData: {

      },
      excelTitle:'导出',
      excelHeaders:{
        "name": "公司",
        "f_userinfo_code": "用户编号",
        "f_user_name": "用户名称",
        "f_gasproperties": "用气性质",
        "f_address": "用户地址",
        "f_meter_brand": "表具类型",
        "cj": "仪表品牌（厂家）",
        "sta_id": "远传站点编号",
        "lx": "计量类型",
        "xh": "仪表型号",
        "sn": "仪表编号",
        "kj": "仪表口径",
        "qf": "铅封编号",
        "jd": "准确度等级",
        "min": "量程下限",
        "max": "量程上限",
        "usetime": "流量计投运时间",
        "jlfs": "计量方式",
        "f_last_flow_standard_total1_1": "1月上期标况累计（抄表）",
        "f_last_surplus_gas1_1": "1月上期表剩余（抄表）",
        "f_last_f_hand_date1_1": "1月上期抄表时间（抄表）",
        "f_flow_standard_total_1": "1月本期标况累计（抄表）",
        "f_surplus_gas_1": "1月本期表剩余（抄表）",
        "f_hand_date_1": "1月本期抄表时间（抄表）",
        "gas_consumption1_1": "1月期间用气量1（抄表）",
        "gas_consumption2_1": "1月期间用气量2（抄表）",
        "sumpregas_1": "1月期间充值量（收费）",
        "f_last_pile_gas_volume_1": "1月上期标况累计（远传）",
        "f_last_residual_gas_volume_1": "1月上期表剩余（远传）",
        "f_last_upload_date_1": "1月上期上报时间（远传）",
        "f_last_isabn_1": "1月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_1": "1月本期标况累计（远传）",
        "f_residual_gas_volume_1": "1月本期表剩余（远传）",
        "f_upload_date_1": "1月本期上报时间（远传）",
        "f_isabn_1": "1月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_1": "1月期间用气量3（远传）",
        "d_value1_1": "1月气量差值1（远传）",
        "d_value2_1": "1月气量差值2（远传）",
        "f_last_flow_standard_total1_2": "2月上期标况累计（抄表）",
        "f_last_surplus_gas1_2": "2月上期表剩余（抄表）",
        "f_last_f_hand_date1_2": "2月上期抄表时间（抄表）",
        "f_flow_standard_total_2": "2月本期标况累计（抄表）",
        "f_surplus_gas_2": "2月本期表剩余（抄表）",
        "f_hand_date_2": "2月本期抄表时间（抄表）",
        "gas_consumption1_2": "2月期间用气量1（抄表）",
        "gas_consumption2_2": "2月期间用气量2（抄表）",
        "sumpregas_2": "2月期间充值量（收费）",
        "f_last_pile_gas_volume_2": "2月上期标况累计（远传）",
        "f_last_residual_gas_volume_2": "2月上期表剩余（远传）",
        "f_last_upload_date_2": "2月上期上报时间（远传）",
        "f_last_isabn_2": "2月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_2": "2月本期标况累计（远传）",
        "f_residual_gas_volume_2": "2月本期表剩余（远传）",
        "f_upload_date_2": "2月本期上报时间（远传）",
        "f_isabn_2": "2月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_2": "2月期间用气量3（远传）",
        "d_value1_2": "2月气量差值1（远传）",
        "d_value2_2": "2月气量差值2（远传）",
        "f_last_flow_standard_total1_3": "3月上期标况累计（抄表）",
        "f_last_surplus_gas1_3": "3月上期表剩余（抄表）",
        "f_last_f_hand_date1_3": "3月上期抄表时间（抄表）",
        "f_flow_standard_total_3": "3月本期标况累计（抄表）",
        "f_surplus_gas_3": "3月本期表剩余（抄表）",
        "f_hand_date_3": "3月本期抄表时间（抄表）",
        "gas_consumption1_3": "3月期间用气量1（抄表）",
        "gas_consumption2_3": "3月期间用气量2（抄表）",
        "sumpregas_3": "3月期间充值量（收费）",
        "f_last_pile_gas_volume_3": "3月上期标况累计（远传）",
        "f_last_residual_gas_volume_3": "3月上期表剩余（远传）",
        "f_last_upload_date_3": "3月上期上报时间（远传）",
        "f_last_isabn_3": "3月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_3": "3月本期标况累计（远传）",
        "f_residual_gas_volume_3": "3月本期表剩余（远传）",
        "f_upload_date_3": "3月本期上报时间（远传）",
        "f_isabn_3": "3月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_3": "3月期间用气量3（远传）",
        "d_value1_3": "3月气量差值1（远传）",
        "d_value2_3": "3月气量差值2（远传）",
        "f_last_flow_standard_total1_4": "4月上期标况累计（抄表）",
        "f_last_surplus_gas1_4": "4月上期表剩余（抄表）",
        "f_last_f_hand_date1_4": "4月上期抄表时间（抄表）",
        "f_flow_standard_total_4": "4月本期标况累计（抄表）",
        "f_surplus_gas_4": "4月本期表剩余（抄表）",
        "f_hand_date_4": "4月本期抄表时间（抄表）",
        "gas_consumption1_4": "4月期间用气量1（抄表）",
        "gas_consumption2_4": "4月期间用气量2（抄表）",
        "sumpregas_4": "4月期间充值量（收费）",
        "f_last_pile_gas_volume_4": "4月上期标况累计（远传）",
        "f_last_residual_gas_volume_4": "4月上期表剩余（远传）",
        "f_last_upload_date_4": "4月上期上报时间（远传）",
        "f_last_isabn_4": "4月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_4": "4月本期标况累计（远传）",
        "f_residual_gas_volume_4": "4月本期表剩余（远传）",
        "f_upload_date_4": "4月本期上报时间（远传）",
        "f_isabn_4": "4月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_4": "4月期间用气量3（远传）",
        "d_value1_4": "4月气量差值1（远传）",
        "d_value2_4": "4月气量差值2（远传）",
        "f_last_flow_standard_total1_5": "5月上期标况累计（抄表）",
        "f_last_surplus_gas1_5": "5月上期表剩余（抄表）",
        "f_last_f_hand_date1_5": "5月上期抄表时间（抄表）",
        "f_flow_standard_total_5": "5月本期标况累计（抄表）",
        "f_surplus_gas_5": "5月本期表剩余（抄表）",
        "f_hand_date_5": "5月本期抄表时间（抄表）",
        "gas_consumption1_5": "5月期间用气量1（抄表）",
        "gas_consumption2_5": "5月期间用气量2（抄表）",
        "sumpregas_5": "5月期间充值量（收费）",
        "f_last_pile_gas_volume_5": "5月上期标况累计（远传）",
        "f_last_residual_gas_volume_5": "5月上期表剩余（远传）",
        "f_last_upload_date_5": "5月上期上报时间（远传）",
        "f_last_isabn_5": "5月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_5": "5月本期标况累计（远传）",
        "f_residual_gas_volume_5": "5月本期表剩余（远传）",
        "f_upload_date_5": "5月本期上报时间（远传）",
        "f_isabn_5": "5月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_5": "5月期间用气量3（远传）",
        "d_value1_5": "5月气量差值1（远传）",
        "d_value2_5": "5月气量差值2（远传）",
        "f_last_flow_standard_total1_6": "6月上期标况累计（抄表）",
        "f_last_surplus_gas1_6": "6月上期表剩余（抄表）",
        "f_last_f_hand_date1_6": "6月上期抄表时间（抄表）",
        "f_flow_standard_total_6": "6月本期标况累计（抄表）",
        "f_surplus_gas_6": "6月本期表剩余（抄表）",
        "f_hand_date_6": "6月本期抄表时间（抄表）",
        "gas_consumption1_6": "6月期间用气量1（抄表）",
        "gas_consumption2_6": "6月期间用气量2（抄表）",
        "sumpregas_6": "6月期间充值量（收费）",
        "f_last_pile_gas_volume_6": "6月上期标况累计（远传）",
        "f_last_residual_gas_volume_6": "6月上期表剩余（远传）",
        "f_last_upload_date_6": "6月上期上报时间（远传）",
        "f_last_isabn_6": "6月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_6": "6月本期标况累计（远传）",
        "f_residual_gas_volume_6": "6月本期表剩余（远传）",
        "f_upload_date_6": "6月本期上报时间（远传）",
        "f_isabn_6": "6月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_6": "6月期间用气量3（远传）",
        "d_value1_6": "6月气量差值1（远传）",
        "d_value2_6": "6月气量差值2（远传）",
        "f_last_flow_standard_total1_7": "7月上期标况累计（抄表）",
        "f_last_surplus_gas1_7": "7月上期表剩余（抄表）",
        "f_last_f_hand_date1_7": "7月上期抄表时间（抄表）",
        "f_flow_standard_total_7": "7月本期标况累计（抄表）",
        "f_surplus_gas_7": "7月本期表剩余（抄表）",
        "f_hand_date_7": "7月本期抄表时间（抄表）",
        "gas_consumption1_7": "7月期间用气量1（抄表）",
        "gas_consumption2_7": "7月期间用气量2（抄表）",
        "sumpregas_7": "7月期间充值量（收费）",
        "f_last_pile_gas_volume_7": "7月上期标况累计（远传）",
        "f_last_residual_gas_volume_7": "7月上期表剩余（远传）",
        "f_last_upload_date_7": "7月上期上报时间（远传）",
        "f_last_isabn_7": "7月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_7": "7月本期标况累计（远传）",
        "f_residual_gas_volume_7": "7月本期表剩余（远传）",
        "f_upload_date_7": "7月本期上报时间（远传）",
        "f_isabn_7": "7月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_7": "7月期间用气量3（远传）",
        "d_value1_7": "7月气量差值1（远传）",
        "d_value2_7": "7月气量差值2（远传）",
        "f_last_flow_standard_total1_8": "8月上期标况累计（抄表）",
        "f_last_surplus_gas1_8": "8月上期表剩余（抄表）",
        "f_last_f_hand_date1_8": "8月上期抄表时间（抄表）",
        "f_flow_standard_total_8": "8月本期标况累计（抄表）",
        "f_surplus_gas_8": "8月本期表剩余（抄表）",
        "f_hand_date_8": "8月本期抄表时间（抄表）",
        "gas_consumption1_8": "8月期间用气量1（抄表）",
        "gas_consumption2_8": "8月期间用气量2（抄表）",
        "sumpregas_8": "8月期间充值量（收费）",
        "f_last_pile_gas_volume_8": "8月上期标况累计（远传）",
        "f_last_residual_gas_volume_8": "8月上期表剩余（远传）",
        "f_last_upload_date_8": "8月上期上报时间（远传）",
        "f_last_isabn_8": "8月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_8": "8月本期标况累计（远传）",
        "f_residual_gas_volume_8": "8月本期表剩余（远传）",
        "f_upload_date_8": "8月本期上报时间（远传）",
        "f_isabn_8": "8月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_8": "8月期间用气量3（远传）",
        "d_value1_8": "8月气量差值1（远传）",
        "d_value2_8": "8月气量差值2（远传）",
        "f_last_flow_standard_total1_9": "9月上期标况累计（抄表）",
        "f_last_surplus_gas1_9": "9月上期表剩余（抄表）",
        "f_last_f_hand_date1_9": "9月上期抄表时间（抄表）",
        "f_flow_standard_total_9": "9月本期标况累计（抄表）",
        "f_surplus_gas_9": "9月本期表剩余（抄表）",
        "f_hand_date_9": "9月本期抄表时间（抄表）",
        "gas_consumption1_9": "9月期间用气量1（抄表）",
        "gas_consumption2_9": "9月期间用气量2（抄表）",
        "sumpregas_9": "9月期间充值量（收费）",
        "f_last_pile_gas_volume_9": "9月上期标况累计（远传）",
        "f_last_residual_gas_volume_9": "9月上期表剩余（远传）",
        "f_last_upload_date_9": "9月上期上报时间（远传）",
        "f_last_isabn_9": "9月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_9": "9月本期标况累计（远传）",
        "f_residual_gas_volume_9": "9月本期表剩余（远传）",
        "f_upload_date_9": "9月本期上报时间（远传）",
        "f_isabn_9": "9月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_9": "9月期间用气量3（远传）",
        "d_value1_9": "9月气量差值1（远传）",
        "d_value2_9": "9月气量差值2（远传）",
        "f_last_flow_standard_total1_10": "10月上期标况累计（抄表）",
        "f_last_surplus_gas1_10": "10月上期表剩余（抄表）",
        "f_last_f_hand_date1_10": "10月上期抄表时间（抄表）",
        "f_flow_standard_total_10": "10月本期标况累计（抄表）",
        "f_surplus_gas_10": "10月本期表剩余（抄表）",
        "f_hand_date_10": "10月本期抄表时间（抄表）",
        "gas_consumption1_10": "10月期间用气量1（抄表）",
        "gas_consumption2_10": "10月期间用气量2（抄表）",
        "sumpregas_10": "10月期间充值量（收费）",
        "f_last_pile_gas_volume_10": "10月上期标况累计（远传）",
        "f_last_residual_gas_volume_10": "10月上期表剩余（远传）",
        "f_last_upload_date_10": "10月上期上报时间（远传）",
        "f_last_isabn_10": "10月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_10": "10月本期标况累计（远传）",
        "f_residual_gas_volume_10": "10月本期表剩余（远传）",
        "f_upload_date_10": "10月本期上报时间（远传）",
        "f_isabn_10": "10月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_10": "10月期间用气量3（远传）",
        "d_value1_10": "10月气量差值1（远传）",
        "d_value2_10": "10月气量差值2（远传）",
        "f_last_flow_standard_total1_11": "11月上期标况累计（抄表）",
        "f_last_surplus_gas1_11": "11月上期表剩余（抄表）",
        "f_last_f_hand_date1_11": "11月上期抄表时间（抄表）",
        "f_flow_standard_total_11": "11月本期标况累计（抄表）",
        "f_surplus_gas_11": "11月本期表剩余（抄表）",
        "f_hand_date_11": "11月本期抄表时间（抄表）",
        "gas_consumption1_11": "11月期间用气量1（抄表）",
        "gas_consumption2_11": "11月期间用气量2（抄表）",
        "sumpregas_11": "11月期间充值量（收费）",
        "f_last_pile_gas_volume_11": "11月上期标况累计（远传）",
        "f_last_residual_gas_volume_11": "11月上期表剩余（远传）",
        "f_last_upload_date_11": "11月上期上报时间（远传）",
        "f_last_isabn_11": "11月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_11": "11月本期标况累计（远传）",
        "f_residual_gas_volume_11": "11月本期表剩余（远传）",
        "f_upload_date_11": "11月本期上报时间（远传）",
        "f_isabn_11": "11月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_11": "11月期间用气量3（远传）",
        "d_value1_11": "11月气量差值1（远传）",
        "d_value2_11": "11月气量差值2（远传）",
        "f_last_flow_standard_total1_12": "12月上期标况累计（抄表）",
        "f_last_surplus_gas1_12": "12月上期表剩余（抄表）",
        "f_last_f_hand_date1_12": "12月上期抄表时间（抄表）",
        "f_flow_standard_total_12": "12月本期标况累计（抄表）",
        "f_surplus_gas_12": "12月本期表剩余（抄表）",
        "f_hand_date_12": "12月本期抄表时间（抄表）",
        "gas_consumption1_12": "12月期间用气量1（抄表）",
        "gas_consumption2_12": "12月期间用气量2（抄表）",
        "sumpregas_12": "12月期间充值量（收费）",
        "f_last_pile_gas_volume_12": "12月上期标况累计（远传）",
        "f_last_residual_gas_volume_12": "12月上期表剩余（远传）",
        "f_last_upload_date_12": "12月上期上报时间（远传）",
        "f_last_isabn_12": "12月上期数据是否异常,0正常 1异常（远传）",
        "f_pile_gas_volume_12": "12月本期标况累计（远传）",
        "f_residual_gas_volume_12": "12月本期表剩余（远传）",
        "f_upload_date_12": "12月本期上报时间（远传）",
        "f_isabn_12": "12月本期数据是否异常,0正常 1异常（远传）",
        "gas_consumption3_12": "12月期间用气量3（远传）",
        "d_value1_12": "12月气量差值1（远传）",
        "d_value2_12": "12月气量差值2（远传）"
      },
    }
  },
  components:{
    Datepicker,
    Pager
  },
  methods : {
    excel() {
      // 将字符串标签转换为DOM元素
      function parseToDOM(str){
        var div = document.createElement("div");
        if(typeof str == "string")
          div.innerHTML = str;
        return div;
      }
      // 将dom导出为excel文件
      let workbook = XLSX.utils.table_to_book(parseToDOM("<table><tr><td>测试导出</td></tr></table>"))
      try {
        XLSX.writeFile(workbook, '月度抄表报表导出.xlsx');
      } catch(e) {
        console.error("前台导出异常(月度抄表报表)",e, workbook);
      }
    },

    initBody(){
      let body = ''
      for (var i = 0; i < this.baseData.length; i++){
        body += '<tr>'
        body +=`
              <td>  <nobr>${i+1}</nobr>  </td>
              <td>  <nobr>${Util.isnull(this.baseData[i].name,'')}</nobr></td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].f_user_name,'暂无信息')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].f_userinfo_code,'')}</nobr>
              </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].f_gasproperties,'')}</nobr>
              </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].f_address,'')}</nobr>
              </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].f_meter_brand,'')}</nobr>
              </td>
               <td>
                    <nobr>${Util.isnull(this.baseData[i].sta_id,'')}</nobr>
               </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].cj,'')}</nobr>
              </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].lx,'')}</nobr>
              </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].xh,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].sn,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].kj,'')}</nobr>
              </td>
              <td>
                    <nobr>${Util.isnull(this.baseData[i].qf,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].jd,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].min,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].max,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].usetime,'')}</nobr>
              </td>
              <td>
                     <nobr>${Util.isnull(this.baseData[i].jlfs,'')}</nobr>
            </td>`
        // 找到当前信息的这个人的数据
        for (let j = 0; j < 12; j++) {
          let kitem = this.resData.find((kkitem)=>{
            if (kkitem.mon == (j+1) && this.baseData[i].f_userinfo_id=== kkitem.f_userinfo_id) {
              return kkitem;
            }else {
              return null;
            }
          })
          if (kitem) {
            body += `
              <td  class="borderleftright"  style="border-left: black">
                <nobr>${Util.isnull(kitem.f_last_flow_standard_total1,'0')}</nobr>
              </td>
              <td  class="borderleftright">
                <nobr>${Util.isnull(kitem.f_last_surplus_gas1,'0')}</nobr>
              </td>
              <td  class="borderleftright">
                <nobr>${Util.isnull(kitem.f_last_f_hand_date1,'')}</nobr>
              </td>
              <td  class="borderleftright">
                <nobr>${Util.isnull(kitem.f_flow_standard_total,'0')}</nobr>
              </td>
              <td  class="borderleftright">
                <nobr>${Util.isnull(kitem.f_surplus_gas,'0')}</nobr>
              </td>
                <td  class="borderleftright">
                <nobr>${Util.isnull(kitem.f_hand_date,'')}</nobr>
              </td>
              <td title="本期标况累计减上期标况累计；如存在换流量计，（旧流量计标况累计减旧流量计上期标况累计）加新流量计本期标况累计" class="borderleftright"><nobr>${Util.isnull(kitem.gas_consumption1,'0')}</nobr></td>
              <td title="用上期抄表剩余加上期间充值量减去本期剩余量" class="borderleftright"><nobr>${Util.isnull(kitem.gas_consumption2,'0')}</nobr></td>
              <td title="期间充值量" class="borderleftright"><nobr>${Util.isnull(kitem.sumpregas,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright"><nobr>${Util.isnull(kitem.f_last_pile_gas_volume,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright"><nobr>${Util.isnull(kitem.f_last_residual_gas_volume,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright" style="${kitem.f_last_isabn==0?'':'color:red;'}"><nobr>${Util.isnull(kitem.f_last_upload_date,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright" style="${kitem.f_last_isabn==0?'':'color:red;'}"><nobr>${Util.isnull(kitem.f_last_isabn==0?'正常':'异常','异常')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright"><nobr>${Util.isnull(kitem.f_pile_gas_volume,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright"><nobr>${Util.isnull(kitem.f_residual_gas_volume,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright" style="${kitem.f_isabn==0?'':'color:red;'}"><nobr>${Util.isnull(kitem.f_upload_date,'0')}</nobr></td>
              <td title="调取每月25日早8点数据" class="borderleftright" style="${kitem.f_isabn==0?'':'color:red;'}"><nobr>${Util.isnull(kitem.f_isabn==0?'正常':'异常','异常')}</nobr></td>
              <td title="本期标况累计减去上期标况累计" class="borderleftright"><nobr>${Util.isnull(kitem.gas_consumption3,'')}</nobr></td>
              <td title="期间用气量1减去期间用气量2（流量计计数用量与充值器扣数差值）" class="borderleftright"><nobr>${Util.isnull(kitem.d_value1,'0')}</nobr></td>
              <td title="期间用气量1减去期间用气量3（实际抄表用量与远传用量差值）" class="borderleftright" style="border-left: black"><nobr>${Util.isnull(kitem.d_value2,'0')}</nobr></td>
              `
          }
          else {
            body+= `
              <td class="borderleftright" style="border-left: black"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright"><nobr></nobr> </td>
              <td class="borderleftright" style="border-right: black"><nobr></nobr> </td>
              `
          }
        }
        body += '</tr>'
      }
      document.getElementById("manbody").innerHTML = body
    },
    getRes(obj) {
      console.log(obj)
      this.f_filialeids = this.$login.convertToIn(obj.resids);
      this.f_orgname = obj.res[0]
    },
    verification() {
      if (!this.f_filialeids) {
        this.$showMessage("请选择分公司")
        return false;
      }
      if (!this.yearDate) {
        this.$showMessage("请选择统计年份")
        return false;
      }
      return true;
    },
    initCondition() {
      this.condition = '1=1'
      if (this.searchModel.f_userinfo_code.trim()) {
        this.condition += ` and ui.f_userinfo_code = '${this.searchModel.f_userinfo_code.trim()}'`
      }
      if (this.searchModel.f_address.trim()) {
        this.condition += ` and uad.f_address = '${this.searchModel.f_address.trim()}'`
      }
      if (this.searchModel.f_gasproperties.trim()) {
        this.condition += ` and uf.f_gasproperties = '${this.searchModel.f_gasproperties.trim()}'`
      }
    },
    // 执行查询
    async search(pageIndex) {
      let isverif = this.verification()// 必填数据校验
      if (!isverif) {
        return;
      }
      this.initCondition() // 组织请求条件

      if (pageIndex) {
        // 是否携带了最新的页码数，如果携带了就更新当前页码为最新页码
        this.pageIndex = pageIndex
      }

      this.seaching = true; //开启logging
      if (this.f_filialeids == `('${this.$login.f.orgid}')` ) {
        this.thisOrgName = this.$login.f.orgname
      }else {
        this.thisOrgName = this.f_orgname
      }

      this.thisYear = this.yearDate //年份

      let  http = new HttpResetClass()
      let newdate = {
        f_filialeids: this.f_filialeids,
        yearDate: this.yearDate,
        condition: this.condition,
        f_userinfo_ids: ``,
        f_userinfo_codes: ``,
        getcount: true //是否查询count 共用同一个sql 实现类似/n的请求
      }

      // 总条数
      let res = await http.load('POST',`/api/af-safecheck/sql/ReadingCheckHandPlanBaseInfo`, {"data": newdate },
        {resolveMsg: '查询汇总成功！', rejectMsg: '查询汇总失败!'}).catch(()=>{
        this.$showMessage("查询汇总失败，网络连接超时，请稍后再试")
        this.seaching = false;
      })
      if (res.data) {
        this.count = res.data[0].count
        newdate.getcount = false //不去查询count 通过参数控制是否查询条数

        // 基础数据
        let resd = await http.load('POST',`/api/af-safecheck/sql/ReadingCheckHandPlanBaseInfo?pageNo=${this.pageIndex}&pageSize=${this.pageSize}`, {"data": newdate},
          {resolveMsg: '查询汇总成功！', rejectMsg: '查询汇总失败!'}).catch(()=>{
          this.$showMessage("查询汇总失败，网络连接超时，请稍后再试")
          this.seaching = false;
        })
          if (resd.data) {
          this.baseData = resd.data
          // 取出该页所有基础数据中的 用户编号和id
          let userids = []
          let usercodes = []
          for (let baseDatum of resd.data) {
            userids.push(baseDatum.f_userinfo_id)
            usercodes.push(baseDatum.f_userinfo_code)
          }
          newdate.f_userinfo_ids = this.$login.convertToIn(userids);
          newdate.f_userinfo_codes = this.$login.convertToIn(usercodes);
        }
          if (resd.data.length == 0){
            newdate.f_userinfo_ids = `('')`
            newdate.f_userinfo_codes = `('')`
          }

        // 开始查询抄表信息，将基础数据的id和编号作为条件给后台
        let ress = await http.load('POST',`/api/af-safecheck/sql/MonthlyMeterReadingStatistics?pageNo=1&pageSize=999999`, {"data": newdate},
          {resolveMsg: '查询汇总成功！', rejectMsg: '查询汇总失败!'}).catch(()=>{
          this.$showMessage("查询汇总失败，网络连接超时，请稍后再试")
          this.seaching = false;
        })
        if (ress.data) {
          this.resData = ress.data
        }
        if (this.resData && this.baseData) {
          this.initBody() //渲染页面
          this.searchData = newdate
          this.excelTitle = `${this.thisOrgName},${this.thisYear}年度工商业抄表情况统计表`
          this.seaching = false;
        } else {
          this.seaching = false;
          this.$showAlert('网络异常，请稍后再试', 'warning', 3000)
        }

      } else {
        this.seaching = false;
        this.$showAlert('网络异常，请稍后再试', 'warning', 3000)
      }
    },


  },
  computed: {

  },
  ready() {

  },
  watch: {

  }
}
</script>

<style lang="less" scoped>
.tableinfo {
  text-align: center;
  background-color: #6aa6e2;
}
.borderleftright {
  border-top: 1px solid #5ac0d9;
  border-left: 1px solid #5ac0d9;
  border-right: 1px solid #5ac0d9;
  border-bottom: 1px solid #5ac0d9;
}
.diy-table {
  tr{
    min-width: 240px;
    max-height: 50px;
    td{
      max-height: 50px;
      min-width: 100px;
      text-align: center;
    }
  }
}
.tablerowclass {
  background-color: #5ac0d9;
  border-left: 1px solid #f2fffa;
  border-right: 1px solid #f2fffa;
  border-top: 1px solid #f2fffa;
  border-bottom: 1px solid #f2fffa;
}

</style>

