<template>
  <div class="customer-css">
    <!--  查询时间和产品  -->
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 5px;">
      <el-form-item :label="'工厂编号:'">
        <el-input v-model="searchData.site" style="width: 85px"></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-input v-model="searchData.resourceId" style="width: 110px"></el-input>
      </el-form-item>
      <el-form-item :label="'计划日期:'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.date1"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.date2"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </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="''" style="margin-left: -5px;">
        <el-checkbox style="margin-top: 20px;" true-label="Y" false-label="N" v-model="searchData.closedFlag">显示已关闭计划
        </el-checkbox>
      </el-form-item>
      <el-form-item :label="' '" style="margin-left: -5px;">
        <el-button type="primary" @click="refreshTables()" class="customer-bun-mid"
                   style="margin-left: 10px;  margin-bottom: 5px;">查询
        </el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          导出
        </download-excel>
      </el-form-item>
      <div class="mainTable">
        <el-table :height="height"
                :data="dataList"
                :row-class-name="routingRowClassName2"
                border
                v-loading="dataListLoading"
                style="width: 100%;">
        <el-table-column
          prop=""
          header-align="center"
          align="center"
          width="70"
          label="操作">
          <template slot-scope="scope" class="foo_container">
            <a type="text" size="small" @click="printAction(scope.row)">打印标签</a>
          </template>
        </el-table-column>
        <el-table-column
          v-for="(item,index) in columnArray" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed"
          :width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
      </el-table>
      </div>
    </el-form>
  </div>
</template>

<script>
  import {
    getProduceScheduleList
  } from '@/api/production/dailyPlan.js'
  import {
    printSerialNo
  } from '@/api/production/pallet.js'
  export default {
    name: 'search_schedule',
    data () {
      return {
        // 导出 start
        exportData: [],
        exportName: "排产日计划清单"+this.dayjs().format('YYYYMMDDHHmmss'),
        exportFooter: [],
        // 导出 end
        height:200,
        dataList:[],
        dataListLoading: false,
        columnArray: [
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceScheduledDate',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "scheduledDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "排产日期",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceItemDesc',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "printFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "是否打印",
            columnWidth: 60,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceOrderNo',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "orderNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "生产订单号",
            columnWidth: 120,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceItemNo',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "itemNo",
            headerAlign: "center",
            align: "right",
            columnLabel: "工序号",
            columnWidth: 50,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceItemDesc',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "itemDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "工序描述",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceResourceId',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "resourceId",
            headerAlign: "center",
            align: "left",
            columnLabel: "机台",
            columnWidth: 60,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceTimeRequired',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "timeRequired",
            headerAlign: "center",
            align: "right",
            columnLabel: "需求时间",
            columnWidth: 60,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceTimeReported',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "timeReported",
            headerAlign: "center",
            align: "right",
            columnLabel: "已报告时间",
            columnWidth: 70,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceQtyRequired',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "qtyRequired",
            headerAlign: "center",
            align: "right",
            columnLabel: "需求数量",
            columnWidth: 60,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceQtyReported',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "qtyReported",
            headerAlign: "center",
            align: "right",
            columnLabel: "已报告数量",
            columnWidth: 70,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceNeedDate',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "needDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "生产订单要求完工日期",
            columnWidth: 130,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceClosedFlag',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "closedFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "已关闭",
            columnWidth: 50,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProducePartNo',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "partNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "产品编码",
            columnWidth: 110,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProducePartDesc',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "partDesc",
            headerAlign: "center",
            align: "left",
            columnLabel: "产品名称",
            columnWidth: 180,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceSpec',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "spec",
            headerAlign: "center",
            align: "left",
            columnLabel: "规格型号",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceSeqNo',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "seqNo",
            headerAlign: "center",
            align: "right",
            columnLabel: "次序号",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceQtyApprove',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "qtyApprove",
            headerAlign: "center",
            align: "right",
            columnLabel: "合格数量",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 5302,
          //   serialNumber: '5302ProduceBarcodeId',
          //   tableId: "5302Produce",
          //   tableName: "条形码",
          //   columnProp: "barcodeId",
          //   headerAlign: "center",
          //   align: "left",
          //   columnLabel: "条形码",
          //   columnWidth: 80,
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceRemark',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "remark",
            headerAlign: "center",
            align: "left",
            columnLabel: "备注",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceCrewSize',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "crewSize",
            headerAlign: "center",
            align: "right",
            columnLabel: "操作工人数",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceQtyScrapt',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "qtyScrapt",
            headerAlign: "center",
            align: "right",
            columnLabel: "报废数量",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceOutWorkFlag',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "outWorkFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "是否外协",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 5302,
          //   serialNumber: '5302ProduceScheduledSeqNo',
          //   tableId: "5302Produce",
          //   tableName: "待生产工单",
          //   columnProp: "scheduledSeqNo",
          //   headerAlign: "center",
          //   align: "right",
          //   columnLabel: "次序号",
          //   columnWidth: 80,
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceShiftNo',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "shiftNo",
            headerAlign: "center",
            align: "left",
            columnLabel: "班次",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceMachSetupTime',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "machSetupTime",
            headerAlign: "center",
            align: "right",
            columnLabel: "调机时间",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceMachRunFactor',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "machRunFactor",
            headerAlign: "center",
            align: "right",
            columnLabel: "单位产出",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceFactorUnit',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "factorUnit",
            headerAlign: "center",
            align: "right",
            columnLabel: "产出单位",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceEfficiency',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "efficiency",
            headerAlign: "center",
            align: "right",
            columnLabel: "效率",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceSite',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "site",
            headerAlign: "center",
            align: "left",
            columnLabel: "工厂编号",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceParkFlag',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "parkFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "暂停",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 5302,
          //   serialNumber: '5302ProduceCustomerName',
          //   tableId: "5302Produce",
          //   tableName: "待生产工单",
          //   columnProp: "customerName",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "客户名称",
          //   columnWidth: 80,
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 5302,
          //   serialNumber: '5302ProduceCustPartNo',
          //   tableId: "5302Produce",
          //   tableName: "待生产工单",
          //   columnProp: "custPartNo",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "客户产品料号",
          //   columnWidth: 80,
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          // {
          //   userId: this.$store.state.user.name,
          //   functionId: 5302,
          //   serialNumber: '5302ProduceQtyRequiredOriginal',
          //   tableId: "5302Produce",
          //   tableName: "待生产工单",
          //   columnProp: "qtyRequiredOriginal",
          //   headerAlign: "center",
          //   align: "center",
          //   columnLabel: "原始派工单需求数量",
          //   columnWidth: 80,
          //   columnHidden: false,
          //   columnImage: false,
          //   columnSortable: false,
          //   sortLv: 0,
          //   status: true,
          //   fixed: false
          // },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceClosedBy',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "closedBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "关闭人",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceClosedDate',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "closedDate",
            headerAlign: "center",
            align: "left",
            columnLabel: "关闭日期",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            userId: this.$store.state.user.name,
            functionId: 5302,
            serialNumber: '5302ProduceCostRollUpFlag',
            tableId: "5302Produce",
            tableName: "待生产工单",
            columnProp: "costRollUpFlag",
            headerAlign: "center",
            align: "left",
            columnLabel: "已排料",
            columnWidth: 80,
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
        ],
        searchData:{
          site:'',
          partNo:'',
          resourceId:'',
          date1:'',
          date2:'',
          orderNo:'',
          closedFlag:'',
        },
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 160
      })
    },
    methods: {
      //导出excel
      createExportData() {

        return this.dataList;

      },
      startDownload() {
        //  this.exportData = this.dataList

      },
      finishDownload() {

      },
      fields() {
        let json = "{"
        this.columnArray.forEach((item, index) => {
          if (index == this.columnArray.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")

        return s
      },
      // 导出 end
      refreshTables(){
        getProduceScheduleList(this.searchData).then(({data}) => {
          //设置查询数据
          this.dataList = data.rows;
        })
      },
      printAction(row){
        let array=[];
        let data={
          site:row.site,
          orderNo:row.orderNo,
          itemNo:row.itemNo,
          scheduleDate:row.scheduledDate,
          shiftNo:row.shiftNo,
         }
        array.push(data);
        printSerialNo(array).then(({data}) => {
          if(data.code===200){
            this.$message({
              message: '打印成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          }else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      },
      routingRowClassName2({row, rowIndex}){

        //判断当前行颜色参数
        if(row.printFlag=="Y"){
          return 'customer-row-2';
        }
      },

  }
</script>

<style scoped>

</style>
