<template>
  <div>
    <el-button size="mini" v-show="visible"  @click="editBtn">编 辑</el-button>
    <el-drawer
        title="新增模板"
        :visible.sync="dialogFormVisible"
        size="800px"
        direction="rtl"
        append-to-body
        @close="dialogFormVisible = false">
      <div class="drawer__panel">
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules" ref="form" label-width="110px" label-position="right" size="mini">
            <el-col :span="24">
              <el-form-item label="项目模板名称" prop="stagetempname">
                <el-input v-model="form.stagetempname" placeholder="项目模板名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="项目类型" prop="projecttype">
                <el-input v-model="form.projecttype" placeholder="项目类型"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remarks">
                <el-input type="textarea" v-model="form.remarks" placeholder="请输入备注"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item>
                <div style="display:flex">
                  <el-checkbox :true-label="1" :false-label="0" v-model="form.isused" checked="checked">启用</el-checkbox>
                  <el-checkbox :true-label="1" :false-label="0" v-model="form.locked">锁定</el-checkbox>
                </div>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="dialogFormVisible = 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 {
  name: "add",
  props:['data'],
  data(){
    return {
      dialogFormVisible:false,
      visible:true,
      form:{
        "sa_projstagetempid": 0,
        "stagetempname":"",
        "remarks":"",
        "projecttype":"",
        "isused":1,
        "locked":0
      },
      rules:{
        stagetempname:[
          { required: true, message: '请输入模板名称', trigger: 'blur'},
        ],
        projecttype:[
          { required: true, message: '请输入项目类型', trigger: 'blur'}
        ]
      }
    }
  },
  methods:{
    editBtn () {
      console.log("页面进行编辑")
     /*/!* this.dialogFormVisible = true*!/
      this.visible = false*/
      console.log(this.visible)
      this.form = Object.assign({},this.form,this.data)
    },
    onSubmit(){
      console.log(this.form)
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": "20221019085704",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    }
  }
}
</script>

<style scoped>

</style>