<template>
  <div>
    <el-button size="mini" type="primary" @click="dialogFormVisible = true">新 增</el-button>
    <el-dialog title="新 建" append-to-body :visible.sync="dialogFormVisible" width="500px">
      <div slot="title" style="font-size: 15px">
        新增银行卡信息
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="90px" label-position="right" size="mini">
          <el-col :span="20">
            <el-form-item label="银行名称" prop="bank">
              <el-input v-model="form.bank" placeholder="银行名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="卡号" prop="bankcardno">
              <el-input v-model="form.bankcardno" placeholder="卡号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="开户人" prop="name">
              <el-input v-model="form.name" placeholder="开户人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="手机号码" prop="phonenumber">
              <el-input v-model="form.phonenumber" placeholder="手机号码"></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  props:["data"],
  data(){
    return {
      dialogFormVisible:false,
      form:{
        "sys_enterprise_bankid": 0,
        "bank": "",
        "bankcardno": "",
        "name": "",
        "phonenumber": "",
        "sys_enterpriseid":''
      },
      rules:{
        bank:[
          { required: true, message: '请输入银行名称', trigger: 'blur'},
        ],
        bankcardno:[
          { required: true, message: '请输入银行卡号', trigger: 'blur'}
        ],
        name:[
          { required: true, message: '请输入开户人', trigger: 'blur'}
        ],
        phonenumber:[
          { pattern:/^1[3-9][0-9]\d{8}$/, message: '请输入正确手机号码',trigger: 'blur' }
        ],
      }
    }
  },
  methods:{
    onSubmit(){
      console.log(this.form)
      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": "20221022165703",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    }
  }
}
</script>

<style scoped>
.dialog-footer {
  margin-top: 0;
}
</style>