<template>
  <div class="auto select-overspread">
    <validator name='v'>
      <ul class="nav nav-tabs" >
        <li role="presentation" class="active"><a href="#">PC端MAC</a></li>
      </ul>
      <form class="form-horizontal">
          <div class="col-sm-6">
            <label class="font_normal_body">使用人员</label>
            <input type="text"  style="width: 60%" class="input_search" v-model="model.f_username" placeholder="使用人员" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body">所属地址</label>
            <input type="text"  style="width: 60%" class="input_search" v-model="model.f_mac_outlets" placeholder="所属地址" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body">mac地址</label>
            <input type="text"  style="width: 60%" class="input_search" v-model="model.f_mac_number" placeholder="mac地址" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body">使用公司</label>

              <res-select restype='organization'
                          is-mul="false"
                          @res-select="getorg"
                          :initresid="curorgid">
              </res-select>

        </div>
      </form>
      <div style="text-align:right;height:auto;">
        <button class="btn button_search" @click="confirm()"  >确认</button>
        <button class="btn button_clear " @click="cancel()" >取消</button>
      </div>
    </validator>
  </div>
</template>
<script>


  export default {
    data () {
      return {
        model: {
          f_username: '',
          f_mac_outlets: '',
          f_mac_number: '',
          f_equipment_type: 'PC',
          f_state: '正常'
        },
        curorgid: this.$login.f.orgid,
        f_orgid: ''
      }
    },
    props: ['data'],
    watch: {
      'data' (val) {
          if (val) {
            this.edit(val)
          } else {
              this.initModel()
          }
      }
    },
    ready () {
      console.log('mac信息：', this.data)
      if (this.data) {
          this.edit(this.data)
      }
    },
    methods: {
      confirm () {
        this.model.f_operator = this.$login.f.name
        this.model.f_operatorid = this.$login.f.id
        this.model.f_orgid = this.f_orgid
        console.log('保存', this.model)
        this.$resetpost('rs/entity/t_equipment', this.model, {resolveMsg: '保存成功', rejectMsg: '保存失败'}).then((res) => {
          this.$dispatch('refresh')
        }).catch((error) => {
          this.$dispatch('refresh')
        })
      },
      edit (row) {
        console.log('修改，，。。', row)
        this.model.f_username = row.f_username
        this.model.f_mac_outlets = row.f_mac_outlets
        this.model.f_mac_number = row.f_mac_number
        this.model.id = row.id
        this.f_orgid = row.f_orgid
      },
      initModel () {
        delete this.model.id
        this.model.f_username = ''
        this.model.f_mac_outlets = ''
        this.model.f_mac_number = ''
      },
      cancel () {
        this.$dispatch('close')
      },
      getorg (val) {
        this.f_orgid = val[0]
      }
    }
  }
</script>
