<template>
  <div>
    <el-form :model="query" class="query-form" size="mini">
      <el-col :span="14">
        <el-form-item class="query-form-item" label="UDI码：" label-width="100px">
          <el-input v-model="query.code" placeholder="条码查询"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item style="margin-left: 20px">
          <el-button-group>
            <el-button type="primary" icon="el-icon-search" @click="getCodeList"
            >查询
            </el-button
            >
          </el-button-group>
        </el-form-item>
      </el-col>
    </el-form>
    <el-table v-loading="loading" :data="codeArry" style="width: 100%" border>
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column
        label="条码"
        prop="code"
        width="300"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="生产日期"
        prop="produceDate"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="失效日期"
        prop="expireDate"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="批次号"
        prop="batchNo"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="序列号"
        prop="serialNo"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="扫码数量"
        prop="count"
        width="180"
        show-overflow-tooltip
      ></el-table-column>
    </el-table>

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

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="query.page"
      :limit.sync="query.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import draggable from "vuedraggable";
import {findByOrderId} from "@/api/inout/code";

export default {
  name: "idQuery",
  props: {
    idQuery: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      query: {
        code: "",
        orderId:"",
        corpOrderId: "",
        page: 1,
        limit: 20,
      },
      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:"",
        corpOrderId: "",
        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;
      this.query.orderId = this.idQuery.billNo;
      findByOrderId(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.orderNo = query.id;

    this.query = Object.assign(this.query, query);
    this.query.limit = parseInt(this.query.limit);
    this.query.corpOrderId = query.id;

    // 加载表格数据
    this.getCodeList();
  },
};
</script>



