<template>
  <div>
    <el-button type="text" size="mini" @click="onShow(drawer = true)">编 辑</el-button>
    <el-drawer
      title="编辑"
      :visible.sync="drawer"
      direction="rtl"
      append-to-body
      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="address">
            <el-input v-model="form.address" 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="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>
<!--            <el-button icon="el-icon-place" type="text" @click="onSubmit(form.isdefault = 1)">设置为默认</el-button>-->
            <el-checkbox v-model="form.isdefault">是否默认</el-checkbox>
          </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,
      },
      rules:{
        enterprisename: [
          { required: true, message: '请输入抬头', trigger: 'blur' },
        ],
        address: [
          { 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
        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()
        })
      });
    },
    onShow () {
      this.form = Object.assign({},this.form,this.data)
      if (this.form.isdefault === 1){
        this.form.isdefault = true
      }else {
        this.form.isdefault = false
      }
    }
  }
}

</script>
<style>
</style>