<template>
  <div class="mod-config">
    <el-form :inline="true"  label-position="top" label-width="100px" >
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(5)"><a herf="#">物料编码</a></span>
        <el-input v-model="searchData.partNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'批次号:'">
        <el-input v-model="searchData.batchNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'是否显示库存为0的批次:'">
        <el-select v-model="searchData.zeroSql" style="width: 120px">
          <el-option label="是" value=" "></el-option>
          <el-option label="否" value=" AND QtyOnHand >0.0001"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="search()" style="margin-left: 0px;margin-top:0px" type="primary">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :height="height"
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop=""
        header-align="center"
        align="center"
        min-width="60"
        label="操作">
        <template slot-scope="scope" class="foo_container">
          <a type="text" size="small" @click="printStock(scope.row)">打印标签</a>
        </template>
      </el-table-column>
      <el-table-column
        prop="site"
        header-align="center"
        align="left"
        min-width="70"
        label="工厂编码">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="100"
        label="物料编码">
      </el-table-column>
      <el-table-column
        prop="partDesc"
        header-align="center"
        align="left"
        min-width="200"
        label="物料名称">
      </el-table-column>
      <el-table-column
        prop="qtyOnHand"
        header-align="center"
        align="right"
        min-width="80"
        label="当前库存">
      </el-table-column>
      <el-table-column
        prop="warehouseID"
        header-align="center"
        align="left"
        min-width="80"
        label="仓库编码">
      </el-table-column>
      <el-table-column
        prop="locationID"
        header-align="center"
        align="left"
        min-width="80"
        label="库位Id">
      </el-table-column>
      <el-table-column
        prop="batchNo"
        header-align="center"
        align="left"
        min-width="110"
        label="批号">
      </el-table-column>
      <el-table-column
        prop="manufactureDate"
        header-align="center"
        align="left"
        min-width="130"
        label="生产日期">
      </el-table-column>
      <el-table-column
        prop="expiredDate"
        header-align="center"
        align="left"
        min-width="130"
        label="失效日期">
      </el-table-column>

    </el-table>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    getStockPrint
  } from "@/api/production/schedule.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  import {
    printMaterialLabelPreview,
  } from "@/views/modules/print/label/print_stock_label_preview.js"
  export default {
    name: 'soscheduleRouting',
    components: {
      Chooselist
    },
    data () {
      return {

        site: this.$store.state.user.site,
        operatorType: 0,

        height: 200,
        tableData: [],
        date1: '',
        searchData: {
          partNo: '',
          zeroSql:' AND QtyOnHand >0.0001',
          batchNo:'',
        },
        photoUrl:'',
        sopData:{
          site:'',
          partNo:'',
        },
        partDescription:'',
        fileTitle:'',
        fileName:'',
        num:1,
        currentData:'',
        photoDatas:[],
        uploadImg:[],
        showviewer: false,
        url: '',
        height2:600,
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
        this.height2 = window.innerHeight -100
      })
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 5) {
            strVal = this.searchData.partNo
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 5) {
          this.searchData.partNo = val.PartNo
        }
      },

      search () {
        if(this.searchData.partNo==''&&this.searchData.batchNo==''){
          this.$alert('料号和批次,请至少输入一个条件！', '错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        getStockPrint(this.searchData).then(({data}) => {
          this.tableData = data.rows
        })
      },
      createExportData () {
        return this.tableData
      },
      startDownload () {
        //  this.exportData = this.dataList

      },
      finishDownload () {

      },
      getStrDate () {
        let dd = new Date()
        let Y = dd.getFullYear()
        let M = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1)// 获取当前月份的日期，不足10补0
        let D = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate()// 获取当前几号，不足10补0
        let H = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
        let MM = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
        let S = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
        return Y + M + D + H + MM + S
      },
      printStock(row){
        let array=[];
        let data={
          seqNo:row.site+'|'+row.partNo+'|'+row.warehouseID+'|'+row.batchNo+'|'+row.locationID,
          site:row.site,
          wareHouseId:row.warehouseID,
          batchNo:row.batchNo,
          locationId:row.locationID,
          partNo:row.partNo,
          partDesc:row.partDesc,
          partSpec:row.partSpec,
          wareHouseDesc:row.wareHouseDesc,
          orderNo:row.orderNo,
          transDate:row.transDate,
          manufactureDate:row.manufactureDate,
          qty:row.qtyOnHand,
          umid:row.umid
        }
        array.push(data)
        printMaterialLabelPreview(array);
      },

    },
    created () {
    }
  }
</script>

<style scoped>
  .input_left{
    text-align: left;
  }
  .input_reight{
    text-align: right;
  }
  /deep/ input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
  }
  input[type='number'] {
    -moz-appearance: textfield !important;
  }

</style>
