<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.search' 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="getOnTimePressureHeatPlant" 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="2">西郊热电一期</th>
                <th colspan="2">西郊热电二期</th>
                <th colspan="2">阳光热力</th>
                <th colspan="2">雁东一期</th>
                <th colspan="2">雁东二期</th>
                <th colspan="2">圣元热力</th>
                <th colspan="2">融鑫热力</th>
                <th colspan="2">南门热力</th>
                <th colspan="2">朱雀路热力</th>
                <th colspan="2">沣东热力</th>
                <th colspan="2">朝阳门热力</th>
                <th colspan="2">太华热力</th>
                <th colspan="2">嘉晟</th>
                <th colspan="2">明德</th>
                <th colspan="2">西联大兴</th>
                <th colspan="2">渭水</th>
                <th colspan="2">城北</th>
                <th colspan="2">幸福林带</th>
                <th colspan="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>
                <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>
                <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_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data1_in',row.data1_in,'西郊热电','一期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data1_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data1_out',row.data1_out,'西郊热电','一期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data2_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data2_in',row.data2_in,'西郊热电','二期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data2_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data2_out',row.data2_out,'西郊热电','二期','主线')">
              </td>

              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data3_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data3_in',row.data3_in,'阳光热力','阳光热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data3_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data3_out',row.data3_out,'阳光热力','阳光热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data4_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data4_in',row.data4_in,'雁东','一期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data4_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data4_out',row.data4_out,'雁东','一期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data5_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data5_in',row.data5_in,'雁东','二期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data5_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data5_out',row.data5_out,'雁东','二期','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data6_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data6_in',row.data6_in,'圣元热力','圣元热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data6_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data6_out',row.data6_out,'圣元热力','圣元热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data7_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data7_in',row.data7_in,'融鑫热力','融鑫热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data7_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data7_out',row.data7_out,'融鑫热力','融鑫热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data8_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data8_in',row.data8_in,'南门热力','南门热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data8_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data8_out',row.data8_out,'南门热力','南门热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data9_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data9_in',row.data9_in,'朱雀路热力','朱雀路热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data9_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data9_out',row.data9_out,'朱雀路热力','朱雀路热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data10_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data10_in',row.data10_in,'沣东热力','沣东热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data10_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data10_out',row.data10_out,'沣东热力','沣东热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data11_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data11_in',row.data11_in,'朝阳门热力','朝阳门热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data11_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data11_out',row.data11_out,'朝阳门热力','朝阳门热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data12_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data12_in',row.data12_in,'太华热力','太华热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data12_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data12_out',row.data12_out,'太华热力','太华热力','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data13_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data13_in',row.data13_in,'嘉晟','嘉晟','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data13_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data13_out',row.data13_out,'嘉晟','嘉晟','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data14_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data14_in',row.data14_in,'明德','明德','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data14_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data14_out',row.data14_out,'明德','明德','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data15_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data15_in',row.data15_in,'西联大兴','西联大兴','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data15_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data15_out',row.data15_out,'西联大兴','西联大兴','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data16_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data16_in',row.data16_in,'渭水','渭水','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data16_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data16_out',row.data16_out,'渭水','渭水','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data17_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data17_in',row.data17_in,'城北','城北','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data17_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data17_out',row.data17_out,'城北','城北','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data18_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data18_in',row.data18_in,'幸福林带','幸福林带','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data18_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data18_out',row.data18_out,'幸福林带','幸福林带','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data19_in"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data19_in',row.data19_in,'品诚','品诚','主线')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.data19_out"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'data19_out',row.data19_out,'品诚','品诚','主线')">
              </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: "OnTimePressureHeatPlant",
  props:['date'],
  data(){
    return{
      model: new PagedList('api/af-revenue/sql/getOnTimePressureHeatPlant',24,{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;
      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){
      if(typeof newData=='string')
        newData = parseFloat(newData);
      let index = this.hasModelBackupTime(row.time);        //判断修改了哪个数据
      if(index !== null ){
        let oldData = this.modelBackup.rows[index][column];
        // if(typeof oldData !== 'int')
        //   oldData = parseInt(oldData);
        if(oldData !== newData){
          //如果更改了数据,修改数据,增加log
          let operatorTime = toStandardTimeString();
          let field= '';
          if(column.indexOf('in')>=0)
            field = 'f_input_pressure';
          else if (column.indexOf('out')>=0)
            field = 'f_output_pressure';
          this.$resetpost('rs/logic/modifyData',{stationName:stationName, childStationName:childStationName, lineName:lineName,
            f_create_time:row.time, oldData:oldData,newData:newData,operatorTime:operatorTime,field:field,
            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.OnTimePressureHeatPlant
    }

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

<style scoped>

</style>
