<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="24">
            <el-form-item label="账户编号" prop="accountno">
              <el-input v-model="form.accountno" placeholder="账户编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="账户名称" prop="accountname">
              <el-input v-model="form.accountname" placeholder="账户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-checkbox :true-label="1" :false-label="0" v-model="form.isrebate">是否返利账户</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item  >
              <el-checkbox :true-label="1" :false-label="0" v-model="form.isorder" checked="checked">允许订货</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item  >
              <el-checkbox :true-label="1" :false-label="0" v-model="form.isused" checked="checked">是否启用</el-checkbox>
            </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",
  data(){
    return {
      dialogFormVisible:false,
      isordercheck:true,
      isusedcheck:false,
      form:{
        sa_accountclassid:0,
        accountno:'',
        accountname:'',
        isorder:'',
        isused:0,
        isrebate:0
      },
      rules:{
        accountno:[
          { required: true, message: '输入账户编号', trigger: 'blur'},
        ],
        accountname:[
          { required: true, message: '输入账户名称', trigger: 'blur'}
        ]
      }
    }
  },
  methods:{
    onSubmit(){
      console.log(this.form)
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": "20221008134703",
          "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>