<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex" v-if="!show">
        <criteria-paged :model="model" v-ref:paged  :pager="false" @sort="sort">
          <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri >
            <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
              <div class="span" style="float:right;">
                <button class="button_search button_spacing" @click="search()">查询</button>
                <export-excel :data="$parent.$parent.getCondition" :footer="$parent.$parent.footer"
                              :field="$parent.$parent.getExportField" :header="$parent.$parent.other"
                              sqlurl="api/af-revenue/logic/openapi/exportfile" sql-name="getInstantaneousFlowRegulatorStation" template-name='调压站瞬时流量查询导出'
                              :choose-col="true">
                </export-excel>
              </div>
            </div>
          </criteria>
          <data-grid  :model="model" partial='list' class="list_area table_sy" >
            <template partial='head'>
              <tr>
                <th rowspan=2>时间</th>
                <th colspan="5">吕小寨</th>
                <th colspan="3">狄寨原</th>
                <th colspan="3">耿镇</th>
                <th colspan="2">港务区</th>
                <th rowspan="2">高陵门站</th>
                <th rowspan="2">未央湖</th>
                <th rowspan="2">凤十站</th>
                <th rowspan="2">草五站</th>
                <th rowspan="2">建章路</th>
                <th rowspan="2">北石桥</th>
                <th rowspan="2">科七路</th>
                <th rowspan="2">凤八路</th>
                <th rowspan="2">万寿北</th>
                <th rowspan="2">朝阳门</th>
                <th rowspan="2">观音庙</th>
                <th rowspan="2">丈八站</th>
                <th colspan="2">南郊站</th>
                <th rowspan="2">浐灞站</th>
                <th rowspan="2">长鸣路</th>
                <th rowspan="2">曲江站</th>
                <th rowspan="2">西万路</th>
                <th rowspan="2">曲一</th>
                <th rowspan="2">郭杜</th>
                <th rowspan="2">小时累计合计</th>
              </tr>
              <tr>
                <th  >一期</th>
                <th  >一期撬装</th>
                <th  >二期</th>
                <th  >二期中压</th>
                <th  >二期扩容</th>
                <th  >二期</th>
                <th  >二期扩容</th>
                <th  >高中调</th>
                <th  >高高调</th>
                <th  >高中调</th>
                <th  >中压调压</th>
                <th  >高高调</th>
                <th  >高中调</th>
                <th  >南郊一期</th>
                <th  >南郊二期</th>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">
                <nobr>{{row.time}}</nobr>
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data1"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data1',row.data1,'吕小寨','一期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data2"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data2',row.data2,'吕小寨','一期撬装','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data3"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data3',row.data3,'吕小寨','二期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data6"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data6',row.data6,'吕小寨','二期中压','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data7"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data7',row.data7,'吕小寨','二期扩容','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data12"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data12',row.data12,'狄寨塬','二期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data17"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data17',row.data17,'狄寨塬','二期扩容','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data20_5"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data20_5',row.data20_5,'狄寨塬','高高调','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data18"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data18',row.data18,'耿镇','高高调','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data19"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data19',row.data19,'耿镇','高中调','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data20"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data20',row.data20,'耿镇','中压调压','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data21"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data21',row.data21,'港务区','高高调','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data22"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data22',row.data22,'港务区','高中调','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data23"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data23',row.data23,'高陵门站','高陵门站','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data24"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data24',row.data24,'未央湖','未央湖','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data25"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data25',row.data25,'凤十站','凤十站','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data26"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data26',row.data26,'草五站','草五站','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data27"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data27',row.data27,'建章路','建章路','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data28"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data28',row.data28,'北石桥','北石桥','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data29"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data29',row.data29,'科七路','科七路','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data30"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data30',row.data30,'凤八路','凤八路','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data31"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data31',row.data31,'万寿北','万寿北','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data32"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data32',row.data32,'朝阳门','朝阳门','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data33"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data33',row.data33,'观音庙','观音庙','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data34"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data34',row.data34,'丈八站','丈八站','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data35"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data35',row.data35,'南郊站','一期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data36"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data36',row.data36,'南郊站','二期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data37"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data37',row.data37,'浐灞站','浐灞站','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data38"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data38',row.data38,'长鸣路','长鸣路','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data39"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data39',row.data39,'曲江站','曲江站','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data40"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data40',row.data40,'西万路','西万路','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data41"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data41',row.data41,'曲一','曲一','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data42"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data42',row.data42,'郭杜','郭杜','主线')">
              </td>
              <td style="text-align: center;">
                <nobr>{{row.data1+row.data2+row.data3+row.data6+row.data7+row.data12+row.data17+row.data18+row.data19+row.data20+row.data21+row.data22+row.data23+row.data24+row.data25+row.data26+row.data27+row.data28+row.data29+row.data30+row.data31+row.data32+row.data33+row.data34+row.data35+row.data36+row.data37+row.data38+row.data39+row.data40+row.data41+row.data42}}</nobr>
              </td>
            </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">
              吕小寨一期合计:{{sumsmodel.data1}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              吕小寨一期撬装合计:{{sumsmodel.data2}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              吕小寨二期合计:{{sumsmodel.data3}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              吕小寨二期中压合计:{{sumsmodel.data6}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              吕小寨二期扩容合计:{{sumsmodel.data7}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              狄寨塬二期合计:{{sumsmodel.data12}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              狄寨塬二期扩容合计:{{sumsmodel.data17}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              耿镇高高调合计:{{sumsmodel.data18}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              耿镇高中调合计:{{sumsmodel.data19}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              耿镇中压调压合计:{{sumsmodel.data20}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              港务区高高调合计:{{sumsmodel.data21}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              港务区高中调合计:{{sumsmodel.data22}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              高陵门站合计:{{sumsmodel.data23}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              未央湖合计:{{sumsmodel.data24}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              凤十站合计:{{sumsmodel.data25}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              草五站合计:{{sumsmodel.data26}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              建章路合计:{{sumsmodel.data27}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              北石桥合计:{{sumsmodel.data28}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              科七路合计:{{sumsmodel.data29}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              凤八路合计:{{sumsmodel.data30}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              万寿北合计:{{sumsmodel.data31}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              朝阳门合计:{{sumsmodel.data32}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              观音庙合计:{{sumsmodel.data33}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              丈八站合计:{{sumsmodel.data34}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              南郊站一期合计:{{sumsmodel.data35}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              南郊站二期合计:{{sumsmodel.data36}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              浐灞站合计:{{sumsmodel.data37}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              长鸣路合计:{{sumsmodel.data38}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              曲江站合计:{{sumsmodel.data39}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              西万路合计:{{sumsmodel.data40}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              曲一合计:{{sumsmodel.data41}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              郭杜合计:{{sumsmodel.data42}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              小时累计总合计:{{finalTotal}}
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>


<script>
  import {PagedList} from "vue-client";
  import {toStandardTimeString} from "../../../Util";
  import exportConfig from "../../sale/config/exportConfig";

  export default {
    name: "InstantaneousFlowRegulatorStation",
    props:['date'],
    data(){
      return{
        model: new PagedList('api/af-revenue/sql/getInstantaneousFlowRegulatorStation',24,{fieldName:"'f_instantaneous_flow'",beginDate:'\''+this.date.yesterday+'\'',endDate:'\''+this.date.today+'\''},{
          data1:0,
          data2:0,
          data3:0,
          data6:0,
          data7:0,
          data12:0,
          data17:0,
          data20_5:0,
          data18:0,
          data19:0,
          data20:0,
          data21:0,
          data22:0,
          data23:0,
          data24:0,
          data25:0,
          data26:0,
          data27:0,
          data28:0,
          data29:0,
          data30:0,
          data31:0,
          data32:0,
          data33:0,
          data34:0,
          data35:0,
          data36:0,
          data37:0,
          data38:0,
          data39:0,
          data40:0,
          data41:0,
          data42:0
        }),
        sumsmodel:{},
        modelBackup:{},
        finalTotal: 0,
        footer:[],
        other:[]
      }
    },
    ready(){
      this.search();
    },
    methods:{
      getotherfooter () {
        this.other = [];
        this.footer = [];
        let exportdata = this.getCondition;
        let otherInData = [];
        otherInData.push('高中调瞬时流量');
        let footerData = [], exportfield = this.getExportField;
        let self = this;
        footerData.push(`合计`);
        for (var field in self.sumsmodel) {
          footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`);
        }
        this.footer.push(footerData);
        this.other.push(otherInData);
      },
      hasModelBackupTime(time) {
        //获取Modelbackup中time所在的数组下标
        for(let i in this.modelBackup.rows){
          if(this.modelBackup.rows[i].time === time)
            return i;
        }
        return null;
      },
      inputDefocus(row,column,newData,stationName,childStationName,lineName){
        debugger
        if(typeof newData=='string')
          newData = parseFloat(newData);
        let index = this.hasModelBackupTime(row.time);        //判断修改了哪个数据
        if(index !== null ){
          let oldData = this.modelBackup.rows[index][column];
          if(oldData !== newData){
            //如果更改了数据,修改数据,增加log
            let operatorTime = toStandardTimeString();
            this.$resetpost('rs/logic/modifyData',{stationName:stationName, childStationName:childStationName, lineName:lineName,
              f_create_time:row.time, oldData:oldData,newData:newData,operatorTime:operatorTime,field:'f_instantaneous_flow',
              operatorName:this.$login.f.ename, operatorId:this.$login.f.loginid
            });
            //重新查询
            this.search();
          }
        }
        //将rows内数据格式化为number
        for(let i in this.model.rows){
          let rowsData = this.model.rows[i];
          for(let j in rowsData){
            if(j!=='time' && typeof rowsData[j] == 'string')
              rowsData[j] = parseFloat(rowsData[j]);
          }
        }
      },
      selfSearch(){
        this.search()
      },
      caculateTotal(){
        this.sumsmodel= this.model.sums;
        //如果有null，设置为0
        for(let i in this.sumsmodel){
          this.sumsmodel[i] = this.sumsmodel[i] === null?0:this.sumsmodel[i];
        }
        //计算小时累计总合计
        debugger
        this.finalTotal = this.sumsmodel.data1+this.sumsmodel.data2+this.sumsmodel.data3+this.sumsmodel.data6+this.sumsmodel.data7+this.sumsmodel.data12+this.sumsmodel.data17+this.sumsmodel.data18+this.sumsmodel.data19+this.sumsmodel.data20+this.sumsmodel.data21+this.sumsmodel.data22+this.sumsmodel.data23+this.sumsmodel.data24+this.sumsmodel.data25+this.sumsmodel.data26+this.sumsmodel.data27+this.sumsmodel.data28+this.sumsmodel.data29+this.sumsmodel.data30+this.sumsmodel.data31+this.sumsmodel.data32+this.sumsmodel.data33+this.sumsmodel.data34+this.sumsmodel.data35+this.sumsmodel.data36+this.sumsmodel.data37+this.sumsmodel.data38+this.sumsmodel.data39+this.sumsmodel.data40+this.sumsmodel.data41+this.sumsmodel.data42;
      },
      async search(){
        await  this.model.search()
        this.modelBackup= JSON.parse(JSON.stringify(this.model))
        this.caculateTotal();
      }
    },
    computed:{
      getCondition(){
        return {
          fieldName:'f_instantaneous_flow',
          beginDate:this.date.yesterday,
          endDate:this.date.today
        }
      },
      getExportField() {
        return exportConfig.InstantaneousFlowRegulatorStation
      }
    },
    watch:{
      sumsmodel:{
        handler: function(val) {
          this.getotherfooter();
        },
        deep: true
      },
    }
  }
</script>

<style scoped>

</style>
