<template>
  <div>
    <el-button type="text" size="small" style="font-size: 14px;!important;" :disabled="!data.onstage" @click="drawer = true">关联</el-button>
    <el-drawer
        title="关联项目阶段"
        :visible.sync="drawer"
        size="35%"
        direction="rtl"
        append-to-body
        :show-close="false"
        @close="onClose">
      <div class="drawer__panel" style="margin-bottom: 0px;padding-bottom: 0px">
        <layoutTable ref="projectType" :layout="tablecols" :data="list"  :custom="true" :checkbox="true" @checkboxCallBack="checkboxCallBack">
          <template v-slot:customcol="scope">
            <p>{{scope.column.data[scope.column.columnname]}}</p>
          </template>
        </layoutTable>
        <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>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import layoutTable from '@/components/table/index2'
export default {
  name: "AssociatedProjectStage",
  props:["data"],
  components:{layoutTable},
  data(){
    return {
      drawer:false,
      tablecols:[],
      list:[],
      currentPage:0,
      total:0,
      selectStage:[],
      param:{
        "id": 20221128143604,
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": "",
            "projecttype":""
          }
        }
      }
    }
  },
  methods:{
    async listData(){
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    checkboxCallBack(val){
      this.selectStage = val.map((item,index)=>{
        return {
          stagename:item.stagename,
          sa_projstagemagid:item.sa_projstagemagid
        }
      })
    },
    onSubmit(){
      this.drawer = false
    },
    onClose(){
      this.drawer = false
      this.$emit("selectStage",this.selectStage)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).AssociatedProjectStageTable.tablecols
    this.listData()
  }
}
</script>

<style scoped>

</style>