<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="getCumulativeFlowStation" 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=3>时间</th>
                <th colspan="8">吕小寨</th>
                <th colspan="7">狄寨原</th>
                <th rowspan="3">省公司合计</th>
                <th rowspan="2" colspan="4">高陵</th>
                <th rowspan="3">小时累计合计</th>
              </tr>
              <tr>
                <th colspan="1">一期</th>
                <th colspan="1">一期撬装</th>
                <th colspan="2">二期</th>
                <th colspan="4">二期扩容</th>
                <th colspan="4">二期</th>
                <th colspan="3">二期扩容</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>
                <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.data4"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data4',row.data4,'吕小寨','二期','一线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data5"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data5',row.data5,'吕小寨','二期','二线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data8"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data8',row.data8,'吕小寨','二期扩容','一线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data9"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data9',row.data9,'吕小寨','二期扩容','二线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data10"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data10',row.data10,'吕小寨','二期扩容','三线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data11"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data11',row.data11,'吕小寨','二期扩容','四线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data13"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data13',row.data13,'狄寨塬','二期','一线')"></td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data14"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data14',row.data14,'狄寨塬','二期','二线')"></td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data15"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data15',row.data15,'狄寨塬','二期','三线')"></td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data16"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data16',row.data16,'狄寨塬','二期','四线')"></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;">
                <nobr>{{row.provicentotal}}</nobr>
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data43"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data43',row.data43,'高陵','高陵','一线')"></td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data44"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data44',row.data44,'高陵','高陵','二线')"></td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data45"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data45',row.data45,'高陵','高陵','三线')"></td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data46"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data46',row.data46,'高陵','高陵','四线')"></td>
              <td style="text-align: center;">
                <nobr>{{row.finaltotal}}</nobr>
              </td>
            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>
<script>
  import {PagedList} from "vue-client";
  import {toStandardTimeString} from "../../../Util";
  import exportConfig from "../../sale/config/exportConfig";

  export default {
    name: "InstantaneousFlowStation",
    props:['date'],
    data(){
      return{
        model: new PagedList('api/af-revenue/sql/getCumulativeFlowStation',24,{fieldName:"'f_instantaneous_flow'",beginDate:'\''+this.date.yesterday+'\'',endDate:'\''+this.date.today+'\''}),
        modelBackup:{},
        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]);
          }
        }
      },
      async search(){
        await this.model.search()
        this.modelBackup= JSON.parse(JSON.stringify(this.model))
      }
    },
    computed:{
      getCondition(){
        return {
          fieldName:'f_instantaneous_flow',
          beginDate:this.date.yesterday,
          endDate:this.date.today
        }
      },
      getExportField() {
        return exportConfig.InstantaneousFlowStation
      }

    },
    watch:{
      sumsmodel:{
        handler: function(val) {
          this.getotherfooter();
        },
        deep: true
      },
    }
  }
</script>

<style scoped>

</style>
