<template>
  <div>
    <el-button type="primary" size="small" @click="onShow">新 建</el-button>
    <el-drawer
        title="新建"
        :visible.sync="drawer"
        direction="rtl"
        append-to-body
        :show-close="false"
        size="700px"
        @close="drawer = false;$refs['form'].resetFields()">
      <div class="drawer__panel">
        <el-form :model="form" ref="form" :rules="rules" :status-icon="false"	 size="mini" label-position="right" label-width="100px" class="demo-form-inline">
          <el-form-item label="开票抬头" prop="enterprisename">
            <el-input v-model="form.enterprisename" placeholder="请填写开票抬头"></el-input>
          </el-form-item>
          <el-form-item label="税号" prop="taxno">
            <el-input v-model="form.taxno" placeholder="请填写税号"></el-input>
          </el-form-item>
          <el-form-item label="开户银行" prop="bank">
            <el-input v-model="form.bank" placeholder="请填写开户银行"></el-input>
          </el-form-item>
          <el-form-item label="开户账号" prop="bankcardno">
            <el-input v-model="form.bankcardno" placeholder="请填写开户账号"></el-input>
          </el-form-item>
          <el-form-item label="开票地址" prop="address">
            <el-input v-model="form.address" placeholder="请填写开票地址"></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="phonenumber">
            <el-input v-model="form.phonenumber" placeholder="请填写手机号（电话）"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input v-model="form.remarks" placeholder="请填写备注"></el-input>
          </el-form-item>
          <el-form-item label="是否默认" prop="remarks">
            <el-radio v-model="form.isdefault" label="1">是</el-radio>
            <el-radio v-model="form.isdefault" label="0">否</el-radio>
          </el-form-item>
          <!--          <el-form-item>
                      <el-button icon="el-icon-place" type="text">设置为默认地址</el-button>
                    </el-form-item>-->
        </el-form>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="drawer = false;$refs['form'].resetFields()" 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>
export default {
  props:['data'],
  name: "add",
  data () {
    return {
      drawer:false,
      form:{
        "sys_enterprise_financeid": 0,
        "sys_enterpriseid": 0,
        "enterprisename": "",
        "taxno": "",
        "bank": "",
        "bankcardno": "",
        "address": "",
        "phonenumber": "",
        "remarks": "",
        "isdefault": '1',
      },
      rules:{
        enterprisename: [
          { required: true, message: '请输入抬头', trigger: 'blur' },
        ],
        /*address: [
          { required: true, message: '请输入开票地址', trigger: 'blur' },
        ],*/
        taxno: [
          { required: true, message: '请输入税号', trigger: 'blur' },
        ],
        /*bank: [
          { required: true, message: '请输入开户行', trigger: 'blur' },
        ],
        bankcardno: [
          { required: true, message: '请输入开户账号', trigger: 'blur' },
        ],
        phonenumber: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { pattern:/^1[3-9][0-9]\d{8}$/, message: '请输入正确手机号码',trigger: 'blur' }
        ],*/
      }
    }
  },
  methods:{
    onShow(){
      if (this.data.enterprisename === '' || this.data.abbreviation === '' || this.data.contact === ''){
        this.$message.error('请先将企业基础信息补充完整，再进行此操作');
      }else {
        this.drawer = true
      }
    },
    onSubmit () {
      console.log(this.form,"表单")
      this.$refs['form'].validate(async (valid) => {
        if (! valid) return false
        const res = await this.$api.requested({
          "id": 20221013160402,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.drawer = false
          this.$refs['form'].resetFields()
        })
      });

    }
  },
  mounted() {
    console.log(this.data,"财务")
    this.form.enterprisename = this.data.enterprisename
    this.form.sys_enterpriseid = this.data.sys_enterpriseid
    console.log(this.form)
  }
}
</script>

<style scoped>

</style>