<template>
  <div>
    <el-button size="mini" type="primary" @click="onShow(dialogFormVisible = true)">新 增</el-button>
    <el-dialog title="新 增" :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="110px" label-position="left" 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="项目类型">
              <el-select v-model="form.projecttype" style="width:100%">
                <el-option v-for="item in sys_options" :key="item.index" :value="item.value" :label="item.value"></el-option>
              </el-select>
            </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 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>
import {mapGetters} from 'vuex'
export default {
  name: "add",
  data(){
    return {
      dialogFormVisible:false,
      isordercheck:true,
      isusedcheck:false,
      form:{
        "sa_projstagetempid": 0,
        "stagetempname":"",
        "remarks":"",
        "projecttype":"",
        "isused":1,
        "locked":0
      },
      rules:{
        stagetempname:[
          { required: true, message: '请输入模板名称', trigger: 'blur'},
        ],
        projecttype:[
          { required: true, message: '请输入项目类型', trigger: 'blur'}
        ]
      }
    }
  },
  computed:{
    ...mapGetters({
      sys_options:'sys_options'
    })
  },
  methods:{
    onShow () {
      this.$store.dispatch('optiontypeselect','projecttype')
    },
    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>