<template>
  <div>
    <el-button size="mini" @click="btn" style="width:100%">报 备</el-button>
    <el-dialog title="选择报备人" append-to-body :visible.sync="dialogFormVisible" width="30%">
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="left" size="mini">
          <el-col :span="20">
            <el-form-item label="选择报备人" prop="reportby">
              <el-select v-model="form.reportby" placeholder="请选择报备人" size="small">
                <el-option
                  v-for="item in data"
                  :key="item.userid"
                  :label="item.name"
                  :value="item.name">
                </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",
  props:['data','rowData'],
  data(){
    return {
      dialogFormVisible:false,
      form:{
        reportby:'',
        sa_projectid:''
      },
      rules:{
        reportby:[
          { required: true, message: '请选择负责人', trigger: 'blur'},
        ],
      }
    }
  },
  methods:{
    btn () {
      this.dialogFormVisible = true
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        this.form.sa_projectid = this.rowData.sa_projectid
        const res = await this.$api.requested({
          "id": "20221021092302",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    }
  }
}
</script>

<style scoped>
/deep/.el-select {
  width: 100%;
}
</style>