<template>
  <div>
    <el-form :model="formData" class="query-form" size="mini" label-width="100px" :inline="true">
      <el-form-item prop="invWarehouseCode" label="当前仓库:">
        <el-input disabled :value="formData.invName"></el-input>
      </el-form-item>

      <el-form-item prop="invWarehouseCode" label="单号:">
        <el-input :value="formData.orderId" clearable placeholder="请输入单号"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button-group style="margin-left: 10px;display:flex;">
          <el-button type="primary" icon="el-icon-refresh" @click.native.stop="reset()">重置</el-button>
          <el-button type="primary" icon="el-icon-search" @click.native.stop="search()">查询</el-button>
          <el-button type="primary" icon="el-icon-check" @click.native.stop="check()">选入</el-button>
        </el-button-group>
      </el-form-item>

    </el-form>

    <el-table v-loading="loading" :data="list" style="width: 100%;margin-top: 20px;"
              highlight-current-row
              @current-change="checkedOrder"
              border max-height="300" height="300">
      <el-table-column label="序号" type="index" width="50"></el-table-column>
      <el-table-column label="单号" prop="billNo" width="150"></el-table-column>
      <el-table-column label="单据类型" prop="billTypeName" width="150"></el-table-column>
      <el-table-column label="出入库类型" prop="mainAction" width="150">
        <template slot-scope="scope">
          {{ mainActionNames[scope.row.mainAction] }}
        </template>
      </el-table-column>
      <el-table-column label="往来单位" prop="fromName" width="150"></el-table-column>
      <el-table-column label="来源单号" prop="corpOrderId" width="150"></el-table-column>
      <el-table-column label="单据来源" prop="fromType" width="150">
        <template slot-scope="scope">
          <span>{{ sourceMap[scope.row.fromType] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
      <el-table-column label="验收时间" prop="auditTime" width="150"></el-table-column>
      <el-table-column label="审核人" prop="reviewUserName" width="150"></el-table-column>
    </el-table>

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

</template>

<script>
import {getInvPlaceOrderList} from "@/api/inventory/invPlace";
import {isBlank} from "@/utils/strUtil";

export default {
  props: {
    closeDialog: {
      type: Function,
      required: true
    },
    formData: {
      type: Object,
      required: true
    },
    getInvProductInfo: {
      type: Function,
      required: true
    }
  },
  name: "InvPlaceSelectOrder",
  data() {
    return {
      filterQuery: {
        invCode: this.formData.invCode,
        orderId: null,
        page: 1,
        limit: 10
      },
      list: [],
      total: 0,
      codeArray: [],
      invList: [],
      loading: false,
      orderDialogVisible: false,
      mainActionNames: {
        WareHouseIn: "入库",
        WareHouseOut: "出库"
      },
      sourceMap: {
        "1": "UDIMS平台",
        "2": "网页新增",
        "3": "pda已校验",
        "4": "pda未校验",
        "5": "pc端扫码精灵",
        "6": "单据流转",
        "7": "供应商平台",
        "8": "平衡补单",
        "9": "单据验收直接补单",
        "10": "单据复制",
        "11": "盘点单据转单",
        "12": "申购计划转单",
        "13": "领用单据转单",
        "14": "第三方单据转单",
      },
      checkOrderId: null
    }
  },
  methods: {
    reset() {
      this.filterQuery.orderId = null;
      this.filterQuery.page = 1;
      this.list = [];
      this.checkOrderId = null;
      this.getList();
    },
    search() {
      this.filterQuery.page = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      getInvPlaceOrderList(this.filterQuery).then((res) => {
        this.loading = false;
        if (res.code === 20000) {
          this.list = res.data.list || [];
          this.total = res.data.total || 0;
        } else {
          this.list = [];
          this.total = 0;
        }
      }).catch((error) => {
        this.loading = false;
        this.list = [];
        this.total = 0;
      });
    },
    check() {
      if (isBlank(this.checkOrderId)) {
        this.$message.error("请选择单据");
        return;
      }
      this.getInvProductInfo(this.checkOrderId);
      this.closeDialog();
    },
    checkedOrder(order) {
      this.checkOrderId = order.billNo;
    },
  },
  created() {
    this.getList();
  },
}
</script>

<style scoped>

</style>
