<template>

  <div>
    <el-card class="box-card noborder">
      <div class="cardtitles">相关企业</div>
      <div class="searchbtns">
        <el-select class="select"  placeholder="企业类型" v-model="searchParam.companyType" @change="handleCurrentChange(1)">
          <el-option v-for="(item,index) in companytype" :label="item.dictLabel" :value="item.dictValue"></el-option>
        </el-select>
        <div class="searchInput">
          <el-input type="text" placeholder="输入关键词查询" v-model="searchParam.companyName"></el-input>
          <div class="btn" @click="handleCurrentChange(1)">搜索</div>
        </div>
        <div class="btn btn_primary h32 b3" @click="opennew"><div class="img img1"></div>添加相关企业</div>
      </div>
      <div class="document tables">
        <el-table
          :data="tableData.rows"
          style="width: 100%"
        >
          <template slot="empty">
            <div class="empty">
              <img src="@/assets/images/project/empty.png">
              <div class="p1">暂无数据展示</div>
              <div class="p2">抱歉，你还未添加相关数据，快去添加吧</div>
              <div class="btn btn_primary h36 w102" @click="opennew">新增联系人</div>
            </div>
          </template>
          <el-table-column
            prop="companyName"
            label="企业名称"
            >
            <template slot-scope="scope">
              <div class="wordprimary">{{scope.row.companyName}}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="depth"
            label="对接深度/竞争力度"
            >
          </el-table-column>
          <el-table-column
            prop="companyRole"
            label="企业角色"
            sortable
            width="">
          </el-table-column>
          <el-table-column
            prop="responsiblePerson"
            label="负责人"
            width="">
          </el-table-column>
          <el-table-column
            prop="name"
            label=""
            align="right"
            width="">
            <template slot-scope="scope">
              <div class="hoverbtn">
                <div class="sc" @click="ondel = scope.row.id">删除</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
          <div class="delform" v-if="ondel != -1">
            <div class="words">是否将企业删除</div>
            <div>
              <div class="btnsmall btn_primary h28" @click="delQY()">确定</div>
              <div class="btnsmall btn_cancel h28" @click="ondel = -1">取消</div>
            </div>
          </div>
        <div class="tables" v-if="tableData.total > searchParam.pageSize">
        <div class="bottems" v-if="ondel != -1">
          <el-pagination
            background
            :page-size="searchParam.pageSize"
            :current-page="searchParam.pageNum"
            @current-change="handleCurrentChange"
            layout="prev, pager, next"
            :total="tableData.total">
          </el-pagination>
        </div>
        </div>
      </div>
      <el-dialog
        class="popups"
        :visible.sync="dialogVisible"
        width="464px">
        <div class="poptitle">
          <img src="@/assets/images/economies/icon.png">
          <span>新建相关企业</span>
        </div>
        <div class="types">
          <div v-for="(item,index) in companytype" :class="{'on':types==item.dictValue}" @click="totype(item.dictValue)"><i></i>{{item.dictLabel}}</div>
        </div>
        <div class="popform">
          <div class="popbot" style="padding-right: 0">
            <div class="btn btn_cancel h32" @click="cancel(0)">返回</div>
            <div class="btn btn_primary h32" @click="gettype">下一步</div>
          </div>
        </div>
      </el-dialog>
      <el-dialog
        class="popups"
        :visible.sync="hzhbVisible"
        width="464px">
        <div class="poptitle">
          <img src="@/assets/images/economies/icon.png">
          <span>新建相关企业-{{types}}</span>
        </div>
        <el-form class="popform i" label-width="85px" :rules="rules" ref="ruleForm" >
          <el-form-item label="企业名称：" prop="companyName" class="row">
            <el-input type="text" v-model="queryParam.companyName" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item :label="typename" class="row">
            <el-input type="text" v-model="queryParam.depth" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item  label="企业角色：" class="row">
            <el-select  placeholder="请选择" v-model="queryParam.companyRole">
              <el-option v-for="(item,index) in companyrole" :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" v-model="queryParam.responsiblePerson" placeholder="请输入"></el-input>
          </el-form-item>
          <div class="popbot">
            <div class="btn btn_cancel h32" @click="cancel(1)">返回</div>
            <div class="btn btn_primary h32" @click="addqy">添加</div>
          </div>
        </el-form>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
  import "@/assets/styles/project.scss"
  import {getXGQY,addXGQY,delXGQY} from '@/api/project/project'
  import {getDictType} from '@/api/main'
  export default {
    name: 'xgqy',
    props: {
      detailId: { //从企业详情跳转过来ID
        type: Number,
        default: 0
      }
    },
    data(){
      return{
        types:1,
        dialogVisible:false,
        hzhbVisible:false,
        textarea:"",
        nowedit:-1,//当前正在编辑的文本
        tipslit:[],//项目标签
        tipsvalue:"",//标签填写内容
        tableData: [
          {
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1516 弄'
          }
        ],
        typelist:['对接深度：','合作阶段：','竞争力度：'],
        typename:"",
        rules:{
          companyName:[{ required: true, message: '请输入非空格字符！', trigger: 'blur' },],
        },
        companytype:[],
        companyrole:[],
        queryParam:{
          businessId:this.detailId ? this.detailId : this.$route.query.id,
          companyId:'',
          companyName:'',
          companyRole:'',
          companyType:'',
          responsiblePerson:'',
          depth:'',
        },
        searchParam:{
          pageSize:20,
          pageNum:1,
          businessId:this.detailId ? this.detailId : this.$route.query.id,
          companyType:"",
          companyName:'',
        },
        ondel:-1,
      }
    },
    created(){
      //企业类型
      getDictType('company_type').then(result=>{
        this.companytype = result.code == 200 ? result.data:[]
        this.types =  this.companytype[0].dictValue
      })
      //企业角色
      getDictType('company_role').then(result=>{
        this.companyrole = result.code == 200 ? result.data:[]
      })
      this.getlist()
    },
    methods:{
      delQY(){
        let id = this.ondel
        delXGQY(id).then(res=>{
          if(res.code == 200){
            this.$message.success('删除成功')
            this.ondel = -1
            this.handleCurrentChange(1)
          }
        })
      },
      addqy(){
        addXGQY(this.queryParam).then(res=>{
          if(res.code == 200){
            this.$message.success('添加成功！')
            this.getlist()
          }else {
            this.$message.error(res.msg)
          }
        })
      },
      getlist(){
        getXGQY(this.searchParam).then(result=>{
          console.log(result)
          this.tableData = result
        })
      },
      //翻页
      handleCurrentChange(val) {
        this.searchParam.pageNum = val
        this.getlist()
      },
      cancel(type){
        if(type == 0)
          this.dialogVisible = false
        else
          this.hzhbVisible =  false
      },
      totype(value){
        this.types = value
      },
      gettype(){
        this.queryParam.companyType = this.types
        this.companytype.forEach((item,index)=>{
          if(item.dictValue == this.types){
            this.typename = this.typelist[index]
          }
        })
        this.hzhbVisible=true
      },
      //打开新建窗口
      opennew(){
        this.dialogVisible = true
        this.queryParam={
          businessId:this.detailId ? this.detailId : this.$route.query.id,
          companyId:'',
          companyName:'',
          companyRole:'',
          companyType:'',
          responsiblePerson:'',
          depth:'',
        }
      },
    }
  }
</script>

<style lang="scss" scoped>
  .w102{
    width: 102px;
  }

  .img.img1{
    margin-right: 4px;
    background: url('../../../../../src/assets/images/project/add_2.png')no-repeat center center;
  }
  .img.img2{
    margin-right: 4px;
    background: url('../../../../../src/assets/images/upload.png')no-repeat center center;
  }
  .box-card{
    position: relative;
  }

  .delform{
    position: fixed; left:50%; top:50%; transform:translate(-50%,-50%)
  }
</style>
