<template>
  <div class="container">
    <my-table
        :data="data"
        :table-filter="tableFilter"
        :columns="columns"
        :is-show-page="false"
        @event-handle="eventHandle"
    >
    </my-table>
  </div>
</template>

<script>
import { StopIllegalWarning, PlcStorageOut, GetIllegalData } from '@/api/integrated'
import MyTable from '@/components/my-table/my-table'
import { logOut } from '@/libs/util'
export default {
  name: "warning-list",
  components: {
    MyTable
  },
  data() {
    return {
      tableFilter: [
        {
          name: 'Button',
          type: 'primary',
          text: '结束预警',
          align: 'right',
          e: 'over'
        }
      ],
      data: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 100,
          align: 'center'
        },
        {
          title: '物料名称',
          key: 'materialName',
          minWidth: 150
        },
        {
          title: '物料编码',
          key: 'materialCode',
          minWidth: 150
        },
        {
          title: '物料标签',
          key: 'rfidCode',
          minWidth: 150
        },
        {
          title: '类型',
          key: 'inOutType',
          minWidth: 150
        },
        {
          title: '操作',
          align: 'center',
          width: '150px',
          fixed: 'right',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '.5vw'
                  },
                  on: {
                    click: () => {
                      PlcStorageOut({
                        inOutStorageNo: '',
                        storageDoor: sessionStorage.getItem('door'),
                        plcStationCode: sessionStorage.getItem('plcCode'),
                        rfidList: [params.row.RfidCode]
                      }).then(res => {
                        if (res.code === 0) {
                          this.data.splice(params.row._index)
                        }
                      })
                    }
                  }
                },
                '出库'
              )
            ])
          }
        }
      ]
    }
  },
  methods: {
    getList() {
      GetIllegalData({
        plcStationCode: sessionStorage.getItem('plcCode')
      }).then(res => {
        if (res.code === 0) {
          this.data = res.result
        }
      })
    },
    // 检索条件事件处理
    eventHandle (option) {
      switch (option._evnet) {
        case 'over':
          StopIllegalWarning({
            plcStationCode: sessionStorage.getItem('plcCode')
          }).then(res => {
            if (res.code === 0) {
              logOut()
            }
          })
          break
      }
    }
  },
  mounted() {
    this.getList()
  }
}
</script>

<style scoped>
  .container {
    padding: 10px 0;
  }
</style>
