<template>
  <div class="auto select-overspread">
    <validator name='v'>
      <ul class="nav nav-tabs" >
        <li role="presentation" class="active"><a href="#">Phone端设备号</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_terminal_number" placeholder="设备号" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body">使用公司</label>
              <right-tree :userid.sync='userid' :source.sync='source' @re-res="getRes"></right-tree>
          </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_terminal_number: '',
          f_equipment_type: 'PHONE',
          f_state: '正常'
        },
        filialeCodeStr: this.$login.f.f_orgids,
        userid: this.$login.f.id,
        source: `tool.getFullTree(this.getRights().where(row.getType() == $organization$))`,
      }
    },
    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_filialeids = this.filialeCodeStr
        console.log('保存', this.model)
        this.$resetpost('rs/entity/t_equipment', this.model, {resolveMsg: '保存成功', rejectMsg: '保存失败'}).then((res) => {
          this.$dispatch('refresh')
        }).catch(() => {
          this.$dispatch('refresh')
        })
      },
      edit (row) {
        console.log('修改，，。。', row)
        this.model.f_username = row.f_username
        this.model.f_terminal_number = row.f_terminal_number
        this.model.id = row.id
        this.filialeCodeStr = row.f_filialeids
      },
      initModel () {
        delete this.model.id
        this.model.f_username = ''
        this.model.f_terminal_number = ''
      },
      cancel () {
        this.$dispatch('close')
      },
      getRes(obj) {
        this.filialeCodeStr = obj.resids
      },
    }
  }
</script>
