<template>
  <div class="auto">
    <validator name="v" @valid="$emit('valid')" @invalid="$emit('invalid')">
      <form class="form-horizontal select-overspread ">
        <div class="row">
          <div class="col-sm-8 form-group" v-if="this.usertype==='非民用'" :class="[(baseinfo.base.f_taxpayer_id.length < 16 || baseinfo.base.f_taxpayer_id.length > 18)  ? 'has-error' : '']">
            <label class="font_normal_body" for="f_taxpayer_id">纳税人识别号</label>
            <input class="input_search" placeholder="纳税人识别号" style="width:70%" type="text"
                   v-model="baseinfo.base.f_taxpayer_id" v-next-el="addressphone"   v-validate:f_taxpayer_id='{required: true }'
                   :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
          <div class="col-sm-8 form-group" v-if="this.usertype!='非民用'">
            <label class="font_normal_body" for="f_taxpayer_id">纳税人识别号</label>
            <input class="input_search" placeholder="纳税人识别号" style="width:70%" type="text"
                   v-model="baseinfo.base.f_taxpayer_id" v-next-el="addressphone"
                   :disabled="!jurisdiction.includes('发票信息修改')">
          </div>

          <div class="col-sm-4 form-group" v-if="this.usertype==='非民用'" :class="[$v.f_paper_name.required ? 'has-error' : '']">
            <label class="font_normal_body" for="f_paper_name">名&emsp;&emsp;称</label>
            <input class="input_search" placeholder="名称" style="width:60%" type="text" v-el:papername
                   v-model="baseinfo.base.f_paper_name" v-next-el="paperaccount" v-validate:f_paper_name='{required: true }'
                   :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
          <div class="col-sm-4 form-group" v-if="this.usertype!='非民用'" >
            <label class="font_normal_body" for="f_paper_name">名&emsp;&emsp;称</label>
            <input class="input_search" placeholder="名称" style="width:60%" type="text" v-el:papername
                   v-model="baseinfo.base.f_paper_name" v-next-el="paperaccount"
                   :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8 form-group" v-if="this.usertype==='非民用'" :class="[$v.f_address_phone.minlength || $v.f_address_phone.maxlength ? 'has-error' : '']">
            <label class="font_normal_body" for="f_address_phone">地址电话&emsp;&emsp;</label>
            <input class="input_search" placeholder="地址-电话" style="width:70%" type="text" v-el:addressphone
                   v-model="baseinfo.base.f_address_phone" v-next-el="papername" v-validate:f_address_phone='{minlength: 11, maxlength: 11 }'
                   :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
          <div class="col-sm-8 form-group" v-if="this.usertype!='非民用'" >
            <label class="font_normal_body" for="f_address_phone">地址电话&emsp;&emsp;</label>
            <input class="input_search" placeholder="地址-电话" style="width:70%" type="text" v-el:addressphone
                   v-model="baseinfo.base.f_address_phone" v-next-el="papername"
                   :disabled="!jurisdiction.includes('发票信息修改')">
          </div>

          <div class="col-sm-4 form-group" :class="[$v.pty.required ? 'has-error' : '']" v-if="this.usertype==='非民用'">
            <label class="font_normal_body" for="f_paper_type">*票据类型</label>
            <input type="text" class="input_search" style="width:60%" v-show="false" v-model="$refs.pty.selectedItems"
                   v-validate:pty='{required: true }' >
            <v-select :options='papertype'
                      :value-single="true"
                      :value.sync="baseinfo.base.f_paper_type" close-on-select
                      placeholder='票据类型'
                      :disabled="!jurisdiction.includes('发票信息修改')"
                      v-ref:pty></v-select>
          </div>
          <div class="col-sm-4 form-group"  v-if="this.usertype!='非民用'">
            <label class="font_normal_body" for="f_paper_type">票据类型</label>
            <input type="text" class="input_search" style="width:60%" v-show="false" v-model="$refs.pty.selectedItems"
            >
            <v-select :options='papertype'
                      :value-single="true"
                      :value.sync="baseinfo.base.f_paper_type" close-on-select
                      placeholder='票据类型'
                      :disabled="!jurisdiction.includes('发票信息修改')"
                      v-ref:pty></v-select>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8 form-group" v-if="this.usertype==='非民用'" :class="[$v.f_paper_account.required ? 'has-error' : '']">
            <label class="font_normal_body " for="f_paper_account">开户行及账号</label>
            <input class="input_search" placeholder="银行名称" style="width:70%" type="text" v-el:paperaccount
                   v-model="baseinfo.base.f_paper_account" v-validate:f_paper_account='{required: true }' :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
          <div class="col-sm-8 form-group" v-if="this.usertype!='非民用'" >
            <label class="font_normal_body " for="f_paper_account">开户行及账号</label>
            <input class="input_search" placeholder="银行名称" style="width:70%" type="text" v-el:paperaccount
                   v-model="baseinfo.base.f_paper_account" :disabled="!jurisdiction.includes('发票信息修改')">
          </div>

          <div class="col-sm-4 form-group" v-if="this.usertype==='非民用'" :class="[$v.f_contact_user.required ? 'has-error' : '']">
            <label class="font_normal_body" for="f_contact_user">联系人名</label>
            <input class="input_search" placeholder="联系人姓名" style="width:60%" type="text" v-el:contactuser
                   v-model="baseinfo.base.f_contact_user" v-validate:f_contact_user='{required: true }' :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
          <div class="col-sm-4 form-group" v-if="this.usertype!='非民用'" >
            <label class="font_normal_body" for="f_contact_user">联系人名</label>
            <input class="input_search" placeholder="联系人姓名" style="width:60%" type="text" v-el:contactuser
                   v-model="baseinfo.base.f_contact_user" :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
        </div>
        <div class="row">
          <div class="col-sm-8 form-group" v-if="this.usertype==='非民用'" :class="[$v.f_email.required ? 'has-error' : '']">
            <label class="font_normal_body " for="f_paper_account">推送票据邮箱</label>
            <input class="input_search" placeholder="推送票据邮箱" style="width:70%" type="text" v-el:f_email
                   v-model="baseinfo.base.f_email" v-validate:f_email='{required: true }' :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
          <div class="col-sm-8 form-group" v-if="this.usertype!='非民用'">
            <label class="font_normal_body " for="f_paper_account">推送票据邮箱</label>
            <input class="input_search" placeholder="推送票据邮箱" style="width:70%" type="text" v-el:f_email
                   v-model="baseinfo.base.f_email" :disabled="!jurisdiction.includes('发票信息修改')">
          </div>
        </div>

      </form>
    </validator>
  </div>
</template>
<script>
export default {
  title: '基本信息',
  data () {
    return {
      jurisdiction: this.$login.r,
      papertype: this.$appdata.getParam('票据类型') ? [{label: '请选择', value: ''}, ...this.$appdata.getParam('票据类型')] : []
    }
  },
  props: ['baseinfo','usertype'],
  methods : {
    // 控制用气性质，气价类型，气价名称修改
    permissionPrice () {
      let res = false

      console.log('获取权限、', this.row, this.jurisdiction)
      if (this.row.f_user_type[0] === '民用') {
        // 判断是否有民用气价权限
        res = !this.jurisdiction.includes('发票信息修改')
      } else if (this.row.f_user_type[0] === '非民用') {
        // 判断是否有非民用气价权限
        res = !this.jurisdiction.includes('发票信息修改')
      }

      console.log('有无发票信息修改权限', res)
      return res
    },
    onValid (res) {
      this.$dispatch('valid')
    },
    onInvalid (res) {
      this.$dispatch('invalid')
    }
  }
}
</script>
