<!-- 联系 -->
<template>
  <div class="context">
    <!-- <div style="text-align: right;margin-bottom: 20px;">
      <el-button type="primary" @click="newconnection = !newconnection">
        新增联系人
      </el-button> 
    </div> -->
    <div>
      <el-table
        :data="tableData"
        border
        size='small'
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
        style="width: 100%;">
        <el-table-column
        type="index"
        label="序号"
        width="50">
        </el-table-column>
        <el-table-column
        prop="name"
        label="联系人名称"
        width="">
        </el-table-column>
        <el-table-column
        prop="lianxi"
        label="联系方式"
        width="">
        </el-table-column>
        <el-table-column
        prop="zhiwu"
        label="职务"
        width="">
        </el-table-column>
        <el-table-column
        prop="juece"
        label="是否决策人"
        width="">
        </el-table-column>
        <el-table-column
        prop="beizhu"
        label="备注"
        width="">
        </el-table-column>
        <el-table-column
        prop="address"
        label="操作"
        width="">
        <template slot-scope="scope">
          <el-button type="primary" @click="cahkan_click(scope.row)">查看</el-button>
          <!-- <el-button type="danger">修改</el-button> -->
        </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 弹窗 -->
    <div>
      <!-- 新增 -->
      <el-dialog
        title="新增联系人"
        :visible.sync="newconnection"
        :modal-append-to-body="false"
        width="60%"
        >
        <div style="height: 50vh;overflow: overlay;">
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>客户名称：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>联系人姓名：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>联系人手机：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
                <span>其他联系方式：</span>
                <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
              </div>
          </div>

          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>联系人职务：</span>
                <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>是否决策人：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span style="position: relative;bottom: 20px;left: 0;">
                  备注：
              </span>
              <el-input type="textarea" :row="2" v-model="textarea" placeholder="请输入内容" style="width: 80%;"></el-input>
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="newconnection = false">取 消</el-button>
          <el-button type="primary" @click="newconnection = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 查看 -->
      <el-dialog
        title="编辑联系人"
        :visible.sync="connection"
        :modal-append-to-body="false"
        width="60%"
        >
        <div style="height: 50vh;overflow: overlay;">
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>客户名称：</span>
              <el-input v-model="viewobj.name" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>联系人姓名：</span>
              <el-input v-model="viewobj.contact_name" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>联系人手机：</span>
              <el-input v-model="viewobj.contact_phone" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
                <span>其他联系方式：</span>
                <el-input v-model="viewobj.contact_way" placeholder="请输入内容" style="width: 60%;"></el-input>
              </div>
          </div>

          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>联系人职务：</span>
                <el-input v-model="viewobj.contact_duties" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>是否决策人：</span>
              <el-select v-model="viewobj.is_decision" placeholder="请选择" style="width: 60%;">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span style="position: relative;bottom: 20px;left: 0;">
                  备注：
              </span>
              <el-input type="textarea" :row="2" v-model="viewobj.remark" placeholder="请输入内容" style="width: 80%;"></el-input>
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="connection = false">取 消</el-button>
          <el-button type="primary" @click="examine_click">审 核</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import{getcontactlist,getcontactget,getcontactcheck} from '../../../api/index'
  export default{
    props:{
      Message:Object
    },
    data(){
      return{
        textarea:'',
        input:'',
        tableData: [],
        newconnection:false,
        connection:false,
        examine_id:'',
        options:[{value:1,label:'是'},{value:2,label:'否'}],
        viewobj:{
          name:'',
          custom_id:'',
          contact_name:'',
          contact_phone:'',
          contact_duties:'',
          is_decision:'',
          remark:'',
          contact_way:''
        },
      }
    },
    created(){
      this.getlist()
    },
    methods:{
      cahkan_click(row){
        this.examine_id = row.id
        this.connection = true
        getcontactget(row.id).then(res =>{
          const contact = res.data.contact_info
          this.viewobj = {
            name:this.Message.name,
            custom_id:contact.id,
            contact_name:contact.contact_name,
            contact_phone:contact.contact_phone,
            contact_duties:contact.contact_duties,
            is_decision:contact.is_decision*1,
            remark:contact.remark,
            contact_way:contact.contact_way
          }
        })
      },
      // 表格数据
      getlist(){
        getcontactlist().then(res =>{
          const list =res.data.list
          const table = []
          list.forEach((item,index) => {
            if(item.is_check==0){
              const arr = {
                index:index+1,
                id:item.id,
                name:item.contact_name,
                lianxi:item.contact_phone,
                zhiwu:item.contact_duties,
                juece:this.getoptions(item.is_decision),
                beizhu:item.remark
              }
              table.unshift(arr)
            }
          });
          this.tableData = table
        })
      },
      // 是否在职
      getoptions(val){
        const options = this.options
        for(let i in options){
          if(options[i].value == val){
            return options[i].label
          }
        }
      },
      examine_click(){
        getcontactcheck(this.examine_id).then(res =>{
          console.log('444444445555',res);
          this.connection = false
        })
      },
    }
  }
</script>
<style lang="scss" scoped>
  .context{
    padding: 20px 0;
    .xinxi{
      display: flex;
      margin-bottom: 15px;
    }
  }

</style>