<template>
  <div class="mod-config">
    <h1>自动打印库存标签</h1>
  </div>
</template>

<script>
  let autoPrint = '' //数据刷新定时器
  import {
    getStockPrintListHunlian,
    updateStockPrintFlag
  } from '@/api/board.js'
  import {
    printMaterialLabel,
  } from "@/views/modules/print/print_stock_label.js"
  import {
    printMaterialLabelReturn,
  } from "@/views/modules/print/print_stock_labelReturn.js"
  import {
    printMaterialLabelPreview,
  } from "@/views/modules/print/print_stock_label_preview.js"
  export default {
    name: 'autoPrintStock',
    data () {
      return {
        ip:this.$route.query.ip
      }
    },
    mounted () {
      this.refreshTable ()
    },
    methods: {
      refreshTable () {
        autoPrint = setInterval(() => {
          this.printStock()
        }, 3000)
      },
      printStock(){
        let ipp='no'
        if(this.ip){
          ipp=this.ip
        }
        getStockPrintListHunlian(ipp).then(({data}) => {
          if (data.code == 0) {
            let array=[];
            if(data.rows.length>0){
              for (let i = 0; i < data.rows.length; i++) {
                for (let j = 0; j <data.rows[i].printQty ; j++) {
                  array.push(data.rows[i])
                }
              }
              printMaterialLabel(array);
              for (let i = 0; i < data.rows.length; i++) {
                let inData={
                  transNo:data.rows[i].transNo,
                  site:data.rows[i].site
                }
                updateStockPrintFlag(inData).then(({data}) => {

                })
              }

            }
            if(data.rows2.length>0){
              let array2=[];
              for (let i = 0; i < data.rows2.length; i++) {
                for (let j = 0; j <data.rows2[i].printQty ; j++) {
                  array2.push(data.rows2[i])
                }
              }
              printMaterialLabelPreview(array2);
            }
            if(data.rows8.length>0){
              let array8=[];
              for (let i = 0; i < data.rows8.length; i++) {
                for (let j = 0; j <data.rows8[i].printQty ; j++) {
                  array8.push(data.rows8[i])
                }
              }
              printMaterialLabelReturn(array8);
              for (let i = 0; i < data.rows8.length; i++) {
                let inData={
                  transNo:data.rows8[i].transNo,
                  site:data.rows8[i].site
                }
                updateStockPrintFlag(inData).then(({data}) => {

                })
              }

            }
          }
        })
      },
    },
  }
</script>

<style >


  .board2 .el-table .cell {
    line-height: 13px;
    font-size: 12px;
    height: 13px;
    padding: 0px;
  }

  .board2 .el-table .success-row {
    background: #1bb61b;
  }
  .board2 .el-table .false-row {
    /*background: #cbcb14;*/
    background: #db1212;
  }
  .board2 .el-table .yellow-row{
    background: #ffff00;
  }
</style>
