<template>
  <div class="auto select-overspread">
    <validator name='v'>
      <ul class="nav nav-tabs" >
        <li role="presentation" class="active"><a href="#">POS</a></li>
      </ul>
      <form class="form-horizontal">
        <div class="row">
          <div class="col-sm-6">
            <label class="font_normal_body" >设备编号</label>
            <input type="text" class="input_search" style="width: 60%" v-model="model.f_terminal_number" placeholder="设备编号" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body" >设备名称</label>
            <input type="text" class="input_search" style="width: 60%" v-model="model.f_terminal_name" placeholder="设备名称" >
          </div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            <label class="font_normal_body" >机器编号</label>
            <input type="text" class="input_search" style="width: 60%" v-model="model.f_machine_number" placeholder="机器编号" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body" >联系电话</label>
            <input type="text" class="input_search" style="width: 60%" v-model="model.f_phone" placeholder="联系电话" >
          </div>
        </div>
        <div class="row">
          <div class="col-sm-6">
            <label class="font_normal_body" >&nbsp;&nbsp;&nbsp;所在地</label>
            <input type="text" class="input_search" style="width: 60%" v-model="model.f_address" placeholder="所在地" >
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body" >所属银行</label>
            <input type="text" class="input_search" style="width: 60%" v-model="model.f_bank_name" placeholder="所属银行" >
          </div>
        </div>
        <div  class="col-sm-12">
          <label  class="font_normal_body " style="margin-top:-20px">&nbsp;&nbsp;&nbsp;备注&nbsp;&nbsp;&nbsp;</label>
          <textarea class="input_textarea" rows="3" style="width:80%;margin-top:5px" v-model="model.f_comments"></textarea>
        </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_terminal_number: '',
          f_terminal_name: '',
          f_bank_name: '',
          f_equipment_type: 'POS',
          f_state: '正常',
          f_machine_number:'',
          f_phone:'',
          f_comments:'',
          f_address:'',
          f_filialeids:this.f_filialeids,
          f_orgid:''
        }
      }
    },
    props: ['data', 'f_filialeids'],
    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 () {
       // if(this.f_filialeids!=''&&this.f_filialeids!=null){
         this.model.f_operator = this.$login.f.name
         this.model.f_operatorid = this.$login.f.id
         this.model.f_filialeids = this.f_filialeids
         this.model.f_orgid = this.$login.f.orgid
         this.model.f_orgname = this.$login.f.orgs
         this.model.f_depid = this.$login.f.depids
         this.model.f_depname = this.$login.f.deps
         this.$resetpost('rs/entity/t_equipment', this.model, {resolveMsg: '保存成功', rejectMsg: '保存失败'}).then((res) => {
           this.$dispatch('refresh')
         }).catch((error) => {
           this.$dispatch('refresh')
         })
       // }else
       // {
       //   this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
       // }

      },
      edit (row) {
        this.model.f_terminal_number = row.f_terminal_number
        this.model.f_terminal_name = row.f_terminal_name
        this.model.f_bank_name = row.f_bank_name
        this.model.f_machine_number = row.f_machine_number
        this.model.f_address = row.f_address
        this.model.f_phone = row.f_phone
        this.model.f_comments=row.f_comments
        this.model.f_filialeids=row.f_filialeids
        this.model.id = row.id
        this.model.f_orgid = row.f_orgid
      },
      initModel () {
        delete this.model.id
        this.model.f_terminal_number = ''
        this.model.f_terminal_name = ''
        this.model.f_bank_name = ''
        this.model.f_machine_number = ''
        this.model.f_phone = ''
        this.model.f_address = ''
        this.model.f_filialeids=''
        this.model.f_orgid=''
        this.model.f_comments=''
      },
      cancel () {
        this.$dispatch('close')
      }
    }
  }
</script>
