<template>
  <div>
    <el-button size="mini" @click="onShow" :disabled="data.status !== '新建'">编 辑</el-button>
    <el-drawer
        title="编辑人员"
        append-to-body
        :visible.sync="dialogTableVisible"
        direction="rtl"
        size="60%"
        @close="dialogTableVisible = false">

      <div class="drawer__panel">
        <p class="normal-margin inline-16" >年度:</p>
        <el-input class="inline-16" style="width:250px" size="small" v-model="form.year" disabled ></el-input>
        <div class="flex-align-center normal-margin flex-between">
          <p>请选择人员:</p>
          <div class="flex-align-center">
            <p>搜索:&nbsp;</p>
            <el-input style="width:250px" size="small" placeholder="人员姓名" v-model="condition" @keyup.native.enter="selectChange"  clearable></el-input>
          </div>
        </div>
        <tablelayout class="normal-margin" :layout="tablecols" :data="list" :custom="true" :checkbox="true" height="calc(100vh - 452px)" @checkboxCallBack="checkboxCallBack">
          <template v-slot:customcol="scope">
            <p>{{scope.column.data[scope.column.columnname]}}</p>
          </template>
        </tablelayout>
        <!-- <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.content.pageNumber"
          :page-size="params.content.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
        </el-pagination> -->
        <div class="flex-align-center">
          <p>已选{{selection.length}}人</p>&nbsp;
          <p>总共{{list.length}}人</p>
        </div>
        <div class="fixed__btn__panel">
          <el-button size="small" @click="dialogTableVisible = false" class="normal-btn-width">取 消</el-button>
          <el-button size="small" type="warning" :disabled="selection.length === 0" @click="onSubmit" class="normal-btn-width">保 存</el-button>
        </div>
<!--        <div class="dialog-footer">
          <el-button size="small" @click="dialogTableVisible = false" class="normal-btn-width">取 消</el-button>
          <el-button size="small" type="warning" :disabled="selection.length === 0" @click="onSubmit" class="normal-btn-width">确 定</el-button>
        </div>-->
      </div>
    </el-drawer>
  </div>

</template>

<script>
import tablelayout from '@/components/table/index.vue'
export default {
  name: "edit",
  props:["data"],
  data(){
    return {
      dialogTableVisible:false,
      form:{
        "year": '',
        "sa_salestargetbillid": 0,//新建年度是为0，添加人员时为具体的数据id
        "sales":[]
      },
      tablecols:[],
      list:[],
      selection:[],
      condition:'',
      total:0,
    }
  },
  components:{
    tablelayout
  },
  methods:{
    onShow(){
      this.dialogTableVisible = true
    },
    async listData () {
      const res = await this.$api.requested({
        "id": 20220901091302,
        "content": {
          "sa_salestargetbillid": this.$route.query.id,
          "where": {
            "condition": this.condition
          }
        },
      })
      res.data.forEach(e => {
        e.marea = e.area.map(m=>{
          return `${m.province}${m.city}${m.county}`
        })
        e.marea = e.marea.join(',')
      });
      this.list = res.data
    },
    checkboxCallBack (val) {
      this.selection = val
    },
    async onSubmit () {
      if (this.form.year === '') return this.$message({
        message:'请选择年度',
        type:'error'
      })
      const res = await this.$api.requested({
        "id": 20220831165302,
        "content": {
          "year":this.form.year,
          "sa_salestargetbillid": this.form.sa_salestargetbillid,
          "sales": this.selection
        },
      })
      this.tool.showMessage(res,()=>{
        this.dialogTableVisible = false
        this.$emit('onSuccess')
      })
    },
    selectChange(){
      this.listData()
    }
  },
  mounted () {
    this.listData()
  },
  created () {
    this.form = this.data
    console.log(this.form)
    this.tablecols = this.tool.tabelCol(this.$route.name)['personalTable'].tablecols
  }
}
</script>

<style scoped>

</style>
