<template>
  <div class="span">
    <validator name='v'>
      <form novalidate class="form-horizontal select-overspread" @valid="confirmEditcheck = true" @invalid="confirmEditcheck = false">

          <ul class="nav nav-tabs">
            <li class="active"><a>表计信息</a></li>
          </ul>

        <div class="col-sm-12 form-group form-input-group" style="margin-top: 20px">
          <label class="button_search">批次号</label>
          <input type="text" v-model="newmeterinfo.f_batch_number" class="form-control" placeholder="批次号">
        </div>

        <div class="col-sm-12 form-group form-input-group" :class="[$v.f_meternumber.required ? 'has-error' : '']">
          <label class="button_search">表号</label>
          <input type="text" v-model="newmeterinfo.f_meternumber" class="form-control" v-validate:f_meternumber='{required: true }'placeholder="表号">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">终端名称</label>
          <input type="text" v-model="newmeterinfo.f_terminal_id" class="form-control" placeholder="终端名称">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">表计电话</label>
          <input type="text" v-model="newmeterinfo.f_meter_phone" class="form-control" placeholder="表计电话">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">表流量</label>
          <input type="text" v-model="newmeterinfo.f_diameter" class="form-control" placeholder="表流量">
        </div>

        <div class="col-sm-12 form-group form-input-group" :class="[$v.f_iot_type.required ? 'has-error' : '']">
          <label class="button_search">表通道类型</label>
          <input type="text" v-model="newmeterinfo.f_iot_type" class="form-control" v-validate:f_iot_type='{required: true }' placeholder="表通道类型">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">阀控标识</label>
          <input type="text" v-model="newmeterinfo.f_valvemark" class="form-control" placeholder="阀控标识">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">表通讯序号</label>
          <input type="text" v-model="newmeterinfo.f_telecomm_no" class="form-control" placeholder="表通讯序号">
        </div>

        <div class="col-sm-12 form-group form-input-group" :class="[$v.f_imei.required ? 'has-error' : '']">
          <label class="button_search">IMEI码</label>
          <input type="text" v-model="newmeterinfo.f_imei" class="form-control" v-validate:f_imei='{required: true }' placeholder="IMEI码">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">IMSI码</label>
          <input type="text" v-model="newmeterinfo.f_imsi" class="form-control" placeholder="IMSI码">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">设备号</label>
          <input type="text" v-model="newmeterinfo.f_device_id" class="form-control" placeholder="设备号">
        </div>

        <div class="col-sm-12 form-group form-input-group">
          <label class="button_search">厂商代码</label>
          <input type="text" v-model="newmeterinfo.f_vender" class="form-control" placeholder="厂商代码">
        </div>

        <div style="text-align:center;height:auto;margin-top:6px;">
          <button class="btn btn-success" @click="confirmEdit()" :disabled="!confirmEditcheck">确认</button>
          <button class="btn btn-default" @click="close()">取消</button>
        </div>
      </form>
    </validator>
  </div>
</template>


<script>
  export default {
    title: '表计信息修改',
    props: ['oldmeter'],
    data () {
      return {
        newmeterinfo: {},
        confirmEditcheck: false
      }
    },
    ready () {
      this.newmeterinfo = Object.assign({}, {}, this.oldmeter)
    },
    watch: {
      'oldmeter' () {
        this.newmeterinfo = Object.assign({}, {}, this.oldmeter)
      }
    },
    methods: {
      close () {
        this.$dispatch('close')
      },
      ready () {
      },
      confirmEdit () {
        if (this.newmeterinfo.f_meternumber && this.newmeterinfo.f_imei && this.newmeterinfo.f_iot_type && this.newmeterinfo.f_meternumber !== '' && this.newmeterinfo.f_imei !== '' && this.newmeterinfo.f_iot_type !== '') {
          let data = {
            f_operator: this.$login.f.name,
            f_orgstr: this.$login.f.orgpathstr,
            f_filialeids: this.$login.f.f_orgids,
            f_filiale: this.$login.orgpathnames
          }
          data.oldmeter = this.oldmeter
          data.newmeter = this.newmeterinfo
          this.$resetpost('rs/logic/EditMeterInfo', {data: data}, {resolveMsg: null, rejectMsg: '修改错误!'}).then((res) => {
            this.$showMessage(res.data.result)
          })
        } else {
          this.$showMessage('表号/IMEI码/表通道类型 不能为空')
        }
        this.$dispatch('close')
      }
    }
  }
</script>
