<template>
  <div>
    <el-button size="mini" type="primary" @click="dialogFormVisible = true">新 建</el-button>
    <el-dialog title="新 建" append-to-body :visible.sync="dialogFormVisible" width="30%">
      <div slot="title" style="font-size: 15px">
        关联缔约企业
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="right" size="mini">
          <el-col :span="24">
            <el-form-item label="联系人" prop="contactsid">
              <el-select v-model="form.contactsid" placeholder="请选择关联的联系人" clearable @clear="form.sys_enterpriseid=''" size="small">
                <el-option
                  v-for="item in contactList()"
                  :key="item.contactsid"
                  :label="item.name"
                  :value="item.contactsid">
                </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-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",
  components:{},
  inject:['contactList','rowData'],
  data(){
    return {
      dialogFormVisible:false,
      projectAddress:[],
      form:{
        "sa_project_parties_contactsid": 0,
        "sa_project_partiesid": "",
        "contactsid": "",
        "remarks": ""
      },
      rules:{
        contactsid:[
          { required: true, message: '请选择企业', trigger: 'blur'},
        ]
      }
    }
  },
  created () {
  },
  methods:{
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        this.form.sa_project_partiesid = this.rowData().sa_project_partiesid
        const res = await this.$api.requested({
          "id": "20221027184702",
          "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 {
  height: 28px !important;
  width: 100%;
}
/deep/.el-input__inner {
  height: 28px !important;
}
</style>