<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 :label="'是否入库:'">
          <el-select v-model="searchData.status">
            <el-option label="全部" value=""></el-option>
            <el-option label="未入库" value="未入库"></el-option>
            <el-option label="已入库" value="已入库"></el-option>
          </el-select>
      </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-button @click="search()" style="margin-left: 0px;margin-top:0px" type="primary">查询</el-button>
        <download-excel
          :fields="exportDataStandard"
          :data="tableData"
          type="xlsx"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :defaultValue="exportDefaultValue"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{'导出'}}
        </download-excel>
      </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="60"
        style="font-size: 20px"
        label="工厂编码">
      </el-table-column>
      <el-table-column
        prop="transNo"
        header-align="center"
        align="left"
        min-width="80"
        style="font-size: 20px"
        label="入库通知单号">
      </el-table-column>
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="left"
        min-width="65"
        style="font-size: 20px"
        label="生产订单号">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="left"
        min-width="65"
        style="font-size: 20px"
        label="是否入库">
      </el-table-column>
      <el-table-column
        prop="transDate"
        header-align="center"
        align="left"
        min-width="105"
        label="报工日期">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="105"
        label="产品编号">
      </el-table-column>
      <el-table-column
        prop="partDesc"
        header-align="center"
        align="left"
        min-width="180"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="transQty"
        header-align="center"
        align="right"
        min-width="60"
        label="通知单数量">
      </el-table-column>
      <el-table-column
        prop="seqNo"
        header-align="center"
        align="right"
        min-width="45"
        label="派工单号">
      </el-table-column>

    </el-table>

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

<script>
  import {
    transFerSearch,
    getTransPrintData

  } from '@/api/production/generateReport.js'
  import Chooselist from '@/views/modules/common/Chooselist'
  import {
    printTransNoLabel,
  } from "@/views/modules/print/print_transNo_label_preview.js"
  export default {
    name: 'soscheduleRouting',
    components: {
      Chooselist
    },
    data () {
      return {
        // 导出 start
        exportData: [],
        exportDataStandard: {
          "工厂编号": "site",
          "入库通知单号": "transNo",
          "生产订单": "orderNo",
          "报工日期": "transDate",
          "产品编号": "partNo",
          "产品名称": "partDesc",
          "通知单数量": "transQty",
          "派工单号": "seqNo",
        },
        exportName: "入库通知单"+this.getStrDate(),
        exportHeader: ["入库通知单"],
        exportFooter: [],
        exportDefaultValue: "",
        // 导出 end
        site: this.$store.state.user.site,
        operatorType: 0,

        height: 200,
        tableData: [],
        date1: '',
        searchData: {
          orderNo: '',
          partNo: '',
          site: '',
          startDate:new Date(),
          endDate:'',
          seqNo:'',
          status:'',
        },
        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 () {
        transFerSearch(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 inData={
          transNo:row.transNo,
          site:row.site
        }
        getTransPrintData(inData).then(({data}) => {
          if (data.code == 0) {

              let inList=[];
              inList.push(data.row)
              printTransNoLabel(inList);

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