<template>
  <div>
    <el-dialog
        title="选择客户"
        :visible.sync="dialogProjectVisible"
        append-to-body
        width="900px"
        @close="onColes">
      <div class="panel_Target">
        <el-input style="width:200px;margin-top: 10px;margin-bottom: 15px" placeholder="请输入搜索内容" suffix-icon="el-icon-search" @input="selectChange" v-model="param.content.where.condition" @keyup.native.enter="customerList(param.content.pageNumber = 1)" @clear="customerList(param.content.pageNumber = 1)" size="small" class="input-with-select inline-16 layout_search__panel" clearable>
        </el-input>
        <tableLayout  ref="list" :layout="tablecols" :data="list" :custom="true" >
          <template v-slot:customcol="scope">
            <p >{{scope.column.data[scope.column.columnname]}}</p>
          </template>
          <template v-slot:opreation="scope">
            <el-button type="text" size="mini" @click="selectProject(scope.data)">选择该客户</el-button>
          </template>
        </tableLayout>
        <div class="container normal-panel" style="text-align:right">
          <el-pagination
              background
              small
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[20, 50, 100, 200]"
              layout="total,sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "customerTable",
  props:["customerDrawer","id","isQuotedPrice"],
  data(){
    return {
      tablecols:'',
      list:[],
      total:0,
      currentPage:0,
      dialogProjectVisible:false,
      param:{
        "id": 20220920083901,
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": "",
            "type":4,
            "sa_projectid":""
          }
        }
      }
    }
  },
  methods:{
    async customerList(){
      if (this.isQuotedPrice){
        this.param.content.where.sa_projectid = this.id
        this.param.content.where.type = 4
        const res = await this.$api.requested(this.param)
        this.list = res.data
        this.total = res.total
        this.currentPage = res.pageNumber
      }else {
        this.param.content.where.type = 2
        const res = await this.$api.requested(this.param)
        this.list = res.data
        this.total = res.total
        this.currentPage = res.pageNumber
      }

    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.customerList()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.customerList()
    },
    selectProject(val){
      this.$emit('customerData',val)
      this.dialogProjectVisible = false

    },
    onColes(){
      this.dialogProjectVisible = false
      this.$emit('projectList')
    },
    selectChange(){
      this.customerList()
    }
  },
  mounted() {
    if (this.customerDrawer){
      this.dialogProjectVisible = true
      this.customerList()
    }
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).enterpriseTable.tablecols
  }
}
</script>

<style scoped>
.el-pagination {
  text-align: right;
}
.panel_Target {
  border-top:1px solid #eeeeee;
  padding:5px 5px;
  margin-bottom:0px
}
>>> .el-dialog__body {
  padding: 0px 0px 10px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
}
>>> .el-dialog__header {
  padding: 10px 10px 10px ;

}
.dialog-footer{
  margin-top: 0px;
  margin-bottom: 10px;
}
>>> .el-dialog__title {
  line-height: 24px;
  font-size: 16px;
  color: #303133;
}
</style>