<template>
  <el-dialog
    class="popups"
    width="534px"
    :visible.sync="dialogVisible"
    @close="resetForm('ruleForm')"
  >
    <div class="poptitle">
      <img src="@/assets/images/economies/icon.png">
      <span>添加客户</span>
    </div>
    <el-form class="popform j" :model="queryParam" :rules="rules" ref="ruleForm" label-width="130px">
      <el-form-item label="项目名称：" class="row"  prop="name">
        <el-input type="text" placeholder="请输入" v-model="queryParam.projectName" @input="getCompany"></el-input>
      </el-form-item>
      <el-form-item label="业主单位：" class="row"  prop="company">
        <el-input type="text" placeholder="请输入" v-model="queryParam.ownerCompany" @input="getCompany"></el-input>
        <div class="resultlist" v-if="showlist">
          <div v-for="(item,index) in companData" @click="selCompany(item)"><span  v-html="item.name"></span></div>
        </div>
      </el-form-item>
      <el-form-item label="项目阶段：" class="row">
        <el-select  placeholder="请选择" v-model="queryParam.projectStage">
          <el-option v-for="(item,index) in customerLevel" :key="index" :label="item.dictLabel" :value="item.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目类型：" class="row">
        <el-select  placeholder="请选择" v-model="queryParam.projectType">
          <el-option v-for="(item,index) in customerLevel" :key="index" :label="item.dictLabel" :value="item.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目类别：" class="row">
        <el-select  placeholder="请选择" v-model="queryParam.projectCategory">
          <el-option v-for="(item,index) in customerLevel" :key="index" :label="item.dictLabel" :value="item.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="投资估算：" class="row">
        <el-input type="text" placeholder="请输入" v-model="queryParam.investmentAmount"></el-input>
      </el-form-item>
      <el-form-item label="可见范围：" class="row">
        <el-select  placeholder="请选择" v-model="queryParam.isPrivate">
          <el-option v-for="(item,index) in Privatelist" :key="index" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <div class="popbot">
        <div class="wordprimary">前往商机雷达寻找项目线索></div>
        <div class="btn btn_cancel h32" @click="resetForm('ruleForm')">返回</div>
        <div class="btn btn_primary h32" @click="submitForm('ruleForm')">新建商机</div>
      </div>
    </el-form>
  </el-dialog>
</template>

<script>
  export default {
    name: 'addProject',
    data(){
      return{
        Privatelist:[
          {
          value:0,
          label:'仅自己可见'
        },{
          value:1,
            label:'他人可见'
          }
        ],//可见范围
        dialogVisible:true,
        queryParam:{
          companyId:'',//jsk企业id
          companyName:'',//客户名称（企业名称
          customerLevel:'',//客户等级
          legalPerson:'',//法定代表人
          registerCapital:'',//注册资本
          registerAddress:'',//企业注册地址
          creditCode:'',//社会统一信用代码
          address:'',//选择的地址
          provinceId:'',
          cityId:'',
          districtId:'',
        },
        xmjd:[],//项目阶段
        queryParam:{
          userId:this.$store.state.user,//用户id
          projectName:'',//	项目名称
          companyId:'',//企业id
          ownerCompany:'',//业主单位
          projectStage:'',//项目阶段
          projectType:'',//项目类型
          projectCategory:'',//项目类别
          investmentAmount:'',//投资估算
          isPrivate:0,//可见范围(0 仅自己可见，1 他人可见)
        },
      }
    },
    mounted(){

    },
    created(){
      //项目阶段
      // project_stage_type
    },
    methods:{

      //添加客户
      submitForm(formName) {
        if(this.queryParam.companyId=="" || this.queryParam.companyId == null){
          this.$message.error({message:'请选择企业！',showClose:true})

          return;
        }
        this.$refs[formName].validate((valid) => {
          if (valid) {
            addCustomer(this.queryParam).then(result=>{
              if(result.code == 200){
                this.$message.success('添加成功！')
                this.dialogVisible = false
                this.handleCurrentChange(1)
                this.resetForm('ruleForm')
              }else{
                this.$message.error(result.msg)
              }
            })
          } else {
          }
        });
      },
      resetForm(formName) {
        this.queryParam = {
          companyId:'',//jsk企业id
          companyName:'',//客户名称（企业名称
          customerLevel:'',//客户等级
          legalPerson:'',//法定代表人
          registerCapital:'',//注册资本
          registerAddress:'',//企业注册地址
          creditCode:'',//社会统一信用代码
          address:'',//选择的地址
          provinceId:'',
          cityId:'',
          districtId:'',
        },
          this.dialogVisible = false
        this.showlist = false
      },
    }
  }
</script>

<style scoped>

</style>
