<template>
  <div >
    <el-button size="mini" type="primary"  @click="onshow" >新增竞争项目</el-button>
    <el-dialog title="新 增" :visible.sync="dialogFormVisible" width="900px">
      <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="left" size="mini">
          <el-col :span="20">
            <el-form-item label="项目名称" prop="projectname">
              <el-input v-model="form.projectname" placeholder="请输入项目名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="项目地址" >
              <el-input v-model="form.address" placeholder="请输入项目地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="项目等级" >
              <el-select v-model="form.grade" placeholder="请选择" style="width: 100%">
                <el-option
                    v-for="item in gradeList"
                    :key="item.value"
                    :label="item.value"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="项目类型" >
              <el-select v-model="form.projecttype" placeholder="请选择" style="width: 100%">
                <el-option
                    v-for="item in typeList"
                    :key="item.value"
                    :label="item.value"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="项目联系人" >
              <el-input v-model="form.name" placeholder="请输入项目联系人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="联系人手机号" >
              <el-input v-model="form.phonenumber" placeholder="请输入联系人手机号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="是否主要威胁" >
              <el-radio v-model="form.important" label="1">是</el-radio>
              <el-radio v-model="form.important" label="0">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="优势信息" >
              <el-input type="textarea" autosize v-model="form.advantage" placeholder="请输入优势信息"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="劣势信息" >
              <el-input type="textarea" autosize v-model="form.inferiority" placeholder="请输入劣势信息"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="备注" >
              <el-input type="textarea" autosize 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",
  props:["data"],
  data(){
    return {
      dialogFormVisible:false,
      form:{
        sa_project_competeid: 0,
        sa_projectid: 0, //工程项目表ID
        contactsid: 0, //
        sa_competitorid: "", //竞争对手ID
        important: 0, //主要威胁 0/1
        advantage: "",
        inferiority: "" ,
        sys_enterpriseid:"",
        projectname:"",
        address:"",
        projecttype:"",
        grade:"",
        name:"",
        phonenumber:"",
        remarks:""
      },
      gradeList:[],
      typeList:[],
      rules:{
        projectname: [
          { required: true, message: '项目名称不能为空', trigger: 'blur' },
        ],
      }
    }
  },
  methods:{
    onshow(){
      console.log(this.data)
      this.querygrade()
      this.queryType()
      this.dialogFormVisible = true
    },
    onSubmit(){
      this.form.sa_competitorid = this.data.sa_competitorid
      this.form.sys_enterpriseid = this.data.sys_enterpriseid
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221019165802,
          "content": this.form,
        })
        this.tool.showMessage(res,()=>{
          this.$emit('insertSuccess')
          this.dialogFormVisible = false
          this.$refs['form'].resetFields()
        })
      })
    },
    /*项目等级*/
    async querygrade(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "projectgrade",
          "parameter": {
            "siteid": "YOSTEST2"
          }
        }
      })
      console.log(res)
      this.gradeList = res.data
    },
    /*项目类型*/
    async queryType(){
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "projecttype",
          "parameter": {
            "siteid": "YOSTEST2"
          }
        }
      })
      console.log(res)
      this.typeList = res.data
    }
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>