<template>
  <div>
    <el-button size="mini" type="primary" @click="onShow">编 辑</el-button>
    <el-drawer
      title="编辑开票申请单"
      :visible.sync="drawer"
      direction="rtl"
      :show-close="false"
      append-to-body
      size="700px">
      <div class="drawer__panel">
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules" class="demo-form-inline" size="small" label-position="right" label-width="80px">
            <!-- <el-col :span="12">
              <p class="normal-title normal-margin">经销商信息</p>
              <el-form-item label="经销商">
                <el-popover
                  placement="bottom"
                  trigger="click"
                  v-model="visible">
                  <invoiceCanUseAgent ref="UseAgent" @selectRow="selectRow"></invoiceCanUseAgent>
                  <el-input readonly slot="reference" v-model="form.enterprisename" @focus="queryAgent" placeholder="经销商"></el-input>
                </el-popover>
              </el-form-item>
            </el-col> -->
            <el-col :span="24">
              <p class="normal-title normal-margin">财务信息</p>
            </el-col>
            <el-col :span="12">
              <el-form-item label="税号">
                <el-popover
                  placement="bottom"
                  trigger="click"
                  v-model="visible1">
                  <invoiceCanUseTax :sys_enterpriseid="sys_enterpriseid" ref="UseTax" @selectTaxRow="selectTaxRow">
                    <addInvoice slot="add" @onSuccess="$refs.UseTax.listData()" :data="{sys_enterpriseid:sys_enterpriseid}"></addInvoice>
                  </invoiceCanUseTax>
                  <el-input readonly slot="reference" v-model="form.taxno" @focus="queryTax" placeholder="税号"></el-input>
                </el-popover>
              </el-form-item>
              <el-form-item label="开票单位">
                <el-input readonly v-model="form.invo_enterprisename" placeholder="开票单位"></el-input>
              </el-form-item>
              <el-form-item label="开票地址">
                <el-input readonly v-model="form.address" placeholder="开票地址"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话">
                <el-input readonly v-model="form.phonenumber" placeholder="联系电话"></el-input>
              </el-form-item>
              <el-form-item label="开户行">
                <el-input readonly v-model="form.bank" placeholder="开户行"></el-input>
              </el-form-item>
              <el-form-item label="开户账号">
                <el-input readonly v-model="form.bankcardno" placeholder="开户账号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input v-model="form.remarks" type="textarea" :aotusize="{minRows:4}" placeholder="备注"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
               <p class="normal-title normal-margin">开票信息</p>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发票种类">
                <el-select style="width:100%" v-model="value" placeholder="请选择">
                  <el-option label="s/专用发票" value="s"></el-option>
                  <el-option label="p/普通发票(电票)" value="p"></el-option>
                </el-select>
              </el-form-item>
               <el-form-item label="发票限额">
                <el-input v-model="form.quota" placeholder="开户账号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="复核人">
                <el-input v-model="form.invoicechecker" placeholder="发票复核人"></el-input>
              </el-form-item>
              <el-form-item label="收款人">
                <el-input v-model="form.invoicepayee" placeholder="发票收款人"></el-input>
              </el-form-item>
              <el-form-item label="开票员">
                <el-input v-model="form.invoiceclerk" placeholder="发票开票员"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">保 存</el-button>
      </div>
    </el-drawer>

  </div>
</template>

<script>
// import invoiceCanUseAgent from '@/template/invoiceCanUseAgent/indexCopy1.vue'
import invoiceCanUseTax from '@/template/invoiceCanUseTax/index.vue'
import addInvoice from '@/components/financialInfo/modules/add'
export default {
  props:['data'],
  data () {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('年龄不能为空'));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error('请输入数字值'));
        } else {
          if (value < 18) {
            callback(new Error('必须年满18岁'));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    return {
      drawer:false,
      visible:false,
      visible1:false,
      form:{
        sa_invoiceapplyid:0,
        remarks:'',
        byhand:false,
      },
      value:'',
      sys_enterpriseid:JSON.parse(window.sessionStorage.getItem('accountinfo')).agenthr.sys_enterpriseid ? JSON.parse(window.sessionStorage.getItem('accountinfo')).agenthr.sys_enterpriseid : '',
      rules:{
        enterprisename: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
        ],
        taxno: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
      }
    }
  },
  components:{
    invoiceCanUseTax,
    addInvoice
  },
  methods:{
    onShow () {
      this.form = Object.assign({},this.form,this.data)
      this.drawer = true
    },
    async onSubmit () {
      const res = await this.$api.requested({
        "id": "20221216142903",
        "version":1,
        "content": this.form
      })
      this.tool.showMessage(res,()=>{
        this.$emit('onSuccess')
        this.drawer = false
        this.form = {
          sa_invoiceapplyid:0,
          remarks:'',
          byhand:false,
        }
      })
    },
    // 选择经销商
    selectRow (row) {
      this.visible = false
      this.form.enterprisename = row.enterprisename
      this.form.sys_enterpriseid = row.sys_enterpriseid
    },
    // 选择开票信息
    selectTaxRow (row) {
      this.visible1 = false
      this.form.sys_enterpriseid = 0
      this.form.invo_enterprisename = row.enterprisename
      this.form.taxno = row.taxno
      this.form.address = row.address
      this.form.phonenumber = row.phonenumber
      this.form.bank = row.bank
      this.form.bankcardno = row.bankcardno
    },
    // 查询经销商
    queryAgent () {
      this.$refs['UseAgent'].listData()
    },

    // 查询开票信息
    queryTax () {
      this.$refs['UseTax'].listData()
    }
  }
}

</script>
<style>
</style>