<template>
  <div>
    <el-form :inline="true" :model="query" class="query-form" size="mini">
      <el-form-item class="query-form-item">
        <el-input v-model="query.code" placeholder="搜索"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button-group>
          <el-button type="primary" icon="search" @click="getCodeList"
            >查询</el-button
          >
          <el-button type="primary" icon="search" @click="intentBack"
            >返回</el-button
          >
        </el-button-group>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="codeArry" style="width: 100%">
      <el-table-column
        label="生产订单ID"
        prop="orderId"
        fixed
      ></el-table-column>
      <el-table-column label="追溯码" prop="code" fixed></el-table-column>
      <el-table-column label="父追溯码" prop="pcode" fixed> </el-table-column>
      <el-table-column label="码状态" prop="packFlag" fixed></el-table-column>
      <el-table-column label="批次号" prop="batchNo" fixed></el-table-column>
      <el-table-column label="生产日期" prop="manufacturingDate" fixed></el-table-column>
      <el-table-column label="失效日期" prop="expirationDate" fixed></el-table-column>
      <el-table-column label="层级" prop="codeLevel" fixed></el-table-column>
      <el-table-column label="最后修改时间" prop="lastModifyTime" fixed></el-table-column>
    </el-table>

    <el-pagination
      :page-size="query.limit"
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { filterBarcodes } from "../../api/receipts/mipsOrder";
import draggable from "vuedraggable";
import { saveAs } from "file-saver";

export default {
  data() {
    return {
      query: {
        code: "",
        orderId: "",
        page: 1,
        limit: 20,
      },
      wareHouseMap: {
        ProduceWareHouseIn: "生产入库",
        SalesWareHouseOut: "销售出库",
        AllocateWareHouseIn: "调拨入库",
        PurchaseWareHouseIn: "采购入库",
        ReturnWareHouseOut: "退货入库",
        ProduceWareHouseOut: "销售出库",
        AllocateWareHouseIn: "退货出库",
        AllocateWareHouseOut: "调拨出库",
        ReworkWareHouseOut: "返工出库",
        DestoryWareHouseOut: "销毁出库",
        CheckWareHouseOut: "抽检出库",
        DirectAllocateWareHouseOut: "直调出库",
        CodeReplace: "码替换",
        CodeDestory: "码注销",
        StockCheck: "盘点",
      },
      codeArry: [],
      total: 0,
      loading: true,
      index: null,
      formLoading: false,
      formVisible: false,
      deleteLoading: false,
      orderNo: null,
    };
  },
  components: {
    draggable,
  },
  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.query = {
        code: "",
        orderId: "",
        page: 1,
        limit: 20,
      };
      this.getCodeList();
    },
    onSubmit() {
      this.$router.push({
        path: "",
        query: this.query,
      });
      this.getCodeList();
    },
    handleSizeChange(val) {
      this.query.limit = val;
      this.getCodeList();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getCodeList();
    },

    getCodeList() {
      this.loading = true;

      filterBarcodes(this.query) //查找该单号下的所有条码
        .then((response) => {
          this.loading = false;
          this.codeArry = response.data.list || [];
          this.total = response.data.total || 0;
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
    intentBack() {
      //  this.$router.push({path:'../readme/detail',query:{id:row.corpOrderId}});
      this.$router.go(-1);
    },
  },
  filters: {},
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  },
  created() {
    let query = this.$route.query;
    this.query.orderId = query.id;
    this.getCodeList();
  },
};
</script>

<style type="text/scss" lang="scss">
</style>
