<template>
  <div>
    <p-table-edit
      size="small"
      :columns="isCaseOrPiece ? printcolumns : printcolumns2"
      rowKey="barcodeDId"
      :data-source="tableData"
      :rowSelectType="isCaseOrPiece ? 2 : false"
      :scroll="{ x: 'max-content' }"
      :pagination="10"
      :rowClassName="setRowClassName"
      :editorRowTable="!makeUpStatus"
      @checkRow="tableSelect"
      bordered
    >
      <!-- <template slot="index" slot-scope="text, record, index">{{ index + 1 }}</template> -->
      <!-- <div slot="action" href="javascript:;" slot-scope="text">
        <a slot="action" style="margin: 0 5px" @click.stop="bartNoCheck(text)">冲红</a>
      </div> -->
    </p-table-edit>
  </div>
</template>

<script>
import { printcolumns, printcolumns2 } from './config/LCN'
import { getPrintInfo } from '../api'
export default {
  name: 'LCLinfo',
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    data: {
      type: Object,
      default: {}
    },
    selectedRows: {
      type: Array,
      default: []
    },
    //补打和非补打标记
    makeUpStatus: {
      type: Boolean,
      default: false
    },
    //整件散件标记
    isCaseOrPiece: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      confirmLoading: false,
      printcolumns,
      printcolumns2,
      tableData: [],
      selectedListRows: [],
      selectedListRowKeys: [],
      selectedPickTaskIdRows: []
    }
  },
  created() {
    console.log('修改拼箱1')
    console.log(this.data)
    console.log(this.selectedRows)
    if (this.selectedRows.length > 0) {
      // debugger
      let selectlist = JSON.parse(JSON.stringify(this.selectedRows))
      //勾选数据去重
      let obj = {}
      selectlist = selectlist.reduce((item, next) => {
        if (!obj[next.pickTaskDId]) {
          item.push(next)
          obj[next.pickTaskDId] = true
        }
        return item
      }, [])
      let list = []
      // selectlist[0].pickTaskDId = '625019163580833799'
      //勾选数据与拼箱去重
      for (let i = 0; i < selectlist.length; i++) {
        console.log(selectlist[i])
        for (let q = 0; q < this.data.barcodeDList.length; q++) {
          if (selectlist[i].pickTaskDId == this.data.barcodeDList[q].pickTaskDId) {
            list.push(selectlist[i].pickTaskDId)
          }
        }
      }
      list.forEach(item => {
        selectlist.forEach((el, index) => {
          if(el.pickTaskDId == item) {
            selectlist.splice(index, 1)
          }
        })

      })
      // console.log(selectlist, 'selectlistselectlistselectlistselectlist')
      // console.log(list, 'listlistlistlist')
      // console.log(selectlist, 'listlistlistlist11111111111111111111')
      this.tableData = [...selectlist,...this.data.barcodeDList]
    } else {
      this.tableData = this.data.barcodeDList
    }

    console.log(this.tableData)
  },
  watch: {
    // data: {
    //   handler(newVal) {
    //     console.log('修改拼箱2')
    //     this.tableData = newVal.barcodeDList
    //   },
    //   immediate: true
    // }
  },
  computed: {},
  methods: {
    setRowClassName(record) {
      if(record.printCount) {
        return 'rowcolor3'
      }
      if (record.itemId) {
        return 'rowcolor'
      } else {
        return 'rowcolor2'
      }
    },
    tableSelect(selectedRowKeys, selectedRows) {
			// console.log('checkRow:', selectedRowKeys, selectedRows);
			this.selectedListRows = selectedRows
      this.selectedListRowKeys = selectedRowKeys
      this.selectedPickTaskIdRows = selectedRows.map(item => {
        return item.pickTaskDId
      })
		},
  }
}
</script>

<style>
.rowcolor {
  background: #da1e2e;
}
.rowcolor2 {
  background: #ff21;
}
.rowcolor3 {color: white;background: green;}
</style>
