<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <label for="f_tablebase" class=" col-sm-2 control-label">旧表剩余金额:</label>
        <div class="col-sm-2">
          <input class="form-control" type="number" v-model="model.f_tablebase" placeholder="表底数" :disabled="disabled">
        </div>
      </form>
      <div class="col-sm-4" style="margin-left:8%" v-if="!message">
        <button class="btn btn-success" @click="confirm()"  :disabled='!$v.valid'>确&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;认</button>
        <button class="btn btn-default" @click="clean()" style="width:80px;margin-left:20px;">取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消</button>
      </div>
    </validator>
  </div>
</template>
<script>
/**
*换表管理
*处理旧表为金额卡表的旧表信息
*/
export default {
  data () {
    return {
      model: {},
      disabled: false
    }
  },
  props: ['row', 'message'],
  methods: {
    confirm () {
      if (this.model.f_tablebase < 0) {
        this.$ChangeMeterService.changeMeter(this.model, this.row)
        .then((res) => {
          this.$dispatch('firstsuccess', 'hand', res.data)
          this.disabled = true
        }).catch((error) => {
          this.$dispatch('error', '换表管理', this.data, error)
        })
      } else {
        this.row.f_newremanent_amount = (this.model.f_tablebase - 0)
        this.$dispatch('firstsuccess', 'nohand')
      }
    },
    clean () {
      this.$dispatch('clean', this.row)
    }
  }
}
</script>
