<template>
  <div style="overflow-x: hidden;">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <!-- <p class="h3" align="center"><b>通气组录入信息表</b></p> -->
        <caption><h3 style="font-weight:bold; text-align:center;">用户表修改</h3></caption>

        <div class="form-group">
          <label for="f_card_id" class="col-sm-offset-1 col-sm-1 control-label">卡号:</label>
          <div class="col-sm-2">
              <input class="form-control" type="text" v-model="model.f_card_id" placeholder='卡号'>
          </div>

          <label for="f_meter_no" class="col-sm-1 control-label">表号:</label>
          <div class="col-sm-2">
             <input class="form-control" type="text" v-model="model.f_meter_no" placeholder='表号'>
          </div>
           <label for="f_meter_brand" class="col-sm-1 control-label">表牌:</label>
           <div class="col-sm-2">
              <!-- <input class="form-control" type="text" v-model="model.f_meter_brand" > -->
              <v-select id="f_meter_brand"
              placeholder='请选择'
              :value.sync="f_meter_brand"
              :options='f_meterbrand'
              close-on-select clear-button></v-select>
            </div>
          </div>

          <div class="form-group">
            <label for="f_meter_measurement" class="col-sm-offset-1 col-sm-1 control-label">计量类型:</label>
            <div class="col-sm-2">
                <!-- <input class="form-control" type="text" v-model="model.f_meter_measurement" > -->
                <v-select id="f_meter_measurement"
                placeholder='请选择'
                :value.sync="f_meter_measurement"
                :options='f_metermeasurement'
                close-on-select clear-button></v-select>
            </div>

            <label for="f_meter_diameter" class="col-sm-1 control-label">表径:</label>
            <div class="col-sm-2">
              <v-select id="f_meter_diameter"
              placeholder='请选择'
              :value.sync="f_meter_diameter"
              :options='f_meterdiameter'
              close-on-select clear-button></v-select>
            </div>
             <label for="f_meter_reading" class="col-sm-1 control-label">机表读数:</label>
             <div class="col-sm-2">
               <input class="form-control" type="text" v-model="model.f_meter_reading"  number
               onkeyup="this.value=this.value.replace(/\D/g,'')"
               onafterpaste="this.value=this.value.replace(/\D/g,'')"
               placeholder='机表读数，只能输入数字'>
              </div>
            </div>

          <div class="form-group">
             <label for="f_meter_remain" class="col-sm-offset-1 col-sm-1 control-label">剩余气量:</label>
             <div class="col-sm-2">
                <input class="form-control" type="text" v-model="model.f_meter_remain" number
                onkeyup="this.value=this.value.replace(/\D/g,'')"
                onafterpaste="this.value=this.value.replace(/\D/g,'')"
                placeholder='剩余气量，只能输入数字'>
             </div>
             <label for="f_meter_total" class="col-sm-1 control-label">总气量:</label>
              <div class="col-sm-2">
                 <input class="form-control" type="text" v-model="model.f_meter_total"
                 onkeyup="this.value=this.value.replace(/\D/g,'')"
                 onafterpaste="this.value=this.value.replace(/\D/g,'')"
                 placeholder='总气量，只能输入数字'>
              </div>

              <label for="f_meter_accumulation" class="col-sm-1 control-label">累购:</label>
              <div class="col-sm-2">
                <input class="form-control" type="text" v-model="model.f_meter_accumulation"
                onkeyup="this.value=this.value.replace(/\D/g,'')"
                onafterpaste="this.value=this.value.replace(/\D/g,'')"
                placeholder='累购，只能输入数字'>
              </div>
            </div>

            <div class="form-group">
               <label for="f_remark" class="col-sm-offset-1 col-sm-1 control-label">备注:</label>
               <div class="col-sm-2">
                  <input class="form-control" type="text" v-model="model.f_remark">
               </div>
              </div>
          </form>
          <div style="text-align:center;height:auto;">
            <button class="btn btn-primary" :disabled='!($v.valid)' @click="confirm()" style="width:100px;margin-left:20px;">
              <span class="glyphicon glyphicon-floppy-disk"></span>保存
            </button>
            <button class="btn btn-default"  @click='$back(row)' style="width:100px;margin-left:20px;">
              <span class="glyphicon glyphicon-log-out"></span>返回
            </button>
          </div>
    </validator>
  </div>
</template>
<script>
import co from 'co'
import AppData from '../../stores/AppData'

let info = function * (self) {
  self.model.f_meter_brand = self.f_meter_brand[0]
  self.model.f_meter_measurement = self.f_meter_measurement[0]
  self.model.f_meter_diameter = self.f_meter_diameter[0]
  console.log('表修改model', self.model)
  // yield self.$post('api/af-safecheck/logic/修改表档案', {data: self.model}, {resolveMsg: null, rejectMsg: null})
  self.$back(self.model)
}

export default {
  title: '表修改',
  data () {
    return {
      model: {},
      f_meter_diameter: '',
      f_meterdiameter: this.$appdata.getParam('表径'),
      f_meter_brand: '',
      f_meterbrand: this.$appdata.getParam('燃气表品牌'),
      f_meter_measurement: '',
      f_metermeasurement: this.$appdata.getParam('计量类型')
    }
  },
  props: [ 'row', 'flag' ],
  watch: {
    // source变化时，把source中的内容全部给model
    'row' (val) {
      this.model = Object.assign({}, this.model, this.row)
      this.f_meter_brand = [this.row.f_meter_brand]
      this.f_meter_measurement = [this.row.f_meter_measurement]
      this.f_meter_diameter = [this.row.f_meter_diameter]
    }
  },
  methods: {
    confirm () {
      let infomathis = info(this)
      return co(infomathis)
    }
  },
  computed: {
    user_type () {
      return this.$appdata.getParam('用户类型')
    }
  },
  ready () {
    this.model.f_meter_brand = this.f_meter_brand
    this.$watch('f_meter_brand', function (val) {
      this.model.f_meter_brand = val
    })
    this.model.f_meter_measurement = this.f_meter_measurement
    this.$watch('f_meter_measurement', function (val) {
      this.model.f_meter_measurement = val
    })
    this.model.f_meter_diameter = this.f_meter_diameter
    this.$watch('f_meter_diameter', function (val) {
      this.model.f_meter_diameter = val
    })
  }
}
</script>
