<template>
  <div class="flex" style="overflow-x: hidden;">
    <div class="auto">
      <div v-if='old'>
        <p class="bg-info text-center" style="padding: 8px;">旧表信息</p>
        <div class="row auto">
          <machine-meter v-if=" row && (row.f_meter_type === '机表' || row.f_meter_type === '远传表')"
                         :row='row' :message='message'></machine-meter>
          <gas-card-meter v-if="row && (row.f_meter_type == '气量卡表')" :row='row' :message='message'></gas-card-meter>
          <amount-card-meter v-if="row && (row.f_meter_type == '金额卡表')" :row='row' :message='message'></amount-card-meter>
          <iot-meter v-if="row && (row.f_meter_type == '物联网表')" :row='row' :message='message'></iot-meter>
        </div>
      </div>
      <p class="bg-info text-center" style="padding: 8px;" v-if="isnew">新表信息</p>
      <change-new-meter v-if="isnew" :row='row'></change-new-meter>
    </div>

  </div>
</template>
<script>
/**
 *换表管理
 *组合界面，加载机表，物联网表，气量卡表，金额卡表旧表信息，以及控制显示换新表信息
 */

export default {
  title: '换表登记',
  data () {
    return {
      isnew: false,
      old: true,
      message: false,
      msg: null
    }
  },
  props: ['row'],
  ready () {
    console.log('看下换表父组件的row内容：', this.row)
  },
  methods: {
    closePrompt () {
      this.$dispatch('refresh')
    }
  },
  events: {
    'firstsuccess' (type, data) {
      if (type === 'nohand') {
        this.old = false
        this.isnew = true
      } else if (type === 'hand') {
        this.message = true
        if (data.errorType === 'owe') {
          this.msg = '该表有欠费,请转到缴费进行清欠'
        } else if (data.errorType === 'hasowe') {
          this.msg = '该表已产生欠费'
        } else if (data.errorType === 'hand') {
          this.msg = '该表有未抄表,请转到抄表管理界面进行抄表'
        } else if (data.errorType === 'iot') {
          this.msg = '该表结算已产生欠费,请转到缴费界面进行缴费'
        } else if (data.errorType === 'split') {
          this.msg = '该表下面有未抄的分表信息,请先对分表进行抄录,才能换表！'
        } else if (data.errorType === 'exceeduse') {
          this.msg = '该表用量已超出'
        }
        console.log('物联网表欠费啦，，，')
        this.$showAlert(this.msg, 'warning', 5000)
        this.$dispatch('refresh', data)
      }
    }
  }
}
</script>
