<template>
  <div class="decisionMaking">

    <template v-if="ifEmpty">
      <div class="flex-box query-box">
        <div class="flex-box query-params"></div>
        <div class="flex-box query-add">
          <el-button type="primary" icon="el-icon-plus" @click="opennew">新增决策链条</el-button>
        </div>
      </div>

      <div class="table-item">
        <tables
          :indexFixed="true"
          :tableLoading="tableLoading"
          :tableData="tableData"
          :forData="forData"
          :tableDataTotal="tableDataTotal"
          :queryParams="queryParams"
          @handle-current-change="handleCurrentChange"
        />
      </div>

    </template>
    <template v-else>
      <div class="cooperate_empty">
        <img src="@/assets/images/project/empty.png"/>
        <div class="empty-t">暂无客户联系人数据</div>
        <div class="empty-d">抱歉，你还未添加客户联系人，快去添加吧</div>
        <el-button type="primary" class="empty-b" @click="opennew">添加联系人</el-button>
      </div>
    </template>

    <!-- 弹窗添加联系人 -->
    <el-dialog
      class="popups1"
      :visible.sync="dialogVisible"
      :before-close="cancel"
      width="464px">
      <div class="poptitle">
        <img src="@/assets/images/economies/icon.png">
        <span>重庆市轨道交通3号线二期工程4标段施工总承包</span>
      </div>
      <el-form :model="addRorm" :rules="addRules" ref="addRorm" class="popform" label-width="75px">
        <el-form-item label="姓名：" prop="name">
          <el-input v-model="addRorm.name" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="角色：" prop="role">
          <el-input v-model="addRorm.role" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="职位：" prop="workUnit">
          <el-input v-model="addRorm.workUnit" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="公司/机关：" prop="position">
          <el-input v-model="addRorm.position" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="联系方式：" prop="contactInformation">
          <el-input v-model="addRorm.contactInformation" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="备注：" prop="remark">
          <el-input v-model="addRorm.remark" placeholder="请输入"></el-input>
        </el-form-item>
        <div class="popbot">
          <div class="btn btn_cancel h32" @click="cancel">返回</div>
          <div class="btn btn_primary h32" @click="add">保存</div>
        </div>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import Tables from "../component/Tables"
import {
  getList,
  addChain
} from '@/api/detail/party-a/decisionMaking'
export default {
  name: 'DecisionMaking',
  components: {
    Tables
  },
  props: {
    customerIds: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ifEmpty:false,
      queryParams:{
        customerId:this.customerIds,
        pageNum:1,
        pageSize:10,
      },
      forData: [
        {label: '姓名', prop: 'name', width: '124'},
        {label: '角色', prop: 'role', width: '110'},
        {label: '公司/机关', prop: 'position', width: '268'},
        {label: '职位', prop: 'workUnit', width: '110'},
        {label: '联系方式', prop: 'contactInformation', width: '105'},
        {label: '内部维护人', prop: 'updateBy', width: '88'},
        {label: '备注', prop: 'remark'},
      ],
      addRorm: {
        customerId:'f25219e73249eea0d9fddc5c7f04f97f',
        name:'',
        role:'',
        workUnit:'',
        position:'',
        contactInformation:'',
        remark:'',
      },
      addRules:{
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
        ],
      },
      stageOptions:[],
      statusOptions:[],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
      //弹窗
      dialogVisible: false,
    }
  },
  created() {
    this.list();
  },
  computed: {

  },
  methods: {
    list(){
      this.tableLoading = true
      getList(this.queryParams).then((res) => {
        if(res.code == 200){
          if(res.rows.length >0){
            this.tableData = res.rows
            this.tableDataTotal = res.total
            this.ifEmpty = true
          }
          this.tableLoading = false
        }
      })
    },
    //分页
    handleCurrentChange(e){
      this.queryParams.pageNum = e
      this.list()
    },
    add(){
      this.$refs.addRorm.validate((valid) => {
        if (valid) {
          addChain(this.addRorm).then((res) => {
            if(res.data){
              this.$message({
                message: '新增成功',
                type: 'success'
              });
              this.cancel()
              this.list()
            }else{
              this.$message({
                message: res.msg,
                type: 'error'
              });
            }
          })
        }
      });
    },
    cancel(){
      this.$refs.addRorm.resetFields();
      this.dialogVisible = false
    },
    //打开新建窗口
    opennew(){
      this.dialogVisible = true
    },
  }
}
</script>
<style lang="scss" scoped>
.decisionMaking{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  input{
    border: 1px solid #EFEFEF;
  }
  ::v-deep .el-form-item{
    margin-bottom: 16px;
  }
  ::v-deep .el-input__inner{
    border-radius: 2px 0 2px 0;
    height: 32px;
    line-height: 32px;
  }
  .cooperate-name{
    ::v-deep .el-form-item__content{
      display: flex;
      span{
        width: 60px;
        height: 32px;
        background: #F5F5F5;
        text-align: center;
        color: #0081FF;
        border: 1px solid #EFEFEF;
        border-left: 0;
        cursor: pointer;
      }
    }

  }
  .query-add{
    button{
      width: 124px;
      line-height: 32px;
      height: 32px;
      background: #0081FF;
      border-radius: 2px 2px 2px 2px;
      padding: 0;
      color: #ffffff;
      span{
        color: #ffff;
        margin-left: 4px;
      }
    }
  }
  .cooperate_empty{
    text-align: center;
    height: calc(100vh - 170px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    img{
      width: 108px;
      height: 108px;
      border-radius: 50%;
      margin-bottom: 24px;
    }
    .empty-t{
      font-size: 16px;
      color: #333333;
      margin-bottom: 8px;
    }
    .empty-d{
      font-size: 14px;
      font-weight: 400;
      color: #999999;
      margin-bottom: 24px;
    }
    .empty-b{
      width: 116px;
      height: 36px;
      background: #0081FF;
      border-radius: 4px;
      padding: 0;
    }
  }
  .table-item{
    margin-top: 10px;
  }
  // 弹窗
  .popups1{
    .poptitle {
      line-height: 48px;
      border-bottom: 1px solid #E1E1E1;
      height: 48px;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      img {
        width: 17px;
        margin: 16px;
        float: left;
      }
      span {
        font-weight: bold;
        font-size: 16px;
        color: #232323;
        font-family: Microsoft YaHei-Bold, Microsoft YaHei;
        width: 385px;
        display: block;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
    ::v-deep .el-dialog__body{
      padding: 24px 24px 18px;
    }
    .popform {
      padding-top: 14px;
      ::v-deep .el-form-item__label{
        padding:0;
      }
      .row {
        padding-bottom: 16px;
        .left {
          width: 137px;
          display: inline-block;
          text-align: right;
          opacity: 0.8;
        }
        ::v-deep .el-input {
          display: inline-block;
          width: 240px;
        }
      }
      .popbot {
        text-align: right;
        padding-top: 8px;
      }
    }
  }
}
::v-deep .el-table__fixed::before, ::v-deep .el-table__fixed-right::before{
  background-color:unset;
}

</style>
