<!-- 联系 -->
<template>
  <div class="context">
    <div style="text-align: right;margin-bottom: 20px;">
      <el-button type="primary" @click="newconnection = true">
        新增联系人
      </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" @click="open_dele(scope.row)">删除</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="Contact.name" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>联系人姓名：</span>
              <el-input v-model="Contact.contact_name" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>联系人手机：</span>
              <el-input v-model="Contact.contact_phone" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
                <span>其他联系方式：</span>
                <el-input v-model="Contact.contact_way" placeholder="请输入内容" style="width: 60%;"></el-input>
              </div>
          </div>

          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>联系人职务：</span>
                <el-input v-model="Contact.contact_duties" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>是否决策人：</span>
              <el-select v-model="Contact.is_decision" placeholder="请选择">
                <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="Contact.remark" 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="newclick">确 定</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="connection_click">确 定</el-button>
        </span>
      </el-dialog>
      <!--删除 -->
      <el-dialog
        title="提示"
        :visible.sync="dele_dialogVisible"
        width="30%">
        <span>是否删除该数据</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dele_dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="delete_click">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {getcontactcreate,getcontactlist,getcontactget,getcontactedit,getcontactdelete}from '../../../api/index'
  export default{
    props:{
      Message:Object
    },
    data(){
      return{
        input:'',
        textarea:'',
        value:'',
        tableData: [],
        newconnection:false,
        connection:false,
        dele_dialogVisible:false,
        options:[{value:1,label:'是'},{value:2,label:'否'}],

        Contact:{
          name:'',
          custom_id:'',
          contact_name:'',
          contact_phone:'',
          contact_duties:'',
          is_decision:'',
          remark:'',
          contact_way:''
        },
        viewobj:{
          name:'',
          custom_id:'',
          contact_name:'',
          contact_phone:'',
          contact_duties:'',
          is_decision:'',
          remark:'',
          contact_way:''
        },
        row_id:0,
        dele_id:0,
        
      }
    },
    created(){
      this.Contact.name=this.Message.name
      this.getlist()
    },
    methods:{
      // 查看弹窗
      cahkan_click(row){
        this.connection = true
        this.row_id = row.id
        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
          }
          console.log('getcontactget222',res);
        })
      },
      // 确认修改
      connection_click(){
        const data = {
          id:this.viewobj.custom_id,
          contact_name: this.viewobj.contact_name,
          contact_phone: this.viewobj.contact_phone,
          contact_duties: this.viewobj.contact_duties,
          is_decision: this.viewobj.is_decision,
          remark: this.viewobj.remark,
          contact_way: this.viewobj.contact_way
        }
        getcontactedit(data).then(res =>{
          console.log('getcontactedit333',res);
          this.getlist()
        })
        this.connection = false
      },
      // 新增弹窗
      newclick(){
        this.newconnection = false
        const data = {
          custom_id: this.Message.id,
          contact_name: this.Contact.contact_name,
          contact_phone: this.Contact.contact_phone,
          contact_duties:this.Contact.contact_duties,
          is_decision: this.Contact.is_decision,
          remark: this.Contact.remark,
          contact_way: this.Contact.contact_way
        }
        getcontactcreate(data).then(res =>{
          console.log('getcontactcreate',res);
          this.getlist()
        })
      },
      // 表格数据源
      getlist(){
        getcontactlist().then(res =>{
          console.log('getcontactlist111',res);
          const list = res.data.list
          const table = []
          list.forEach((item,index) => {
            if(item.is_check==1){
              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.push(arr)
            }
          });
          this.tableData = table
        })
      },
      // 打开删除弹窗
      open_dele(row){
        this.dele_id = row.id
        this.dele_dialogVisible = true
      },
      // 删除确认
      delete_click(){
        getcontactdelete(this.dele_id).then(res =>{
          this.$message({message:res.data.msg,type: 'success'})
          this.getlist()
          this.dele_dialogVisible = false
        })
      },

      // 是否在职
      getoptions(val){
        const options = this.options
        for(let i in options){
          if(options[i].value == val){
            return options[i].label
          }
        }
      }
      
    }
  }
</script>
<style lang="scss" scoped>
  .context{
    padding: 20px 0;
    .xinxi{
      display: flex;
      margin-bottom: 15px;
    }
  }

</style>