<template>
  <div class="auto select-overspread">
    <validator name='v'>
      <form class="form-horizontal" novalidate>
        <ul class="nav nav-tabs">
          <li class="active"><a href="#">设备信息</a></li>
        </ul>
        <div class="row">
          <div :class="[$v.f_brand_spec.required ? 'has-error' : 'has-success']" class="col-sm-6">
            <label class="font_normal_body" for="f_brand_spec">设备名称</label>
            <input :disabled='isEdit' class="input_search" placeholder="设备名称" style="width:60%"
                   type="text" v-model="model.f_brand_spec" v-validate:f_brand_spec='{required: true }'>
          </div>
          <div :class="[$v.f_typename.required ? 'has-error' : 'has-success']" class="col-sm-6">
            <label class="font_normal_body" for="f_typename">设备品牌</label>
            <input :disabled='isEdit' class="input_search" placeholder="设备品牌" style="width:60%"
                   type="text" v-model="model.f_typename" v-validate:f_typename='{required: true }'>
          </div>
          <div :class="[$v.f_typenumber.required ? 'has-error' : 'has-success']" class="col-sm-6">
            <label class="font_normal_body" for="f_typenumber">设备型号</label>
            <input :disabled='isEdit' class="input_search" placeholder="设备型号" style="width:60%"
                   type="text" v-model="model.f_typenumber" v-validate:f_typenumber='{required: true }'>
          </div>
          <div :class="[$v.f_unitprice.required ? 'has-error' : 'has-success']" class="col-sm-6">
            <label class="font_normal_body" for="f_unitprice">设备价格</label>
            <input :disabled='isEdit' class="input_search" placeholder="设备价格" style="width:60%"
                   type="text" v-model="model.f_unitprice" v-validate:f_unitprice='{required: true }'>
          </div>
          <div class="col-sm-6">
            <label class="font_normal_body">使用公司</label>
            <res-select :initresid='curorgid'
                        @res-select="getorg"
                        is-mul="false"
                        restype='organization'>
            </res-select>
          </div>
        </div>
      </form>

      <div style="text-align:right;height:auto;margin-top: 10px;">
        <button :disabled='!$v.valid' @click="confirm()" class="button_search" v-if="!isEdit">确认</button>
        <button @click="close()" class="button_clear">取消</button>
      </div>
    </validator>
  </div>
</template>
<script>
import {HttpResetClass} from 'vue-client'
import Vue from 'vue'

export default {
  data () {
    return {
      model: {
        f_operatorid: Vue.$login.f.id,
        f_operator: Vue.$login.f.name,
        f_orgid: Vue.$login.f.orgid,
        f_orgname: Vue.$login.f.orgs,
        f_depid: Vue.$login.f.depids,
        f_depname: Vue.$login.f.deps,
        // 所属公司
        f_filialeid: '',
        // 所属公司名称
        f_filialename: ''
      },
      // 编辑控制
      isEdit: false,
      // 公司树状图信息
      curorgid: [this.$login.f.orgid]
    }
  },
  props: ['data'],
  async ready () {
    if (this.data) {
      // 合并选中数据
      this.model = Object.assign({}, this.model, this.data)
    }
  },
  methods: {
    async confirm () {
      // 验证公司组织是否已选择
      if (!this.model.f_filialeid) {
        this.$showAlert('请选择使用公司', 'warning', 2000)
        return
      }
      await this.$resetpost('rs/logic/savedevice', this.model, {resolveMsg: '保存成功', rejectMsg: '保存失败'})
      this.$dispatch('close')
    },
    getorg (id, name) {
      this.model.f_filialeid = id[0]
      this.model.f_filialename = name[0]
    },
    close () {
      this.$dispatch('close')
    }
  }
}
</script>
<style lang="less">
#gas-price-form {
  .form-group {
    margin-left: 0px;
    margin-right: 0px;
  }
}
</style>
