<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="row">
                <div class="span" style="float:right;">
                  <!--<read-idcard></read-idcard>-->
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <export-excel :data="$parent.$parent.getCondition" :footer="$parent.$paren t.footer"
                                :field="$parent.$parent.getExportField" :header="$parent.$parent.other"
                                sqlurl="api/af-revenue/logic/openapi/exportfile" sql-name="getCumulativeFlowHeatPlant" template-name='热源厂累计流量导出'
                                :choose-col="true">
                  </export-excel>
                </div>
              </div>
            </div>
          </criteria>

            <data-grid   :model="model" partial='list' class="list_area table_sy" style="height: 95%" v-ref:grid>
            <template partial='head'>
              <tr >
                <th rowspan="2">时间</th>
                <th colspan="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>
                <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>

              </tr>
              <tr>
                <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;">
                <nobr>{{ row.xjrdtotal}}</nobr>
              </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.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;">
                <nobr>{{row.ydtotal}}</nobr>
              </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.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.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.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.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.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;">
                <nobr>{{row.finaltotal}}</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">
              西郊热电总合计:{{xjrdTotal}}
            </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.data4}}
            </td>
            <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              雁东二期合计:{{sumsmodel.data5}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              雁东总合计:{{ydTotal}}
            </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.data8}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              朱雀路热力合计:{{sumsmodel.data9}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              沣东热力合计:{{sumsmodel.data10}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              朝阳门热力合计:{{sumsmodel.data11}}
            </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.data13}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              明德合计:{{sumsmodel.data14}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              西联大兴合计:{{sumsmodel.data15}}
            </td>
             <td
              style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
              渭水合计:{{sumsmodel.data16}}
            </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">
              小时累计总合计:{{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: "CumulativeFlowHeatPlant",
  props:{
    date:{
      yesterday: String,
      today:String
    }
  },
  data(){
    return{
      model: new PagedList('api/af-revenue/sql/getCumulativeFlowHeatPlant', 24, {fieldName:"'f_cumulative_flow'",beginDate:'\''+this.date.yesterday+'\'',endDate:'\''+this.date.today+'\''},{
        data1:0,
        data2:0,
        xjrdtotal:0,
        data3:0,
        data4:0,
        data5:0,
        ydtotal:0,
        data6:0,
        data7:0,
        data8:0,
        data9:0,
        data10:0,
        data11:0,
        data12:0,
        data13:0,
        data14:0,
        data15:0,
        data16:0,
        data17:0,
        data18:0,
        data19:0,
        finaltotal:0
      }),
      modelBackup:{},
      sumsmodel:{},
      xjrdTotal: 0,
      ydTotal: 0,
      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){
      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_cumulative_flow',
            operatorName:this.$login.f.ename, operatorId:this.$login.f.loginid
          });
          //重新查询
          this.selfsearch(null);
        }
      }
      //将rows内数据格式化为number
      for(let i in this.model.rows){
        let rowsData = this.model.rows[i];
        for(let j in rowsData){
          console.log("type of = ",typeof rowsData[j])
          if(j!=='time' && typeof rowsData[j] == 'string')
            rowsData[j] = parseInt(rowsData[j]);
        }
      }
    },
    selfsearch(args){
      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];
      }
      //计算西郊热电总合计，雁东总合计，小时累计总合计
      this.xjrdTotal = this.model.sums.data1+this.model.sums.data2;
      this.ydTotal = this.model.sums.data4+this.model.sums.data5;
      this.finalTotal = this.sumsmodel.data1+this.sumsmodel.data2+this.sumsmodel.data3+this.sumsmodel.data4+this.sumsmodel.data5+this.sumsmodel.data6+this.sumsmodel.data7+this.sumsmodel.data8+this.sumsmodel.data9+this.sumsmodel.data10+this.sumsmodel.data11+this.sumsmodel.data12+this.sumsmodel.data13+this.sumsmodel.data14+this.sumsmodel.data15+this.sumsmodel.data16+this.sumsmodel.data17+this.sumsmodel.data18+this.sumsmodel.data19;
    },
    async search(){
     await this.model.search();
     this.modelBackup= JSON.parse(JSON.stringify(this.model))
     this.caculateTotal();
    }
  },
  computed:{
    getCondition(){
      return {
        fieldName:'f_cumulative_flow',
        beginDate:this.date.yesterday,
        endDate:this.date.today
      }
    },
    getExportField() {
      return exportConfig.CumulativeFlowHeatPlantConfig
    }

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

<style scoped>

</style>

