<template>
  <div class="auto">
    <data-grid :model="model" partial='list' v-ref:grid>
      <template partial='head'>
        <tr>
           <th>序号</th>
           <th>用户姓名</th>
           <th>户编号</th>
           <th>表编号</th>
           <th>表册号</th>
           <th>表品牌</th>
           <th>表型号</th>
           <th>是否总表</th>
           <th>操作</th>
        </tr>
      </template>
      <template partial='body'>
        <td>{{$index+1}}</td>
        <td style="text-align:center">{{row.f_user_name}}</td>
        <td style="text-align:center">{{row.f_userinfo_id}}</td>
        <td style="text-align:center">{{row.f_user_id}}</td>
        <td style="text-align:center">{{row.f_meterbook_id}}</td>
        <td style="text-align:center">{{row.f_meter_brand}}</td>
        <td style="text-align:center">{{row.f_meter_style}}</td>
        <td style="text-align:center">{{row.f_meter_type}}</td>
        <td><button type="button" name="button" class="btn btn-link"
        @click.stop="$parent.$parent.deleteSplit(row)">删除</button></td>
      </template>
     <template partial='foot'></template>
   </data-grid>
  </div>
</template>

<script>
/**
*阶梯水价相关信息组件
*/

export default {
  props: ['data'],
  data () {
    return {
      model: {
        rows: []
      }
    }
  },
  watch: {
    'data' (val) {
      if (val.f_user_id) {
        this.getUpdate(val.f_user_id)
      }
    }
  },
  ready () {
    if (this.data && this.data.f_user_id) {
      this.getUpdate(this.data.f_user_id)
    }
  },
  methods: {
    getUpdate (id) {
      let tablename = 'V_user_table'
      let condition = 'f_meter_id =' + "'" + id + "'"
      this.$SqlService.singleTable(tablename, condition)
      .then(
        (res) => {
          this.model.rows = res.data
        }
      ).catch(
        (error) => this.$dispatch('error', '总分表管理', this.data, error)
      )
    },
    deleteSplit (row) {
      this.$resetpost('rs/logic/deleteSplit', {data: row}).then((res) => {
        this.getUpdate(this.data.f_user_id)
      })
    }
  }
}
</script>
<style>

</style>
