 <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="getGasConsumputionByDay" 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 >时间</th>
                <th colspan="2">购气量</th>
                <th >门站二期扩容P进</th>
                <th >门站二期扩容P出</th>
                <th >暂用凤十P进</th>
                <th >浐河站P进</th>
                <th >西延P进</th>
                <th >朱雀站P进</th>
                <th >丈八站P进</th>
                <th >曲江站P进</th>
                <th >西万路站</th>
                <th >球罐PA</th>
                <th >球罐PB</th>
                <th >球罐PC</th>
                <th >球罐PD</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.time1}}</nobr>
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.gaspurchasecapacity"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'gaspurchasecapacity',row.gaspurchasecapacity,'','','',0,'')">
              </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,'港务区','高高调','主线',1,'f_cumulative_flow')">
              </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,'吕小寨','二期扩容','主线',2,'f_input_pressure')">
              </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,'吕小寨','二期扩容','主线',3,'f_output_pressure')">
              </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,'凤十站','凤十站','主线',2,'f_input_pressure')">
              </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,'浐灞站','浐灞站','主线',2,'f_input_pressure')">
              </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,'西延站','西延站','主线',2,'f_input_pressure')">
              </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,'朱雀站','朱雀站','主线',2,'f_input_pressure')">
              </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,'丈八站','丈八站','主线',2,'f_input_pressure')">
              </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,'曲江站','曲江站','主线',2,'f_input_pressure')">
              </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,'西万路','西万路','主线',2,'f_input_pressure')">
              </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,'储配站','储配厂','球罐A',2,'f_input_pressure')">
              </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,'储配站','储配厂','球罐B',2,'f_input_pressure')">
              </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,'储配站','储配厂','球罐C',2,'f_input_pressure')">
              </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,'储配站','储配厂','球罐D',2,'f_input_pressure')">
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_consumpution}}</nobr>
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.f_correction"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'f_correction',row.f_correction,'修正量','修正量','修正量',4,'f_consumpution')">
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_result}}</nobr>
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.f_wosi_lng"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'f_wosi_lng',row.f_wosi_lng,'我司','我司','主线',4,'f_wosi_lng')">
              </td>
              <td style="text-align: center;">
                <input type="text" style="width:120px" class="input_search" v-model="row.f_yinzhen_lng"
                       @blur="$parent.$parent.$parent.inputDefocus(row,'f_yinzhen_lng',row.f_yinzhen_lng,'引镇','引镇','主线',4,'f_yinzhen_lng')">
              </td>
              <td>
                <nobr>{{row.finaltotal}}</nobr>
              </td>
            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>


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

export default {
  name: "CaculateGasConsumputionByDay",
  title:"日用气量计算",
  ready(){
    this.initVariable();
    this.search();
  },
  data(){
    return{
      model: new PagedList('api/af-revenue/sql/getGasConsumputionByDay',30,{beginDate:'this.model.beginDate',endDate:'this.model.endDate'}),
      date:{
        today:"",
        yesterday:""
      },
      modelBackup:{},
      footer:[],
      other:[]
    }
  },
  methods:{
    modifyConsumupution(row,oldData,newData,field){
      //获取修改动作的相关信息
      let operatorTime = toStandardTimeString();
      let operatorName = this.$login.f.ename;
      let operatorId = parseInt(this.$login.f.loginid);
      //修改数据并完成log插入
      this.$resetpost('api/af-revenue/logic/modifyConsumpution',{f_create_time:row.time1,oldData:oldData,newData:newData,field:field,
        operatorTime:operatorTime,operatorName:operatorName,operatorId:operatorId
      });
      this.search();
    },
    getotherfooter () {
      this.other = [];
      this.footer = [];
      let exportdata = this.getCondition;
      let otherInData = [];
      otherInData.push('日用气量计算');
      let footerData = [], exportfield = this.getExportField;
      let self = this;
      this.footer.push(footerData);
      this.other.push(otherInData);
    },
    hasModelBackupTime(time1) {
      debugger
      //获取Modelbackup中time所在的数组下标
      for(let i in this.modelBackup.rows){
        if(this.modelBackup.rows[i].time1 === time1)
          return i;
      }
      return null;
    },
    modifyData(oldData,newData,row,stationName,childStationName,lineName,field){
      //获取修改动作的相关信息
      let operatorTime = toStandardTimeString();
      let operatorName = this.$login.f.ename;
      let operatorId = parseInt(this.$login.f.loginid);
      //修改数据并完成log插入
      this.$resetpost('api/af-revenue/logic/modifyData',{stationName:stationName, childStationName:childStationName, f_create_time:row.time1,lineName:lineName,oldData:oldData,newData,field:field,
        operatorTime:operatorTime,operatorName:operatorName,operatorId:operatorId
      });
      this.search();

    },

    inputDefocus(row,column,newData,stationName,childStationName,lineName,type,field){
      if(typeof newData=='string')
        newData = parseFloat(newData);
      //获取输入框失焦的数据坐标
      let index = this.hasModelBackupTime(row.time1);
      console.log("index = ",index)
      let oldData = this.modelBackup.rows[index][column];
      //如果数据被修改
      if(oldData !== newData) {
        if(type === 0 || index === null){
          //不用修改
          return;
        }
        else if(type >=1 && type <=3){
          //修改累计流量 | 进站压力 |出站压力
          this.modifyData(oldData,newData,row,stationName,childStationName,lineName,field);
        }
        else if(type === 4){
          //  修改修正量
          this.modifyConsumupution(row,oldData,newData,field);
        }
      }
      //将rows内数据格式化为number
      for(let i in this.model.rows){
        let rowsData = this.model.rows[i];
        for(let j in rowsData){
          if(j!=='time1' && typeof rowsData[j] == 'string')
            rowsData[j] = parseInt(rowsData[j]);
        }
      }
    },
    resort(){
      //根据客户的需求将数据位置进行调换
      let data = this.model.rows;
      if(data[0].time1.substr(11,2) === '08' && data[1].time1.substr(11,2) === '08') {
        let temp = data[1];
        data.splice(1, 1);
        let length = data.length;
        data.splice(length - 1, 0, temp);
      }
    },
    async selfSearch(args){
      this.initVariable();
      await this.model.search(null,args.model);
      this.resort();
      this.modelBackup= JSON.parse(JSON.stringify(this.model))
    },
    async search(){
      this.initVariable();
      await this.model.search(null,this.$refs.paged.$refs.cri.model);
      this.resort();
      this.modelBackup= JSON.parse(JSON.stringify(this.model))
    },
    initVariable(){
      //获取今天昨天的日期
      this.date.today = toStandardDateString();
      this.date.yesterday = addDate(this.date.today,-1).slice(0,10);
      this.date.today = 'to_date(\''+this.date.today+' 08:00:00'+'\',\'yyyy-mm-dd hh24:mi:ss\')';
      this.date.yesterday = 'to_date(\''+this.date.yesterday+' 08:00:00'+'\',\'yyyy-mm-dd hh24:mi:ss\')';

      this.$refs.paged.$refs.cri.model.endDate = this.date.today;
      this.$refs.paged.$refs.cri.model.beginDate = this.date.yesterday;

    }
  },
  computed:{
    getCondition(){
      return {
        fieldName:'f_cumulative_flow',
        beginDate:this.date.yesterday,
        endDate:this.date.today
      }
    },
    getExportField() {
      return exportConfig.CaculateGasConsumputionByDay
    }

  },
}
</script>

<style scoped>

</style>
