<template>
  <div >
    <el-button size="small" type="primary"  @click="onshow" >新增竞争项目</el-button>
    <el-drawer
        title="关联项目商机"
        :visible.sync="drawer"
        size="40%"
        direction="rtl"
        append-to-body
        >
      <div class="drawer__panel">
        <el-row :gutter="20">
          <el-form :model="form" :rules="rules" ref="form" label-width="100px" label-position="right" size="mini">
            <el-col :span="12">
              <el-form-item label="项目名称" prop="projectname">
                <el-input v-model="form.projectname" placeholder="请选择项目" @focus="projectList"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目编号" >
                <el-input v-model="project.projectnum" placeholder="项目编号" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目地址" >
                <el-input v-model="project.address" placeholder="项目详细地址" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目等级" >
                <el-input v-model="project.grade" placeholder="项目等级" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目类型" >
                <el-input v-model="project.projecttype" placeholder="项目类型" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目规模" >
                <el-input v-model="project.scale" placeholder="项目规模" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目状态" >
                <el-input v-model="project.status" placeholder="项目状态" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目预算" >
                <el-input v-model="project.budgetary" placeholder="项目预算" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预计签约金额" >
                <el-input v-model="project.signamount_due" placeholder="预计签约金额" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预计签约时间" >
                <el-input v-model="project.signdate_due" placeholder="预计签约时间" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系人" prop="name">
                <el-input v-model="form.name" placeholder="请选择联系人" @focus="contactsList"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号" >
                <el-input v-model="contacts.phonenumber" placeholder="联系人手机号" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <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="12">
              <el-form-item label="优势信息" >
                <el-input type="textarea" autosize v-model="form.advantage" placeholder="请输入优势信息"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="劣势信息" >
                <el-input type="textarea" autosize v-model="form.inferiority" placeholder="请输入劣势信息"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <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>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
<!--    <el-dialog title="新 建" :visible.sync="dialogFormVisible" width="900px">
      <div slot="title" style="font-size: 15px">
        新增竞争项目
      </div>

      <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>-->
    <project :visible="visible" v-if="visible" @onProject="onProject"></project>
    <contact :visible="visibleContacts" v-if="visibleContacts" @onContact="onContact" :data="data"></contact>
  </div>
</template>

<script>
import project from '../components/project'
import contact from '../components/contacts'
export default {
  name: "add",
  props:["data"],
  components:{project,contact},
  data(){
    return {
      drawer:false,
      visible:false,
      visibleContacts:false,
      form:{
        sa_project_competeid: 0,
        sa_projectid: 0, //工程项目表ID
        contactsid: 0, //
        sa_competitorid: "", //竞争对手ID
        important: 0, //主要威胁 0/1
        advantage: "",
        inferiority: "" ,
        remarks:"",
        projectname:"",
        name:""
      },
      project:{},
      contacts:{},
      rules:{
        projectname: [
          { required: true, message: '项目名称不能为空', trigger: 'change' },
        ],
        name: [
          { required: true, message: '联系人不能为空', trigger: 'change' },
        ],
      }
    }
  },
  methods:{
    onshow(){
      console.log(this.data)
      this.drawer = true
    },
    onSubmit(){
      this.form.sa_competitorid = this.data.sa_competitorid
      console.log(this.form)
      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.drawer = false
          this.$refs['form'].resetFields()
        })
      })
    },
    projectList(){
      this.visible = true
    },
    contactsList(){
      console.log("------------------------")
      console.log(this.data)
      this.visibleContacts = true
    },
    onProject(data){
      this.visible = false
      console.log("获取")
      console.log(data)
      this.form.sa_projectid = data.sa_projectid
      this.form.projectname = data.projectname
      this.project = data
      console.log("项目详细信息")
      console.log(this.project)
    },
    onContact(data){
      this.visibleContacts = false
      this.form.name = data.name
      console.log(data)
      this.contacts = data
      this.form.contactsid = data.contactsid
    }
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>