<template>
    <div>
        <div class="mrg-b">
          <!--<drop-filter :columns="wholeLabels" :storeKey="storeKey"  :storeLabels="storeLables"  @doFilter="labels => storeLables = labels"></drop-filter>-->
            <el-table
            ref="table"
            stripe
            border
            :max-height="tableMaxHeight"
            :data="tableData"
            :filteredLabels="storeLables"
            @selection-change='handleSelectChange'>
                <table-column
                type="selection"
                fixed
                width="45"
                    align="center">
                </table-column>
                <table-column
                label="货主编码"
                prop="ownerCode">
                <template slot-scope="scope">
                    <span class="blue" @click.stop="handleOpenDetail(scope.row.ownerCode,scope.row.parentSkuCode,scope.row.kitType)" >{{scope.row.ownerCode}}</span>
                  </template>
                </table-column>
                <table-column
                label="货主名称"
                prop="ownerName">
                </table-column>
                <table-column
                label="父件编码"
                prop="parentSkuCode">
                </table-column>
                <table-column
                label="父件名称"
                prop="parentSkuName">
                </table-column>
                <table-column
                label="组合件类型"
                prop="kitType">
                <template slot-scope="scope">
                  {{ $utils.keyMatcher(scope.row.kitType, $keys.maintain.kitType).name }}
                </template>
                </table-column>
                <table-column
                label="齐套管理类型"
                prop="kittingType">
                <template slot-scope="scope">
                  {{ $utils.keyMatcher(scope.row.kittingType, $keys.maintain.kittingType).name }}
                </template>
                </table-column>
                <table-column
                label="备注"
                prop="remark">
                </table-column>
                <table-column
                label="操作"
                width="100"
                fixed="right">
                    <template slot-scope="scope">
                       <el-tooltip content="编辑" placement="top">
                        <el-button
                        v-auth="50500010108"
                        size="mini"
                        type="primary"
                        icon="el-icon-edit"
                        plain
                        circle
                        @click="handleEdit(scope.$index, scope.row)"></el-button></el-tooltip>
                         <el-tooltip content="删除" placement="top">
                        <el-button
                        v-auth="50500010109"
                        size="mini"
                        type="danger"
                        icon="el-icon-delete"
                        plain
                        circle
                        @click="handleDelete(scope.$index, scope.row)"></el-button></el-tooltip>
                    </template>
                </table-column>
            </el-table>
        </div>
    <div>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
    </div>
</div>
</template>
<script>
export default {
  data () {
    return {

      remove: [],
      headData: {},
      goodsData: [],
      storeKey: 'libraryGoods'
    }
  },
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    total: Number,
    pageSize: Number,
    currentPage: Number,
  },
  methods: {

    // 每页显示条数
    handleSizeChange (pageSize) {
      const query = { 'page.currentPage': this.currentPage, 'page.limitCount': pageSize }
      this.$emit('getList', query)
    },

    // 当前页码
    handleCurrentChange (currentPage) {
      const query = { 'page.currentPage': currentPage, 'page.limitCount': this.pageSize }
      this.$emit('getList', query)
    },
    getData (url, param) {
      return this.$https.post(url, param)
    },

    // 编辑行
    handleEdit (index, row) {
      const headUrl = this.$API.maintain.CdWhBomList.getHeader
      const subDetailUrl = this.$API.maintain.CdWhBomList.getSubDetail
      const stepUrl = this.$API.maintain.CdWhBomList.getStep
      const param = { ownerCode: row.ownerCode, parentSkuCode: row.parentSkuCode, kitType: row.kitType }
      this.$https.all([this.getData(headUrl, param), this.getData(subDetailUrl, param), this.getData(stepUrl, param)]).then(res => {
        const head = res[0].data
        const subDetail = res[1].rows
        const step = res[2].rows
        this.$emit('handleOpenEditForm', 'edit', head, subDetail, step)
      })
    },

    // 详情
    handleOpenDetail (ownerCode, parentSkuCode, kitType) {
      const headUrl = this.$API.maintain.CdWhBomList.getHeader
      const subDetailUrl = this.$API.maintain.CdWhBomList.getSubDetail
      const stepUrl = this.$API.maintain.CdWhBomList.getStep
      const param = { ownerCode, parentSkuCode, kitType }
      this.$https.all([this.getData(headUrl, param), this.getData(subDetailUrl, param), this.getData(stepUrl, param)]).then(res => {
        const head = res[0].data
        const subDetail = res[1].rows
        const step = res[2].rows
        this.$emit('handleOpenDetail', 'detail', head, subDetail, step)
      })
    },

    // 删除行
    handleDelete (index, row) {
      const url = this.$API.maintain.CdWhBomList.delList
      this.remove.push(row)
      const param = { bomHeaders: JSON.stringify(this.remove) }

      this.$confirm('是否删除此条数据？', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // checkbox勾选
    handleSelectChange (selection) {
      const rows = selection.map(item => item)
      this.$emit('handleSelectChange', rows)
    }
  }
}
</script>
<style lang="scss" scoped>
    .mrg-b{
        margin-bottom: 20px;
    }
    .mrg-l{
        margin-left:10px;
    }
    .blue{
      cursor: pointer;
      color:#0682ea
    }
</style>
