<template>
  <div>
    <div class="mrg-b">
      <!--<drop-filter-->
        <!--:columns="wholeLabels"-->
        <!--:storeKey="storeKey"-->
        <!--:storeLabels="storeLables"-->
        <!--@doFilter="labels => storeLables = labels"-->
      <!--&gt;</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="kitNo">
          <template slot-scope="scope">
            <span class="blue" @click.stop="handleOpenDetail(scope.row, scope.row.kitNo)">{{scope.row.kitNo}}</span>
          </template>
        </table-column>
        <table-column label="物流单号 " prop="logisticNo"></table-column>
        <table-column label="状态" prop="status">
          <template slot-scope="scope">
            {{$utils.keyMatcher(scope.row.status, $keys.maintain.status).name}}
          </template>
        </table-column>
        <table-column label="类型">
          <template slot-scope="scope">
            <p>{{ $utils.keyMatcher(scope.row.kitType, $keys.maintain.kitType).name }}</p>
          </template>
        </table-column>
        <table-column label="数量EA" prop="qty"></table-column>
        <table-column label="货主">
          <template slot-scope="scope">
            <p>{{scope.row.ownerCode}}</p>
            <p>{{scope.row.ownerName}}</p>
          </template>
        </table-column>
        <table-column label="计划加工台" prop="kitLoc"></table-column>
        <table-column label=" 计划加工时间" prop="planTime"></table-column>
        <table-column label="操作" width="100" fixed="right">
            <template slot-scope="scope">
              <el-tooltip content="编辑" placement="top">
                <el-button
                    size="mini"
                    type="primary"
                    icon="el-icon-edit"
                    plain
                    circle
                    @click="handleProcess(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: {
    getOrderStatus (kitOrderHeader) {
      const orderStatus = {
        'NEW': 'NEW', // 新增状态
        'CREATE_NEW': 'CREATE_NEW', // 创建未审核
        'CREATE_CLOSE': 'CREATE_CLOSE', // 创建已审核
        'CREATE_NOT': 'CREATE_NOT', // 创建不审核
        'PARTKIT_CLOSE': 'PARTKIT_CLOSE', // 部分加工已审核
        'PARTKIT_NOT': 'PARTKIT_NOT', // 部分加工不审核
        'FULLKIT_CLOSE': 'FULLKIT_CLOSE', // 完全加工已审核
        'FULLKIT_NOT': 'FULLKIT_NOT', // 完全加工不审核
        'CLOSE': 'CLOSE', // 关闭订单
        'CANCEL': 'CANCEL'// 取消订单
      }
      if (!kitOrderHeader || !kitOrderHeader.jobId || kitOrderHeader.jobId === '') {
        return orderStatus.NEW
      }
      // 创建
      if (kitOrderHeader.status === '00') {
        if (kitOrderHeader.auditStatus === '00') {
          return orderStatus.CREATE_NEW
        }
        if (kitOrderHeader.auditStatus === '99') {
          return orderStatus.CREATE_CLOSE
        }
        if (kitOrderHeader.auditStatus === '90') {
          return orderStatus.CREATE_NOT
        }
      }
      // 部分加工
      if (kitOrderHeader.status === '70') {
        if (kitOrderHeader.auditStatus === '99') {
          return orderStatus.PARTKIT_CLOSE
        }
        if (kitOrderHeader.auditStatus === '90') {
          return orderStatus.PARTKIT_NOT
        }
      }
      // 完全加工
      if (kitOrderHeader.status === '80') {
        if (kitOrderHeader.auditStatus === '99') {
          return orderStatus.FULLKIT_CLOSE
        }
        if (kitOrderHeader.auditStatus === '90') {
          return orderStatus.FULLKIT_NOT
        }
      }
      // 关闭订单
      if (kitOrderHeader.status === '99') {
        return orderStatus.CLOSE
      }
      // 取消订单
      if (kitOrderHeader.status === '90') {
        return orderStatus.CANCEL
      }
    },

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

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

    // checkbox勾选
    handleSelectChange (selection) {
      const ids = selection.map(item => item.kitNo)
      this.$emit('handleSelectChange', ids)
    },
    getData (url, param) {
      return this.$https.post(url, param)
    },
    // 详情页
    handleOpenDetail (data, kitNo) {
      this.$emit('handleOpenDetail', 'detail', data)
    },
    handleProcess (row) {
      const kitOrderStatus = this.getOrderStatus(row)
      if (!(kitOrderStatus === 'CREATE_CLOSE' || kitOrderStatus === 'CREATE_NOT' || kitOrderStatus === 'PARTKIT_CLOSE' || kitOrderStatus === 'PARTKIT_NOT')) {
        return this.$message('不是创建或部分加工状态，不能操作')
      }
      const url = this.$API.maintain.KitBomKitConfirmList.kitControll
      let arr = []
      arr.push(row.kitNo)
      const param = { kitNos: JSON.stringify(arr) }
      this.$https.post(url, param).then(res => {
        this.$emit('getList', this.query)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.mrg-b {
  margin-bottom: 20px;
}
.mrg-l {
  margin-left: 10px;
}
.blue {
  cursor: pointer;
  color: #0682ea;
}
</style>
