<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="name">
              <el-input v-model="form.name" placeholder="请输入模板名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="模板类型" prop="type">
              <el-select v-model="form.type">
                <el-option label="服务" value="服务"></el-option>
                <el-option label="安装调试" value="安装调试"></el-option>
                <el-option label="安装培训" value="安装培训"></el-option>
              </el-select>
            </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,
      form:{
        "sa_workorder_templateid":0,     //sa_brandid<=0时 为新增
        "name":"",
        "type":""
      },
      rules:{
        name:[
          { required: true, message: '请输入模板名称', trigger: 'blur'},
        ],
        type:[
          { 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": "20230207140403",
          "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;
}
.el-select {
  width: 100% !important;
}
</style>