<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="SAP订单产线" prop="productLineCode">
        <el-select v-model="queryParams.productLineCode" placeholder="请选择SAP订单产线" clearable>
          <el-option
            v-for="item in productLineList"
            :key="item.productLineCode"
            :label="item.productLineName"
            :value="item.productLineCode"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="公司条码" prop="productSncode">-->
<!--        <el-input-->
<!--          v-model="queryParams.productSncode"-->
<!--          placeholder="请输入公司条码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="SAP计划编号" prop="productOrderNo">
        <el-input
          v-model="queryParams.productOrderNo"
          placeholder="请输入SAP计划编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品型号" prop="productModel">
        <el-input
          v-model="queryParams.productModel"
          placeholder="请输入产品型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="泡前入库时间">
        <el-date-picker
          v-model="daterangeBeginTime"
          style="width: 340px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="boxTraceabilityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" v-if="false"/>
      <el-table-column label="主键标识" align="center" prop="objId" v-if="columns[0].visible"/>
      <el-table-column label="工厂" align="center" prop="factoryName" v-if="columns[1].visible" width="110"/>
      <el-table-column label="产线" align="center" prop="productLineName" v-if="columns[2].visible"/>
      <el-table-column label="SAP计划编号" align="center" prop="ORDER_CODE" v-if="columns[3].visible" width="120"/>
      <el-table-column label="销售订单号" align="center" prop="SALEORDER_CODE" v-if="columns[4].visible"/>
      <el-table-column label="销售行号" align="center" prop="SALEORDER_LINENUMBER" v-if="columns[5].visible"/>
      <el-table-column label="物料编码" align="center" prop="MATERIAL_CODE" v-if="columns[6].visible" width="100"/>
      <el-table-column label="产品型号" align="center" prop="MATERIAL_MODEL" v-if="columns[7].visible" width="140"/>
      <el-table-column label="订单数" align="center" prop="ORDER_AMOUNT" v-if="columns[8].visible" width="120"/>
      <el-table-column label="泡前入库数" align="center" prop="BEFORE_NUMBER" v-if="columns[9].visible" width="100"/>
      <el-table-column label="成品下线数" align="center" prop="SCAN_NUMBER" v-if="columns[10].visible"/>
      <el-table-column label="差异数" align="center" prop="DIFF_NUMBER" v-if="columns[11].visible"/>
      <el-table-column label="报废记录数" align="center" prop="SCRAP_NUMBER" v-if="columns[12].visible"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { findProductLineList } from '@//api/base/productLine'
import { parseTime } from '@//utils/ruoyi'
import { boxTraceabilityReport } from '@//api/report/reportAPI'
export default {
  name: "ProductOffLine",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 扫描下线记录报表表格数据
      boxTraceabilityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productFactoryCode: null,
        productSncode: null,
        productOrderNo: null,
        productSaleNo: null,
        productSaleLineNo: null,
        productCode: null,
        productModel: null,
        productName: null,
        productType: null,
        productCheckInfo: null,
        productRemark: null,
        productBarNo: null,
        productMasterModel: null,
        productVersion: null,
        productUserinfo: null,
        productCirculate: null,
        productCreatedate: null,
        productScantime: null,
        boxCode: null,
        beginBeginTime: null,
        endBeginTime: null,
        productLineCode: 'CX_02'
      },
      // 更新时间时间范围
      daterangeBeginTime: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      columns: [
        { key: 0, label: `主键标识`, visible: false },
        { key: 1, label: `工厂`, visible: false },
        { key: 2, label: `产线`, visible: false },
        { key: 3, label: `SAP计划编号`, visible: true },
        { key: 4, label: `销售订单号`, visible: true },
        { key: 5, label: `销售行号`, visible: true },
        { key: 6, label: `物料编码`, visible: true },
        { key: 7, label: `产品型号`, visible: true },
        { key: 8, label: `订单数`, visible: true },
        { key: 9, label: `泡前入库数`, visible: true },
        { key: 10, label: `成品下线数`, visible: true },
        { key: 11, label: `差异数`, visible: true },
        { key: 12, label: `报废记录数`, visible: true },
      ],
      // 产线选项
      productLineList: [],
    };
  },
  created() {
    findProductLineList({productLineType: 1}).then(response => {
      this.productLineList = response.data
    })
    const nowDate = parseTime(new Date(), '{y}-{m}-{d}')
    this.daterangeBeginTime[0] = nowDate + ' 00:00:00'
    this.daterangeBeginTime[1] = nowDate + ' 23:59:59'
    this.getList();
  },
  methods: {
    /** 查询扫描下线记录报表列表 */
    getList() {
      this.loading = true;
      if (null != this.daterangeBeginTime && '' != this.daterangeBeginTime) {
        this.queryParams.beginBeginTime = this.daterangeBeginTime[0]
        this.queryParams.endBeginTime = this.daterangeBeginTime[1]
      } else {
        this.queryParams.beginBeginTime = null
        this.queryParams.endBeginTime = null
      }
      boxTraceabilityReport(this.queryParams).then(response => {
        this.boxTraceabilityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        objId: null,
        productFactoryCode: null,
        productSncode: null,
        productOrderNo: null,
        productSaleNo: null,
        productSaleLineNo: null,
        productCode: null,
        productModel: null,
        productName: null,
        productType: null,
        productCheckInfo: null,
        productRemark: null,
        productBarNo: null,
        productMasterModel: null,
        productVersion: null,
        productUserinfo: null,
        productCirculate: null,
        productCreatedate: null,
        productScantime: null,
        boxCode: null,
        productLineCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.objId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('report/productionReport/boxTraceabilityReport/export', {
        ...this.queryParams
      }, `productOffLine_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
