<template>
  <div class="inline-16">
    <el-button size="small" type="text" @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="form.projectnum"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目地址" >
                <el-input v-model="form.address"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目等级" >
                <el-input v-model="form.grade"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目类型" >
                <el-input v-model="form.projecttype"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目规模" >
                <el-input v-model="form.scale"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目状态" >
                <el-input v-model="form.status"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目预算" >
                <el-input v-model="form.budgetary"  disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预计签约金额" >
                <el-input v-model="form.signamount_due" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预计签约时间" >
                <el-input v-model="form.signdate_due"  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="form.phonenumber"  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>
    <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: "edit",
  props:["data"],
  components:{project,contact},
  data(){
    return {
      drawer:false,
      visible:false,
      dialogFormVisible:false,
      visibleContacts:false,
      form:{},
      rules:{
        projectname: [
          { required: true, message: '项目名称不能为空', trigger: 'blur' },
        ],
        name: [
          { required: true, message: '联系人不能为空', trigger: 'change' },
        ],
      },
      project:{},
      contacts:{},
    }
  },
  methods:{
    onshow(){
      this.form = this.data
      console.log("输出表单数据")
      console.log(this.form)
      if (this.form.important === 0){
        this.form.important = '0'
      }else if (this.form.important === 1){
        this.form.important = '1'
      }
      this.drawer = true
    },
    onSubmit(){
      this.form.sa_competitorid = this.data.sa_competitorid
      if (this.form.important === "0"){
        this.form.important = 0
      }else if (this.form.important === "1"){
        this.form.important = 1
      }
      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
    }
  }
}
</script>

<style scoped>

</style>