<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="产线" prop="productLineCode">
        <el-select v-model="queryParams.productLineCode" placeholder="请选择产线" 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="linerCode">
        <el-input
          v-model="queryParams.linerCode"
          placeholder="请输入内胆码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="SAP订单编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          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="boxCode">
        <el-input
          v-model="queryParams.boxCode"
          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="info"
          plain
          size="mini"
        >绑定数：{{ totalSum }}
        </el-button>
      </el-col>
      <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="codeBandingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" v-if="false"/>
      <el-table-column label="箱体码" align="center" prop="BOX_CODE" width="110"/>
      <el-table-column label="箱体型号" align="center" prop="BOX_NAME" width="110"/>
      <el-table-column label="内胆码" align="center" prop="LINER_CODE"  width="110"/>
      <el-table-column label="内胆型号" align="center" prop="LINER_NAME" />
      <el-table-column label="SAP订单编号" align="center" prop="ORDER_CODE" width="100"/>
      <el-table-column label="产线编号" align="center" prop="PRODUCT_LINE_CODE" width="80"/>
      <el-table-column label="产线名称" align="center" prop="PRODUCT_LINE_NAME" width="80"/>
      <el-table-column label="壳胆绑定时间" align="center" prop="RECORD_TIME1" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.RECORD_TIME1, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产品SN码" align="center" prop="PRODUCT_CODE" width="100"/>
      <el-table-column label="产品SN码绑定时间" align="center" prop="RECORD_TIME2" width="180" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.RECORD_TIME2, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>

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


  </div>
</template>

<script>
import { listCodeBanding } from "@/api/report/codeBanding";
import { findProductLineList } from '@//api/base/productLine'
import { parseTime } from '@//utils/ruoyi'
export default {
  name: "ProductOffLine",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 壳胆绑定集合
      codeBandingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      totalSum: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productLineCode: 'CX_02',
        orderCode:null,
        boxCode:null,
        boxName:null,
        linerCode:null,
        linerName:null,
        recordTime1:null,
        recordTime2:null,
        productCode:null,
        recordBeginTime:null,
        recordEndTime:null
      },
      // 更新时间时间范围
      daterangeBeginTime: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      columns: [
        { key: 0, label: `主键标识`, visible: false },
        { key: 1, label: `工厂`, visible: true },
        { key: 2, label: `公司条码`, visible: true },
        { key: 3, label: `工单号`, visible: true },
        { key: 4, label: `销售订单号`, visible: false },
        { key: 5, label: `销售行号`, visible: false },
        { key: 6, label: `物料编码`, visible: true },
        { key: 7, label: `产品型号`, visible: false },
        { 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 },
        { key: 13, label: `主型号`, visible: true },
        { key: 14, label: `版本号`, visible: true },
        { key: 15, label: `用途位`, visible: true },
        { key: 16, label: `流通特性`, visible: true },
        { key: 17, label: `生成日期`, visible: true },
        { key: 18, label: `扫描时间`, visible: true },
        { key: 19, label: `箱体码`, visible: true },
        { key: 20, 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.recordBeginTime = this.daterangeBeginTime[0]
        this.queryParams.recordEndTime = this.daterangeBeginTime[1]
      } else {
        this.queryParams.recordBeginTime = null
        this.queryParams.recordEndTime = null
      }
      listCodeBanding(this.queryParams).then(response => {
        this.codeBandingList = response.rows;
        this.total = response.total;
        this.totalSum = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        objId: null,
        orderCode:null,
        boxCode:null,
        boxName:null,
        linerCode:null,
        linerName:null,
        recordTime1:null,
        recordTime2:null,
        productCode:null,
        productLineCode: null,
        recordBeginTime:null,
        recordEndTime: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/codeBandingReportList/export', {
        ...this.queryParams
      }, `productOffLine_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
