<template>
  <div>

    <el-form :model="formData" :rules="formRules" ref="dataForm">
      <el-row type="flex" justify="end">
        <el-button-group style="display: flex;margin-bottom: 15px; margin-right: 50px">
          <el-button
              type="primary"
              @click.native="saveOrder('1')"
              :loading="loading"
          >草稿保存
          </el-button
          >
          <el-button
              type="primary"
              @click.native="saveOrder('2')"
              :loading="loading"
          >提交单据
          </el-button
          >
        </el-button-group>
      </el-row>

      <el-card style="margin-top: -5px;">
        <el-row :gutter="20" style="margin-top: 10px;">
          <el-col :span="3">
            <div class="ao-text">
              <span>单据号：</span>
            </div>
          </el-col>
          <el-col :span="7">
            <el-form-item prop="billNo">
              <el-input v-model="formData.billNo" auto-complete="off" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <div class="ao-text">
              <span>单据日期：</span>
            </div>
          </el-col>
          <el-col :span="7">
            <el-form-item prop="billdate">
              <el-date-picker
                  v-model="formData.billdate"
                  type="datetime"
                  placeholder="选择日期"
                  style="width: 100%"
                  :clearable="false"
                  value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20" style="margin-top: -10px">
          <el-col :span="3">
            <div class="ao-text">
              <span>业务类型：</span>
            </div>
          </el-col>
          <el-col :span="7">
            <el-form-item prop="billType">
              <el-select v-model="formData.billType" placeholder="请选择业务类型"
                         @change="actionChange" clearable>
                <el-option
                    v-for="item in busTypes"
                    :key="item.thirdAction"
                    :label="item.thirdName"
                    :value="item.thirdAction">
                  <span style="float: left">{{ item.thirdName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="3">
            <div class="ao-text">
              <span>往来单位：</span>
            </div>
          </el-col>
          <el-col :span="7">
            <el-form-item class="query-form-item" prop="fromCorp">
              <el-select
                  v-model="formData.corpName"
                  filterable
                  remote
                  clearable="true"
                  reserve-keyword
                  placeholder="请输入往来单位"
                  :remote-method="findStorageMethod"
                  :loading="loading"
                  @change="storageChange"
              >
                <el-option
                    v-for="item in fromStorageOptions"
                    :key="item.value"
                    :label="item.code"
                    :value="item">
                  <span style="float: left">{{ item.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                      item.code
                    }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="20" style="margin-top: -10px">


          <el-col :span="3">
            <div class="ao-text">
              <span>当前分库：</span>
            </div>
          </el-col>

          <el-col :span="7">
            <el-form-item prop="invWarehouseCode">
              <el-select v-model="formData.invWarehouseCode" placeholder="当前分库信息"
                         clearable>
                <el-option
                    v-for="item in subInvList"
                    :key="item.name"
                    :label="item.name"
                    :value="item.code">
                  <span style="float: left">{{ item.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.warehouseName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
      </el-card>

      <el-card>
        <el-button-group style="display: flex">
          <el-button
              type="primary"
              size="small"
              @click.native.stop="selectProductFunction()"
              style="margin: 0px 60px 10px auto; height: 35px"
              :loading="loading"
          >产品录入
          </el-button
          >
        </el-button-group>

        <el-table v-loading="loading" :data="codeArray" style="width: 100%;"
                  :row-class-name="tableRowClassName"
                  max-height="300" height="300" ref="multipleTable">
          <el-table-column label="序号" type="index" width="50"></el-table-column>
          <el-table-column width="150"
                           label="产品通用名"
                           prop="productName"
                           show-overflow-tooltip
          ></el-table-column>
          <el-table-column width="150"
                           label="规格型号"
                           prop="spec"
                           show-overflow-tooltip
          ></el-table-column>
          <el-table-column width="150" label="批次号">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.batchNo"
                        :disabled="scope.row.index !== selectedIndex"
                        @input="scope.row.batchNo =scope.row.batchNo.replace(/[\W]/g, '')"
                        ref='inputBatchNoRef'
                        placeholder="请输入批次号" style="width: 80%"></el-input>
            </template>
          </el-table-column>
          <el-table-column width="180" label="生产日期(yyMMdd)">
            <template slot-scope="scope">

              <el-input v-model="scope.row.productDate" auto-complete="off"
                        oninput="if(value.length>6)value=value.slice(0,6)"
                        :disabled="scope.row.index !== selectedIndex"
                        type="number"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column width="180" label="失效日期(yyMMdd)">
            <template slot-scope="scope">

              <el-input v-model="scope.row.expireDate" auto-complete="off"
                        oninput="if(value.length>6)value=value.slice(0,6)"
                        :disabled="scope.row.index !== selectedIndex"
                        type="number"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column width="150" label="单据数量">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.count"
                        placeholder="请输入数量" style="width: 80%"
                        type='number'
                        @change="tableCountChange(scope.row)"
                        :disabled="scope.row.index !== selectedIndex"
                        oninput="value=value.replace(/[^\d]/g,'')"></el-input>
            </template>
          </el-table-column>
          <el-table-column width="150" label="价格">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.price"
                        type='number'
                        :disabled="scope.row.index !== selectedIndex"
                        placeholder="请输入价格" style="width: 80%"
              ></el-input>
            </template>
          </el-table-column>

          <el-table-column width="150"
                           label="注册/备案凭证号"
                           prop="zczbhhzbapzbh"
                           show-overflow-tooltip
          ></el-table-column>
          <el-table-column width="150"
                           label="生产厂家"
                           prop="ylqxzcrbarmc"
                           show-overflow-tooltip
          ></el-table-column>
          <el-table-column label="操作" fixed="right" width="150">
            <template slot-scope="scope">

              <el-button
                  type="text"
                  size="small"
                  :disabled="scope.row.index === selectedIndex"
                  @click.stop="true"
                  @click.native="rowChange(scope.row)"
              >编辑
              </el-button
              >
              <el-button
                  type="text"
                  size="small"
                  @click.stop="true"
                  @click.native="copyDetail(scope.row)"
              >复制
              </el-button
              >
              <el-button
                  type="text"
                  size="small"
                  @click.stop="true"
                  @click.native="deleteCodeArray(scope.$index, scope.row)"
              >删除
              </el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </el-form>

    <el-dialog
        title="产品录入"
        :visible.sync="selectProductVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="85%"
        v-if="selectProductVisible"
        :append-to-body='true'
    >
      <stockOrderNewSelectProduct
          :closeDialog="closeDialogC2"
          :data="thisData"
      ></stockOrderNewSelectProduct>
    </el-dialog>

    <el-dialog
        title="库存产品录入"
        :visible.sync="selectInvProductVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="85%"
        v-if="selectInvProductVisible"
        :append-to-body='true'
    >
      <dialogInvProduct
          :closeDialog="closeDialogC2"
          :data="thisData"
          :invQueryData="invQueryData"
      ></dialogInvProduct>
    </el-dialog>
  </div>
</template>

<script>
import {
  stockOrderDetail,
  submitStockOrder,
  stockOrderGenerateBillNo,
  getStockOrderDetailInstrument,
  insertStockOrderWeb,
  deleteStockOrderDetailById,
  addStockOrderDetailFromCode,
  uploadStockOrderDetail,
  stockOrderDetailQueryProduct,
  getStockOrderDetailInstrumentById, stockOrderDetail2, generateBillNoInt
} from "../../api/warehouse/stockOrder";
import draggable from "vuedraggable";
import {saveAs} from "file-saver";
import {parseTime} from "../../filtres";
import store from "../../store";
import stockOrderNewSelectProduct from "../warehouse/stockOrderNewSelectProduct";
import {getBasicUnitMaintains, getBasicUnitMaintains2} from "../../api/basic/basicUnitMaintain";
import {getBussinessType} from "../../api/basic/bussinessType";
import {getLocalBusType, getLocalJoinBusType, getLocalJoinByUser} from "../../api/basic/busLocalType";
import {filterAll, filterAllByLoc, filterAllByUser} from "@/api/basic/invWarehouse";
import dialogInvProduct from "../inventory/DialogInvProduct"
import {getOriginJoinBusType} from "@/api/basic/busOriginType";
import {inserThrOrderWeb} from "@/api/thrsys/thrOrderReceive";
import {getThrOrderDetails, delThrOrders, delOrderDetail} from "@/api/thrsys/thrOrder";
import {filterSubByInv} from "@/api/basic/invSubWarehouse";

export default {
  name: "idQuery",
  props: {
    closeDialog: {
      type: Function,
      required: true,
    },
    idQuery: {
      type: Object,
      required: true,
    },
    closeConfirmFunction: {
      type: Function,
      required: true,
    },
  },
  data() {
    return {
      code: "",
      query: {
        orderIdFk: "",
        page: 1,
        limit: 10,
      },
      formData: {
        noInvOut: false,
        locStorageCode: null,
        invWarehouseCode: null,
        fromSubInvCode: null,
        billNo: null,
        billdate: "",
        billType: "",
        type: null,
        corpName: "",
        corpId: "",
      },
      formRules: {
        corpName: [
          {required: true, message: "请输入供应商", trigger: "blur"}
        ],
        billdate: [
          {required: true, message: "请输入单据日期", trigger: "blur"}
        ],
        billType: [
          {required: true, message: "请选择业务类型", trigger: "blur"}
        ],
        locStorageCode: [
          {required: true, message: "请选择当前仓库", trigger: "blur"}
        ],
        invWarehouseCode: [
          {required: true, message: "请选择当前分库", trigger: "blur"}
        ],
        // type: [
        //     {required: true, message: "请选择采购类型", trigger: "blur"}
        // ],
      },
      codeArray: [],
      subInvList: [],
      fromOptions: [],
      fromStorageOptions: [],
      total: 0,
      loading: false,
      index: null,
      formLoading: false,
      formVisible: false,
      deleteLoading: false,
      orderNo: null,
      statusMap: {
        101: "未处理",
        102: "已处理",
        201: "未配货",
        202: "已配货",
        301: "已打印",
        401: "异常",
        501: "未提交",
        502: "已提交",
      },
      typeMap: {
        1: "预入库",
        2: "普通采购",
      },
      curAction: {
        corpType: 0,
        genUnit: false,
      },
      orderEditor: true,
      iCount: 0,
      sOptions: [],
      sValue: [],
      sList: [],
      sLoading: false,
      busTypes: [],
      currentRow: {},
      selectedIndex: "",
      selectProductVisible: false,
      selectInvProductVisible: false,
      thisData: {},
      storageList: [],
      invQueryData: {},

    };
  },
  components: {
    draggable,
    stockOrderNewSelectProduct,
    dialogInvProduct,
  },
  methods: {
    saveOrder(status) {

      this.code = "";
      this.$refs.multipleTable.setCurrentRow();
      this.currentRow = {};
      this.selectedIndex = "";
      this.iCount = 0;
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (this.codeArray.length < 1) {
            this.$message.warning('未添加产品');
            return;
          }

          for (let i = 0; i < this.codeArray.length; i++) {
            if (!this.$isBlank(this.codeArray[i].productDate) && this.codeArray[i].productDate.length != 6) {
              return this.$message.error('生产日期格式错误');
            }
            if (!this.$isBlank(this.codeArray[i].expireDate) && this.codeArray[i].expireDate.length != 6) {
              return this.$message.error('失效日期格式错误');
            }

          }

          if (status === '0') {
            for (let i = 0; i < this.codeArray.length; i++) {
              if (this.$isBlank(this.codeArray[i].count) || this.codeArray[i].count == "0") {
                return this.$message.error('单据数量不能为0');
              }
              if (this.$isBlank(this.codeArray[i].batchNo)) {
                return this.$message.error('批次号不能为空');
              }


            }
          }
          if (status === '0') {
            for (let i = 0; i < this.codeArray.length; i++) {
              if (this.$isBlank(this.codeArray[i].count) || this.codeArray[i].count == "0") {
                return this.$message.error('单据数量不能为0');
              }
            }
          }

          if (status == "1") {
            this.submitFunction(status);
          } else {
            let tip = "是否确定提交订单?";
            this.$confirm(tip, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }).then(() => {
              this.submitFunction(status);
            }).catch(() => {
              this.loading = false;
            });
          }


        }
      });
    },
    storageChange(row) {
      console.log(row);
      this.formData.corpId = row.code;
      this.formData.corpName = row.name;
    },
    getStorage(event) {
      this.storageList = [];
      filterAllByUser()
          .then((response) => {
            this.storageList = response.data || [];
            this.findSubInvs();
          })
          .catch(() => {
          });
    },

    getActionName(action) {
      for (let i = 0; i < this.busTypes.length; i++) {
        if (this.busTypes[i].action === action) {
          return this.busTypes[i].advanceType;
        }
      }
    },
    findStorageMethod(query) {
      if (this.formData.locStorageCode == null)
        return;
      this.fromStorageOptions = [];
      let cQuery = {
        locInvCode: this.formData.locStorageCode,
      };
      filterAllByLoc(cQuery)
          .then((response) => {
            let temp = response.data || [];
            for (let i = 0; i < temp.length; i++) {
              if (temp[i].code != this.formData.locStorageCode) {
                this.fromStorageOptions.push(temp[i]);
              }
            }

          })
          .catch(() => {
          });
    },
    submitFunction(status) {
      let tMessage = status === '501' ? '保存' : '提交';
      this.loading = true;
      let tQuery = this.formData;
      tQuery.editStatus = status;
      tQuery.subErpOrders = this.codeArray;
      tQuery.thirdPartyDate = 2;

      // tQuery.billType = this.formData.bi;
      console.log(tQuery);

      inserThrOrderWeb(tQuery)
          .then(response => {
            this.loading = false;
            if (response.code === 20000) {
              this.$message.success(tMessage + "成功");
              this.closeDialog(true);
            } else {
              this.$message.error(response.message);
            }
          })
          .catch(() => {
            this.loading = false;
          })
    },
    selectProductFunction(event) {

      if (event == null) {
        // this.$refs.inputRef.focus();
      } else {
        event.target.select();
      }
      if (this.$isBlank(event)) {

        if (this.$isBlank(this.formData.corpName) || this.$isBlank(this.formData.billType)) {
          this.$message.error("往来信息和单据类型不能为空！")
          return;
        }
        this.code = "";
        this.$refs.multipleTable.setCurrentRow();
        this.currentRow = {};
        this.selectedIndex = "";
        this.iCount = 0;
        this.thisData.code = "";
        this.thisData.orderEditor = this.orderEditor;
        this.thisData.orderId = "";
        if (this.orderEditor) {
          this.thisData.orderId = this.formData.id
        }
        this.curAction = this.getActionItem(this.formData.billType);
        this.thisData.stockOrderLists = this.codeArray;
        this.thisData.formData = this.formData;
        this.thisData.formData.thirdSysFk = this.curAction.thirdSys;
        this.thisData.billType = this.curAction.localAction;


        this.invQueryData = {
          locStorageCode: this.formData.locStorageCode,
        };
        this.selectInvProductVisible = true;

        return;
      }


    },
    closeDialogC2(rData) {
      this.selectProductVisible = false;
      this.selectInvProductVisible = false;
      this.thisData = {};

      if (this.$isNotBlank(rData)) {
        this.codeArray = [];
        rData.forEach((obj, index) => {
          this.codeArray.unshift(obj);
        });
        console.log(this.codeArray);
        this.$refs.multipleTable.setCurrentRow(this.codeArray[0]);
        this.currentRow = this.codeArray[0];
        this.selectedIndex = 0;
        this.focusNext('iCount');
        this.closeConfirmFunction(true);
      }
    },
    rowChange(val) {
      this.currentRow = val;
      this.selectedIndex = val.index;
      this.iCount = val.count;

      this.focusNext('iCount');

    },
    iCountChange() {
    },
    iCountEnterFunction() {
      if (this.$isNotBlank(this.currentRow)) {
        this.currentRow.count = this.iCount;
        // this.currentRow.reCount = this.iCount;
      }
      this.focusNext('inputRef');
    },
    tableCountChange(row) {
      if (this.$isNotBlank(row)) {
        // row.count = row.reCount;
      }
    },
    tableRowClassName({row, rowIndex}) {
      row.index = rowIndex;
    },
    focusNext(nextRef) {
      this.$refs[nextRef].focus()
    },
    focusNextToTable(nextRef) {
      this.$refs[nextRef][0].focus()
    },
    // 刷新表单
    resetForm() {
      if (this.$refs["dataForm"]) {
        // 清空验证信息表单
        this.$refs["dataForm"].clearValidate();
        // 刷新表单
        this.$refs["dataForm"].resetFields();
        this.getList();
      }
    },
    addCode() {
      this.code = this.code.trim();
      if (this.$isBlank(this.code)) {
        this.$message.warning('请输入条码');
        return;
      }
      if (this.iCount <= 0) {
        this.$message.warning('请输入数量');
        return;
      }
      this.loading = true;
      let tQuery = {
        orderId: this.formData.id,
        count: this.iCount,
        code: this.code,
      };
      if (this.orderEditor) {
        addStockOrderDetailFromCode(tQuery).then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            this.getStockOrderDetailList();
          } else {
            this.$alert(response.message, '提示', {
              confirmButtonText: '确定',
              type: 'warning',
              closeOnClickModal: true,
              callback: action => {
                this.$refs.inputRef.focus();
              }
            });
          }
        });
      } else {
        getStockOrderDetailInstrument(tQuery).then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            for (let i = 0; i < this.codeArray.length; i++) {
              if (this.codeArray[i].productId === response.data.productId) {
                this.$alert("已添加", '提示', {
                  confirmButtonText: '确定',
                  type: 'warning',
                  closeOnClickModal: true,
                  callback: action => {
                    this.$refs.inputRef.focus();
                  }
                });
                break;
              }
              if (i + 1 === this.codeArray.length) {
                this.codeArray.push(response.data);
              }
            }
            if (this.codeArray.length === 0) {
              this.codeArray.push(response.data);
            }
          } else {
            this.$alert(response.message, '提示', {
              confirmButtonText: '确定',
              type: 'warning',
              closeOnClickModal: true,
              callback: action => {
                this.$refs.inputRef.focus();
              }
            });
          }
        });
      }
    },
    saveCodeArray(index, row) {
      if (this.$isBlank(row.batchNo)) {
        return this.$message.error('批次号不能为空');
      }
      this.$refs.multipleTable.setCurrentRow();
      this.currentRow = {};
      this.selectedIndex = "";
      this.iCount = 0;

      this.detailLoading = true;
      // row.count = row.reCount;
      let tQuery = row;
      uploadStockOrderDetail(tQuery).then((response) => {
        this.detailLoading = false;
        if (response.code === 20000) {
          this.$message.success("修改完成");
          this.getStockOrderDetailList();
          this.$refs.inputRef.focus();
        } else {
          this.$message.error(response.message);
        }
      });
    },
    deleteCodeArray(index, row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$refs.multipleTable.setCurrentRow();
        this.currentRow = {};
        this.selectedIndex = "";
        this.iCount = 0;

        if (this.orderEditor) {
          this.detailLoading = true;
          if (this.$isNotBlank(row.id)) {
            delOrderDetail({id: row.id})
                .then(response => {
                  this.detailLoading = false;
                  if (response.code === 20000) {
                    this.$message.success(response.data);
                    // this.getStockOrderDetailList();
                    this.codeArray.splice(index, 1);
                  } else {
                    this.$message.error(response.message);
                  }
                })
                .catch(() => {
                  this.detailLoading = false;
                })
          } else {
            this.$message.success('删除成功');
            this.codeArray.splice(index, 1);
          }
        } else {
          this.$message.success('删除成功');
          this.codeArray.splice(index, 1);
        }
      }).catch(() => {

      });
    },
    copyDetail(row) {
      this.$confirm("是否复制该记录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let rData = JSON.parse(JSON.stringify(row));
        rData.id = null;
        if (this.codeArray.length === 0) {
          this.codeArray.push(rData);
          this.$refs.multipleTable.setCurrentRow(this.codeArray[0]);
          this.currentRow = this.codeArray[0];
          this.selectedIndex = 0;
        } else {
          this.codeArray.unshift(rData);
          this.$refs.multipleTable.setCurrentRow(this.codeArray[0]);
          this.currentRow = this.codeArray[0];
          this.selectedIndex = 0;
        }
        this.$message.success("复制成功");
        this.iCount = this.currentRow.count;
        this.focusNext('iCount');
      }).catch(() => {
      });
    },
    getInputFocus(event) {
      event.currentTarget.select();
    },
    tableSelection() {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleAllSelection();
    },
    handleSizeChange(val) {
      this.query.limit = val;
      this.getStockOrderDetailList();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getStockOrderDetailList();
    },
    getStockOrderDetailList() {
      this.loading = true;
      getThrOrderDetails(this.query) //查找该单号下的所有条码
          .then((response) => {
            console.log(response)
            this.codeArray = response.data.list || [];
            this.total = response.data.total || 0;
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
            this.list = [];
            this.total = 0;
          });
    },
    intentBack() {
      this.$router.go(-1);
    },
    getBusType() {
      let query = {
        enabled: true,
        corpType: 1,
      };
      getOriginJoinBusType(query)
          .then((response) => {
            this.busTypes = response.data.list || [];
            this.curAction = this.busTypes[0];
          })
          .catch(() => {
          });
    },
    selectOne(event) {

      this.formData.corpName = event.name;
      this.formData.corpId = event.erpId;
      this.formData.unitIdFk = event.erpId;
    },
    findMethod(query) {
      console.log(query);
      this.fromOptions = [];
      let cQuery = {
        key: query,
        corpType: null,
        outType: null,
      };
      if (this.curAction.corpType == 3) {//特殊往来
        cQuery.corpType = 4;
        this.formData.corpId = this.curAction.defaultUnit;
      } else if (this.curAction.corpType == 2)//客户
      {
        cQuery.corpType = 4;
        cQuery.outType = 2;

      } else if (this.curAction.corpType == 0) {
        cQuery.corpType = 2;
      } else return;

      getBasicUnitMaintains(cQuery)
          .then((response) => {
            this.loading = false;
            this.fromOptions = response.data.page.list || [];
            if (this.curAction.corpType == 3) {
              for (let i = 0; i < this.fromOptions.length; i++) {
                if (this.fromOptions[i].erpId == this.formData.corpId) {
                  this.formData.corpName = this.fromOptions[i].name;
                }
              }
            }
          })
          .catch(() => {
            this.loading = false;
          });
    },
    getActionItem(action) {
      for (let i = 0; i < this.busTypes.length; i++) {
        if (this.busTypes[i].thirdAction === action) {
          return this.busTypes[i];
        }
      }
    },
    actionChange(item) {
      console.log(item);
      this.curAction = this.getActionItem(item);
      this.locInChange();
      this.findMethod();

    },
    locInChange(item) {
      if (this.formData.invWarehouseCode != null) {
        this.formData.invWarehouseCode = "";
      }
      this.formData.locStorageCode = item;
      this.$forceUpdate();
      this.getBusType(item);
      this.findStorageMethod();
      this.findSubInvs();
    },
    findSubInvs() {
      this.subInvList = [];
      let query = {
        pcode: this.formData.locStorageCode
      };
      filterSubByInv(query)
          .then((response) => {
            this.subInvList = response.data || [];
            if (this.subInvList != null && this.subInvList.length == 1) {
              this.formData.invWarehouseCode = this.subInvList[0].code;
            }
          })
          .catch(() => {
          });
    }


  },
  filters: {},
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  },
  created() {

    if (this.$isNotBlank(this.idQuery.id)) {
      this.query.limit = 100;
      this.query.orderIdFk = this.idQuery.id;
      this.formData = this.idQuery.formData;
      this.orderEditor = true;
      this.sValue = this.formData.corpName;
      this.getStockOrderDetailList();
    } else {
      this.formData = {
        billNo: null,
        billdate: "",
        customerId: store.getters.customerId,
        billType: "",
        type: "2",
        corpName: "",
        corpId: "",
        noInvOut: "",
        locStorageCode: "",
        invWarehouseCode: "",
      };
      this.iCount = 0;
      this.orderEditor = false;
      // this.generateBillNo();
    }

    this.getBusType();
    this.getStorage();
    this.findSubInvByInv();
    this.findSubStorageMethod();
    this.codeArray = [];
    this.closeConfirmFunction(false);
  },
};
</script>
<style>

.ao-text {
  width: 100%;
  font-size: 13px;
  font-family: "Microsoft YaHei";
  float: right;
  text-align: right;
  margin-top: 10px;
}

</style>



