<template>
  <div>
    <el-dialog
        title="新 建"
        :visible.sync="dialogProjectVisible"
        append-to-body
        width="900px"
        @close="onColes">
      <div slot="title" style="font-size: 15px">
        选择企业
      </div>
      <div class="flex-align-center flex-between mt-10">
        <el-input 
          style="width:200px" 
          size="small"  
          suffix-icon="el-icon-search" 
          v-model="params.content.where.condition" 
          placeholder="搜索" 
          @keyup.enter.native="listData(params.content.pageNumber = 1)" @clear="listData(params.content.pageNumber = 1)" clearable></el-input>
      </div>
      <layout_table
          ref="projectTable"
          :layout="tablecols"
          :data="list"
          :opwidth="200"
          :custom="false"
          :height="320"
          :checkbox="true"
          :onRow="row"
          @rowClick="rowClick"
          @onRow="onRow"
      >
      </layout_table>
      <div style="margin-top:16px;text-align:right">
        <el-pagination
            background
            small
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-size="params.content.pageSize"
            layout="total, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
      <div class="dialog-footer">
        <el-button size="small" @click="onColes" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" class="normal-btn-width btn-warning"  @click="onSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import layout_table from './table'
export default {
  name: "enterprise",
  props:["visible","index"],
  data(){
    return {
      dialogProjectVisible:false,
      bill_id:"",
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      row:"",
      params:{
        "id": 20220920083901,
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": "",
            // "type":1,//1:经销商，2：客户，3：其他，不传查全部,4:查询项目缔约方，sa_projectid必传
            "sa_projectid":""
          }
        }
      }
    }
  },
  components:{layout_table},
  mounted() {
    console.log(this.visible)
    this.dialogProjectVisible = true
    console.log(this.index)
    this.listData()
  },
  methods:{
    async listData(){
        const res = await this.$api.requested(this.params)
        this.list = res.data
        this.total = res.total
        console.log(this.list[0])
        if (this.index !== ''){
          this.toggleSelection([this.list[this.index]])
        }
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    onColes(){
      this.dialogProjectVisible = false
      this.$emit("onEnterprise")
    },
    onRow(row){

      this.row = row
    },
    onSubmit(){

      this.dialogProjectVisible = false
      this.$emit("onEnterprise",this.row)

    },
    toggleSelection(rows) {
      console.log("保存")
      console.log(rows)
      if (rows) {
        rows.forEach(row => {
          this.$refs.projectTable.$refs.tables.setCurrentRow(row);
        });
      } else {
        this.$refs.projectTable.$refs.tables.clearSelection();
      }
    },
    rowClick(row){
      console.log("选中")
      console.log(row)
    }

  },

  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).enterpriseTable.tablecols
  }
}
</script>

<style scoped>

</style>