<template>
  <div class="main">
    <el-button type="primary" @click="save" style="margin:20px">保存</el-button>
    <el-button type="primary" @click="back" style="margin:20px">返回</el-button>
    <el-button type="primary" @click="station" style="margin:20px">场站</el-button>
    <!-- 表格 -->
    <el-table :data="tableData" style="width:98%;margin:20px" max-height="800px">
      <el-table-column
        v-for="(i,index) in Object.keys(tableData[0]).sort(function(n,m){
        return parseInt(n.split('_')[0])-parseInt(m.split('_')[0]);
        })"
        :key="index"
        :prop="i"
        :label="i | clu"
        width="160"
      >
       <template slot-scope="scope">
         <el-input @input="send(scope.row)"  v-if="scope.row.name =='止码' && i != 'name' && i != 'date'" v-model="scope.row[i]" :disabled='routerData.isConfirm == 1'></el-input>
         <label v-else>{{scope.row[i]}}</label>  
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import dateFormat from "../../public/js/dateFormat";
export default {
  data() {
    return {
      tableData: [],
      routerData:this.$route.params,
      lm: [],
      timeValue: [
        dateFormat(
          "yyyy-MM-dd",
          new Date(new Date().setDate(new Date().getDate() - 5))
        ),
        dateFormat("yyyy-MM-dd", new Date()),
      ],
    };
  },
  created() {
    this.fetch();
    console.log(this.routerData)
  },

  mounted() {},
  methods: {
    async fetch() {
      const res = await this.$http.get(
        `analysisplus/bdzlist?theday=${dateFormat("yyyy-MM-dd", new Date(this.routerData.data.theday))}&wpid=${this.routerData.data.wpid}`
      );
      for(let i in res.data){
        if( res.data[i].date == undefined ){
        }else{
        res.data[i].date =dateFormat("yyyy-MM-dd", new Date(res.data[i].date));
        }
      }
      this.tableData = res.data;
     
      console.log(res.data);
      var name = ['2_dfds','8_fdf','1_fdjkf'];
      var aaa = this.px(name);
      
      console.log(aaa);
      
    },
    px(name){
      return name.sort(function(a,b){
        return parseInt(a.split("_")[0])-parseInt(b.split("_")[0])
      });
    },
    
    
    
    send(v){
    },
    async save(){
      var obj = this.tableData[2];
      const wpid = this.routerData.data.wpid;
      obj.wpid=wpid
      console.log(obj)
      const res = await this.$http.post(
        `analysisplus/bdzupdate`,obj
      );
      console.log(res)
    },
    back(){
      this.$router.push({ name: "home", params: { beginDate: this.routerData.beginDate,endDate: this.routerData.endDate} });
    },
    station(){
      console.log(this.routerData);
      const param = {
         theday: this.routerData.data.theday,
         wpid: this.routerData.data.wpid
         
      }
      this.$router.push({ name: "station", params: { data: param,beginDate:this.routerData.beginDate,endDate:this.routerData.endDate } });
    }
  },
  filters: {
    clu(val){
      switch (val) {
        case 'name':
          return '设备名称';
          break;
      case 'date':
          return '日期';
          break;
      
        default:
          return val.split("_")[1]
          break;
      }
    },
  },
};
</script>
<style scoped lang="scss">
body {
  margin: 0;
  padding: 0;
}
.main {
  width: 100%;
}
</style>