<template>
  <div class="mod-config">
    <el-form :inline="true"  label-position="top" label-width="100px" >
      <el-form-item :label="'工厂编码:'">
        <el-input v-model="searchData.site" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'入库日期：'">
        <el-date-picker
          style="width: 130px"
          v-model="searchData.startDate"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="'至: '">
        <el-date-picker
          style="width: 130px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <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.orderNo" 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="'是否打印:'">
        <el-select filterable v-model="searchData.printFlag" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="是" value="Y"></el-option>
          <el-option label="否" value="N"></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="qty"
        header-align="center"
        align="right"
        min-width="80"
        label="数量">
      </el-table-column>
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="left"
        min-width="100"
        label="生产订单号">
      </el-table-column>
      <el-table-column
        prop="transDate"
        header-align="center"
        align="left"
        min-width="160"
        label="入库时间">
      </el-table-column>
      <el-table-column
        prop="transNo"
        header-align="center"
        align="left"
        min-width="120"
        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="printFlag"
        header-align="center"
        align="left"
        min-width="80"
        label="是否打印">
      </el-table-column>

    </el-table>

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

<script>
  import {
    getStockPrint
    , updatePrintStock
  } from '@/api/production/generateReport.js'
  import Chooselist from '@/views/modules/common/Chooselist'
  import {
    printMaterialLabelPreview,
  } from "@/views/modules/print/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: {
          orderNo: '',
          partNo: '',
          site: '',
          startDate:new Date(),
          endDate:'',
          printFlag:'N',
          seqNo:'',
          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 () {
        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,
          wareHouseDesc:row.wareHouseDesc,
          orderNo:row.orderNo,
          qty:row.qty,
          umid:row.umid,
          transDate:row.transDate,
          expiredDate:row.expiredDate,
          status:row.status,
          weight:row.weight
        }
        array.push(data)
        printMaterialLabelPreview(array);
        let inData={
          transNo:row.transNo,
          site:row.site
        }
        updatePrintStock(inData).then(({data}) => {
          if (data && data.code === 0) {
            this.search ();
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

    },
    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>
