<template>
  <div>
    <el-button type="primary" size="small" @click="drawer = true">新 建</el-button>
    <el-drawer
      title="新建"
      :visible.sync="drawer"
      direction="rtl"
      append-to-body
      :show-close="false"
      size="700px">
      <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="开户银行" >
            <el-input v-model="form.bank" placeholder="统一社会信用代码"></el-input>
          </el-form-item>
          <el-form-item label="开户账号" >
            <el-input v-model="form.bankcardno" placeholder="开户账号"></el-input>
          </el-form-item>
          <el-form-item label="开票地址" >
            <el-input v-model="form.address" placeholder="开票地址"></el-input>
          </el-form-item>
          <el-form-item label="电话" >
            <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" 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'],
  data () {
    return {
      drawer:false,
      form:{
        "sys_enterprise_financeid": 0,
        "sys_enterpriseid": 0,
        "enterprisename": "",
        "taxno": "",
        "bank": "",
        "bankcardno": "",
        "address": "",
        "phonenumber": "",
        "remarks": "",
        "isdefault": '1',
        "ownerid": this.$route.query.id,
        "ownertable": "sa_customers"

      },
      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:{
    onSubmit () {
      this.$refs['form'].validate(async (valid) => {
        if (! valid) return false
        this.form.sys_enterpriseid = this.data.sys_enterpriseid
        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() {
    this.form.enterprisename = this.data.enterprisename
  }
}

</script>
<style>
</style>