<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.name+param.title].bak_val}}
        </div>
      </div>
      <div style="height: auto">
        <ul class="nav nav-tabs col-sm-12" >
          <li class="active"><a>区间用气量报警参数</a></li>
        </ul>
        <div class="col-sm-12"  style="height: auto">时间区间1：{{row['readperiodusegasAlarmparam'].bak_val.timesection1||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">区间1用气量：{{row['readperiodusegasAlarmparam'].bak_val.usegas1||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">时间区间2：{{row['readperiodusegasAlarmparam'].bak_val.timesection2||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">区间2用气量：{{row['readperiodusegasAlarmparam'].bak_val.usegas2||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">时间区间3：{{row['readperiodusegasAlarmparam'].bak_val.timesection3||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">区间3用气量：{{row['readperiodusegasAlarmparam'].bak_val.usegas3||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">上次报警区间：{{row['readperiodusegasAlarmparam'].bak_val.realusegas1||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">上次报警区间：{{row['readperiodusegasAlarmparam'].bak_val.realusegas2||'暂无数据'}}</div>
        <div class="col-sm-12"  style="height: auto">上次报警区间：{{row['readperiodusegasAlarmparam'].bak_val.realusegas3||'暂无数据'}}</div>
<!--        [{"yjbbhlength":28,"softversionNo":"n0100081","mzbbhlength":15,"mzversion":"BC25PAR01A04_BT","version":"2022-07-28","yjversion":"YIMS-M-T1-3-1-H-2-13-17_V1.1"}]-->
        <ul class="nav nav-tabs col-sm-12" >
          <li class="active"><a>软件版本号</a></li>
        </ul>
        {{row['getMeterVersion'].bak_val||'暂无数据'}}
<!--        [{"yjbbhlength":28,"softversionNo":"n0100081","mzbbhlength":15,"mzversion":"BC25PAR01A04_BT","version":"2022-07-28","yjversion":"YIMS-M-T1-3-1-H-2-13-17_V1.1"}]-->
      </div>
      <div style="height: auto">
        <ul class="nav nav-tabs col-sm-12" >
          <li class="active"><a>下次上报日期</a></li>
        </ul>
        {{row['readNextreportTime'].bak_val||'暂无数据'}}
      </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>
        <tr>
          <th style="text-align:center"><nobr>指令发送状态</nobr></th>
          <th style="text-align:center"><nobr>操作</nobr></th>
        </tr>
        <!--        <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.f_instruct_state}}</nobr></td>
          <td><nobr>{{row.msg}}</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>
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?pageNo=1&pageSize=9999999', {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) => {
                if (item.f_back_content === '1') {
                  item.f_back_content = '开'
                }
                if (item.f_back_content === '0') {
                  item.f_back_content = '关'
                }
                if (item.f_param_name === '读表功能') {
                  if (item.f_param_content === '读区间用气量报警参数' && item.f_back_content) {
                    let str = item.f_back_content.substring(0, item.f_back_content.indexOf(']'))
                    item.f_back_content = JSON.parse(str.replace('[', '').replace(']', ''))
                  }
                  if (item.f_param_value && item.f_back_content && item.f_param_value === 'getMeterVersion') {
                    let str = item.f_back_content.substring(0, item.f_back_content.indexOf(']'))
                    item.f_back_content = JSON.parse(str.replace('[', '').replace(']', ''))['softversionNo']
                  }
                  if (item.f_param_value && item.f_back_content && item.f_param_value === 'readNextreportTime') {
                    let str = item.f_back_content.substring(0, item.f_back_content.indexOf(']'))
                    str = JSON.parse(str.replace('[', '').replace(']', ''))['datetime']
                    item.f_back_content = '20' + str.substr(0, 2) + '-' + str.substr(2, 2) + '-' + str.substr(4, 2) + ' ' +
                    str.substr(6, 2) + ':' + str.substr(8, 2) + ':' + str.substr(10, 2)
                  }
                  if (!item.f_param_value) {
                    item.f_param_value = '暂无数据'
                  }
                  this.row[item.f_param_value] = {set_val: item.f_param_value, bak_val: item.f_back_content}
                } else {
                  this.row[item.f_param_name + item.f_param_lname] = {set_val: item.f_param_value, bak_val: item.f_back_content}
                }
              })
                // 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 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.filter(item => { return (item.name !== '读表功能' && item.name !== '读记录数据' && item.name !== '设置区间用气量报警参数') })
      } catch (error) {
        this.$showAlert('该气表品牌不支持参数设置', 'warning', 1500)
      }
    },
    readNextReportTime_parse () {
      let str = JSON.parse(row['readNextreportTime'].bak_val)[0].datetime
    }
  }
}
</script>
<style>
  .btn-border {
    border: none;
    border-radius: 6px;
  }
</style>
