<template>
  <div class="mod-config">
    <el-form :inline="true"  label-position="top" label-width="100px" style="margin-top: -20px;">
      <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.orderRef1" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料编码 ：'">
        <el-input v-model="searchData.partNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'计划日期：'">
        <el-date-picker
          style="width: 130px"
          v-model="searchData.startDate1"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item style="margin-top: 30px;">
        <laber style="margin-left: -9px;font-size: 19px">&#10142</laber>
      </el-form-item>
      <el-form-item style="margin-top: 30px;">
        <el-date-picker
          style="width: 130px"
          v-model="searchData.endDate1"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-button @click="search()" style="margin-left: 0px;margin-top: 33px" 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>
    <el-table
      :height="height"
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="left"
        min-width="80"

        label="日计划单号">
      </el-table-column>
      <el-table-column
        prop="orderDate"
        header-align="center"
        align="left"
        min-width="70"
        label="计划日期">
      </el-table-column>
      <el-table-column
        prop="orderRef1"
        header-align="center"
        align="left"
        min-width="90"
        label="订单号">
      </el-table-column>
      <el-table-column
        prop="partNo"
        header-align="center"
        align="left"
        min-width="70"
        label="物料编码">
      </el-table-column>
      <el-table-column
        prop="partDescription"
        header-align="center"
        align="left"
        min-width="200"
        label="物料名称">
      </el-table-column>
      <el-table-column
        prop="orderQty"
        header-align="center"
        align="right"
        min-width="50"
        label="计划数量">
      </el-table-column>
      <el-table-column
        prop="qtyfinished"
        header-align="center"
        align="right"
        min-width="50"
        label="已完工数">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="left"
        min-width="50"
        label="录入人">
      </el-table-column>
      <el-table-column
        prop="enterDate"
        header-align="center"
        align="left"
        min-width="100"
        label="录入时间">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import {
    getDailyPlanData
  } from "@/api/production.js"

  export default {
    name: 'searchDailyPlan',
    data () {
      return {
        // 导出 start
        exportData: [],
        exportDataStandard: {
          "日计划单号": "orderNo",
          "计划日期": "orderDate",
          "订单号": "orderRef1",
          "物料编码": "partNo",
          "物料名称": "partDescription",
          "计划数量": "orderQty",
          "已完工数": "qtyfinished",
          "录入人": "userName",
          "录入时间": "enterDate"
        },
        exportName: "日计划列表"+this.getStrDate(),
        exportHeader: ["日计划列表"],
        exportFooter: [],
        exportDefaultValue: "这一行这一列没有数据",
        // 导出 end
        height:200,
        tableData:[],
        date1:'',
        searchData:{
          orderNo:'',
          orderRef1:'',
          partNo:'',
          startDate1:new Date(),
          endDate1:'',
          status:'all',
          site:this.$store.state.user.site,
        },
      }
    },
    mounted() {
      this.$nextTick(()=>{
        this.height = window.innerHeight - 210;
      })
    },
    methods: {
      search(){
        getDailyPlanData(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;

      }


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

<style scoped>

</style>
