<template>
    <div class="binary-left" style="width:24% ;text-align:center;align-content: center;">
      <div class="row">
      <div v-for="data in newmeterinfo" style="height: auto">
        <ul class="nav nav-tabs col-sm-12" >
          <li class="active"><a>{{data.name}}</a></li>
        </ul>
        <div class="col-sm-12"  style="height: auto" v-for="param in data.params">
                {{param.name}}：{{row[param.title]}}
        </div>
      </div>
  </div>
    </div>
    <div class="binary-right" style="width:74%;overflow-y: auto;max-height:1000px;">
      <div class="row list_area table_sy">
        <table class="table table-bordered table-striped table-hover" id="table1" >
          <thead>
          <th style="text-align:center"><nobr>操作</nobr></th>
          <th style="text-align:center"><nobr>指令发送状态</nobr></th>
  <!--        <th style="text-align:center"><nobr>客户类型</nobr></th>-->
  <!--        <th style="text-align:center"><nobr>气表品牌</nobr></th>-->
          </thead>
          <tbody>
          <tr v-for="row in history">
            <td><nobr>{{row.msg}}'</nobr></td>
            <td><nobr>{{row.f_instruct_state}}</nobr></td>
  <!--          <td><nobr>{{row.f_user_type}}</nobr></td>-->
  <!--          <td><nobr>{{row.f_meter_brand}}</nobr></td>-->
          </tr>
          </tbody>
        </table>
      </div>
    </div>
</template>


<script>
  import {PagedList} from 'vue-client'

export default {
    title: '表计信息修改',
    props: ['user', 'checked1', 'gasbrandid'],

    data () {
      return {
        newmeterinfo: [{}],
        history: [],
        row: {},
        gasbrand: null
      }
    },
    ready () {

    },
    watch: {
      'user': {
        handler: async function (val) {
          this.history = []
          if (val.length === 1) {
            await this.$resetpost('rs/sql/getIotParams', {data: {t_userfiles_id: val[0].f_userfiles_id}}, {resolveMsg: null, rejectMsg: null}).then((rat) => {
              this.row = {}
              console.log('=============', rat.data)
              this.row.forceSafeCheckUsedDayCount = 0
              this.row.currStairUsedGasCount = 0
              this.row.forceScrapUsedDayCount = 0
              this.row.isForceSrape = '1'
              if (rat.data.length > 0) {
                rat.data.forEach((item) => {
                  this.row[item.f_param_lname] = item.f_param_value
                })
                // let param = JSON.parse(rat.data[0].f_data)
                // console.log(param)
                // this.row= param
              }
            })
            await this.$resetpost('rs/sql/getParamInstruct', {data: {condition: `i.f_userfiles_id='${val[0].f_userfiles_id}'` }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
              this.history = res.data
            })
          }
          if (this.gasbrandid[0]) {
            await this.refreshParam(this.gasbrandid[0])
          }
        },
        deep: true

      }
    },
    methods: {
      close () {
        this.$dispatch('close')
      },
      async setParam () {
        let user = []
        let filesid = ''
        this.user.forEach((item) => {
          user.push(item.f_userfiles_id)
          filesid += item.f_userfiles_id + ','
        })
        filesid = filesid.substr(0, filesid.length - 1)
        let params = []
        console.log('------------this.newmeterinfo', this.newmeterinfo)
        for (let i = 0; i < this.newmeterinfo.length; i++) {
          for (let j = 0; j < this.newmeterinfo[i].params.length; j++) {
            for (let key in this.row) {
              if (key === this.newmeterinfo[i].params[j].title) {
                let data = {}
                data.param_group = this.newmeterinfo[i].name
                data.param_name = this.newmeterinfo[i].params[j].name
                data.param_value = this.row[key]
                data.param_lname = this.newmeterinfo[i].params[j].title
                params.push(data)
              }
            }
          }
        }
        let param = {
          condition: 'f_gasbrand_id = ' + this.gasbrandid[0] + ' and f.f_userfiles_id in (' + filesid + ')',
          switchCheckAll: this.checked1,
          users: user,
          params: params,
          f_alias: this.gasbrand.f_alias,
          columnName: 'g.f_userfiles_id',
          // inputter_name: this.$login.f.name,
          f_operator: this.$login.f.name,
          f_operatorid: this.$login.f.id,
          f_orgid: this.$login.f.orgid,
          f_orgname: this.$login.f.orgs,
          f_depid: this.$login.f.depids,
          f_depname: this.$login.f.deps
        }
        console.log(param)
        await this.$resetpost('/rs/logic/alteration_batch', {data: param}, {rejectMsg: '批量保存失败', resolveMsg: '保存成功'})
        this.row = null
        this.$dispatch('clear')
      },
      async refreshParam (val) {
        this.newmeterinfo = [{}]
        try {
          let res = await this.$resetpost('/webmeter/rs/logic/getParamsByGasBrand', {data: {gasBrandId: val}}, {resolveMsg: null, rejectMsg: null})
          this.newmeterinfo = res.data
        } catch (error) {
          this.$showAlert('该气表品牌不支持参数设置', 'warning', 1500)
        }
      }
    }
  }
</script>
<style>
  .btn-border {
    border: none;
    border-radius: 6px;
  }
</style>
