<template>
  <div>
    <el-card v-loading="loading">
      <outsourceSearch ref="outsourceSearch" @search="reload"></outsourceSearch>
      <ele-pro-table
        ref="table"
        key="id"
        :initLoad="false"
        :columns="columns"
        :datasource="datasource"
        row-key="code"
        :selection.sync="selection"
        :cache-key="`outsourcingTable`"
        @sort-change="onSortChange"
        autoAmendPage
        @update:selection="handleSelectionChange">

        <template v-slot:toolbar>
          <el-button type="primary" @click="createPlan">创建计划</el-button>
        </template>

      </ele-pro-table>
    </el-card>

    <outsourceAddOrEdit ref="outsourceAddOrEdit"></outsourceAddOrEdit>
  </div>
</template>


<script>
import outsourceSearch from './components/outsourceSearch.vue'
import outsourceAddOrEdit from './components/outsourceAddOrEdit.vue'
export default {
  components: {
    outsourceSearch,
    outsourceAddOrEdit
  },
  data(){
    return {
      loading: false,
      columns: [

      ],
      selection: [],
    }
  },
  created() {

  },
  methods: {
    createPlan(){
      console.log('create....')
      this.$refs.outsourceAddOrEdit.open();
    },
    /* 刷新表格 */
    reload(where) {
      this.$nextTick(() => {
        this.$refs.table.reload({ page: 1, where });
      });
    },
    datasource(){

    },
    onSortChange(e) {
      let sort = {
        orderBy: e.order,
        sortName: e.prop
      };
      this.sort = sort;
      this.reload();
    },
    handleSelectionChange(list) {
      if (list.length > 1) {
        let _list = [];
        list.forEach((e) => {
          if (e.childList.length > 0 && e.splitBatch != 2) {
            _list.push(...e.childList);
          } else {
            _list.push(e);
          }
        });
        this.selection = _list;
      } else {
        this.selection = [];
      }
    },
  }
}
</script>

<style scoped lang="scss">

</style>
