<template>
  <div>
    <el-button size="mini"  type="primary" @click="dialogTableVisible = true" :disabled="disabled">添加项目</el-button>
    <el-dialog
        title="添加项目"
        :visible.sync="dialogTableVisible"
        width="20%"
        append-to-body
        @close="onCancel"
    >
      <div class="panel_Target">
        <el-row style="margin-top: 3%">
          <el-col :span="4" :offset="1">
            <div style="width: 100%;text-align: right">
              <label class="normal-margin inline-16" style="margin-top: 8%">项目名称:</label>
            </div>
          </el-col>
          <el-col :span="18">
            <el-input v-model="form.projectname" size="small" placeholder="请选择项目" @focus="projectList"></el-input>
          </el-col>
        </el-row>
      </div>
      <div class="dialog-footer ">
        <el-button size="small" @click="onCancel" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary"  @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-dialog>
    <project :visible="visible" v-if="visible" @onProject="onProject"></project>
  </div>
</template>

<script>
import project from '../../components/projectAdd/project'
export default {
  name: "index",
  components:{project},
  props:["id","year","disabled"],
  data(){
    return {
      dialogTableVisible:false,
      visible:false,
      form:{
        projectname:'',
        sa_projectid:''
      }
    }
  },
  methods:{
    onCancel(){

    },
    async onSubmit(){
      const res = await this.$api.requested({
        "id": 20220905154102,
        "content": {
          "year": this.year,
          "hrid": this.id,
          /*"sa_salestargetbillid":2,//可不传*/
          "project": [
            {
              "sa_projectid": this.form.sa_projectid,
            },
          ]
        },
      })
      this.tool.showMessage(res,()=>{
        this.dialogTableVisible = false
        this.$emit("onSuccess")
      })
    },
    projectList(){
      this.visible = 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)
    },
  }
}
</script>

<style scoped>
.el-pagination {
  text-align: right;
}
.panel_Target {
  border-top:1px solid #eeeeee;
  padding:5px 5px;
  margin-bottom:0px
}
</style>