<template>
  <div class="auto select-overspread">
    <validator name='v'>
      <form class="form-horizontal" style="margin-top:20px;flex: 1;">
        <div class="row">

          <div class="col-sm-6"  :class="[$v.f_adjustable_id.required ? 'has-error' : '']">
            <label  class="font_normal_body">&nbsp;&nbsp;&nbsp;抄表册名&nbsp;&nbsp;&nbsp;</label>
            <input type="text"  v-model="model.f_book_name" v-validate:f_adjustable_id='{required: true }' class="input_search" style="width:60%" >
          </div>

          <div class=" col-sm-6" :class="[$v.f_adjustable_address.required ? 'has-error' : '']">
            <label  class="font_normal_body">&nbsp;&nbsp;&nbsp;抄&nbsp;&nbsp;表&nbsp;&nbsp;员&nbsp;&nbsp;</label>
            <v-select :value.sync="model.f_inputtor" v-model="model.f_inputtor"  :value-single="true"
                      :options='inputtores' placeholder='　抄表员' close-on-select ></v-select>
          </div>

          <div class="col-sm-6"  >
            <label class="font_normal_body">&nbsp;&nbsp;&nbsp;组&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;织&nbsp;&nbsp;&nbsp;</label>
            <input type="text" v-model="model.f_orgname" readonly="true"
                   class="input_search" style="width:60%" placeholder="进口管径" v-el:inpipe v-next-el="outpipe">
          </div>

          <div class="col-sm-6"  >
            <label class="font_normal_body">&nbsp;&nbsp;&nbsp;部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门&nbsp;&nbsp;&nbsp;</label>
            <input type="text" v-model="model.f_depname" readonly="true"
                   class="input_search" style="width:60%" placeholder="进口管径" v-el:inpipe v-next-el="outpipe">
          </div>

          <div class="col-sm-6"  >
            <label class="font_normal_body">&nbsp;&nbsp;&nbsp;登&nbsp;&nbsp;录&nbsp;&nbsp;人&nbsp;&nbsp;</label>
            <input type="text" v-model="model.f_operator" readonly="true"
                   class="input_search" style="width:60%" placeholder="进口管径" v-el:inpipe v-next-el="outpipe">
          </div>


        </div>
        <div class="row">
          <div class="col-sm-12">
            <label class="font_normal_body">&nbsp;&nbsp;&nbsp;备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注&nbsp;&nbsp;&nbsp;</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.f_book_remark"  rows="3" placeholder="备注"  v-el:remark ></input>
          </div>
        </div>
      </form>
      <div style="text-align:right;height:auto;margin-top:30px;margin-right:50px;">
        <button class="button_search button_spacing" @click="commit()" :disabled='!$v.valid || haveid || havaname'>保存</button>
        <button class="button_clear " @click="cancel()"  >取消</button>
      </div>
    </validator>
  </div>
</template>

<script>
    export default {
      props: ['changeinfo', 'dowhat'],
      data () {
        return {
          model: {
            f_book_name: '',
            f_operator: this.$login.f.name,
            f_operatorid: this.$login.f.id,
            f_orgid: this.$login.f.orgid,
            f_orgname: this.$login.f.orgs,
            f_depid: this.$login.f.depids,
            f_depname: this.$login.f.deps,
            f_book_remark: '',
            f_inputtor: ''
          },
          Source: 'dep=this.getParentByType($organization$).getSpecialResByType($department$),' +
            'tool.getFullTree(dep.where(row.hasSpecialRole($抄表员$)))'
        }
      },
      computed: {
        inputtores () {
          // 获取抄表员
          console.log('获取抄表员', this.$login.f)
          let rs = new Array()
          if (this.$login.f.f_gasman.length > 0) {
            for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
              let temp = {
                label: this.$login.f.f_gasman[i].name,
                value: this.$login.f.f_gasman[i].name
              }
              rs.push(temp)
            }
          }
          // let rs = this.$appdata.getParam('抄表员')
          return rs
        }
      },
      methods: {
        commit () {
          if (this.dowhat === 'change') {
            this.model.id = this.changeinfo.id
            this.model.version = this.changeinfo.version
          }
          this.$resetpost('rs/entity/t_meter_book', this.model, {
            resolveMsg: '添加成功',
            rejectMsg: '未通过，保存出错!!!'
          }).then(() => {
            this.$parent.refresh = -1 * this.$parent.refresh
            this.$parent.addShow = false
          })
        },
        cancel () {
          this.$parent.addShow = false
        }

      },
      watch: {
        changeinfo (v) {
          if (this.dowhat === 'change' || this.dowhat === '') {
            this.model.f_book_name = this.changeinfo.f_book_name
            this.model.f_operator = this.changeinfo.f_operator
            this.model.f_operatorid = this.changeinfo.f_operatorid
            this.model.f_orgid = this.changeinfo.f_orgid
            this.model.f_orgname = this.changeinfo.f_orgname
            this.model.f_depid = this.changeinfo.f_depid
            this.model.f_depname = this.changeinfo.f_depname
            this.model.f_book_remark = this.changeinfo.f_book_remark
            this.model.f_inputtor = this.changeinfo.f_inputtor
          } else {
            this.model.f_book_name = '',
              this.model.f_operator = this.$login.f.name,
              this.model.f_operatorid = this.$login.f.id,
              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.model.f_book_remark = '',
              this.model.f_inputtor = ''
          }
        }
      },
      ready () {
        if (this.dowhat === 'change' || this.dowhat === '') {
          this.model.f_book_name = this.changeinfo.f_book_name
          this.model.f_operator = this.changeinfo.f_operator
          this.model.f_operatorid = this.changeinfo.f_operatorid
          this.model.f_orgid = this.changeinfo.f_orgid
          this.model.f_orgname = this.changeinfo.f_orgname
          this.model.f_depid = this.changeinfo.f_depid
          this.model.f_depname = this.changeinfo.f_depname
          this.model.f_book_remark = this.changeinfo.f_book_remark
          this.model.f_inputtor = this.changeinfo.f_inputtor
        }
      }
    }
</script>

<style scoped>

</style>
