<template>
  <div>
    <el-card style="margin: 5px;margin-top: -20px">
      <el-form :model="formData" :rules="formRules" ref="dataForm" label-width="100px"
               style="margin-bottom: -15px">
        <el-button-group style="display: flex;margin: 0px 0 10px 80%; height: 35px">
          <el-button
            size="mini"
            type="primary"
            @click.native="saveOrder()"
          >草稿保存
          </el-button
          >
          <el-button
            size="mini"
            type="primary"
            @click.native="submit('0')"
          >提交订单
          </el-button
          >
        </el-button-group>
        <el-row>
          <el-col :span="11">
            <el-form-item prop="corpOrderId" label="单据号:">
              <el-input v-model="formData.corpOrderId" auto-complete="off" style="width: 90%"
                        clearable
                        :disabled="corpOrderIdDisabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="createTime" label="单据时间:">
              <el-date-picker
                v-model="formData.createTime"
                type="datetime"
                placeholder="日期"
                clearable
                :disabled="true"
                style="width: 90%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item prop="invCode" label="当前仓库:">
              <el-select v-model="formData.invCode" placeholder="当前仓库信息"
                         style="width: 90%"
                         clearable
                         :disabled="corpOrderIdDisabled" @change="changeInv" filterable>
                <el-option
                  v-for="item in curInvOptions"
                  :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.code
                    }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11">
            <el-form-item prop="action" label="单据类型:">
              <el-select v-model="formData.action" placeholder="请选择单据类型"
                         :disabled="corpOrderIdDisabled"
                         clearable
                         style="width: 90%"
                         @change="actionChange">
                <el-option
                  v-for="item in busTypeOptions"
                  :key="item.name"
                  :label="item.name"
                  :value="item.action">
                  <span style="float: left">{{ item.name }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item prop="fromCorp"
                          label="往来信息:"
                          v-if="curAction.corpType ==0 || curAction.corpType == 3 || (curAction.corpType == 2 && !curAction.genUnit)"
            >
              <el-select
                v-model="formData.fromCorp"
                filterable
                remote
                clearable
                reserve-keyword
                style="width: 90%"
                placeholder="请输入往来单位"
                :remote-method="findMethod"
                :loading="loading"
                :disabled="corpOrderIdDisabled"
              >
                <el-option
                  v-for="item in fromOptions"
                  :key="item.erpId"
                  :label="item.name"
                  :value="item.erpId"
                >
                  <span style="float: left">{{ item.name }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="fromCorp"
                          v-if="curAction.corpType ==1"
                          label="往来信息:"
            >
              <el-select v-model="formData.fromInvCode" placeholder="请选择往来仓库"
                         :disabled="corpOrderIdDisabled" filterable @change="getFormStorageCode"
                         clearable
                         style="width: 90%"
              >
                <el-option
                  v-for="item in fromInvOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                  <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-form-item prop="fromCorp"
                          v-if="curAction.corpType ==2 && curAction.genUnit">
              <el-input v-model="formData.fromCorp" auto-complete="off"
                        clearable
                        style="width: 90%"
                        :disabled="corpOrderIdDisabled"
                        placeholder="请输入病人住院号"
              ></el-input>
            </el-form-item>

          </el-col>
          <el-col :span="11">
            <el-form-item prop="remark" label="备注:">
              <el-input v-model="formData.remark" auto-complete="off"
                        clearable
                        style="width: 90%"
                        placeholder="请输入备注信息"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item prop="code" label="扫码录入:">
              <el-input
                id="inputer"
                @focus="getInputFocus($event)"
                @keypress.enter.native="enterKey($event)"
                ref='inputRef'
                style="ime-mode:disabled"
                type="tel"
                v-model="formData.code"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-button
              type="primary"
              size="mini"
              @click.native.stop="addCode()"
              style=" margin-left: 15px"
            >添加
            </el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-tabs type="border-card" style="margin: 5px">
      <el-tab-pane label="扫码明细">
        <codesPanel :idQuery="idQuery"></codesPanel>
      </el-tab-pane>
      <el-tab-pane label="扫码详情">
      </el-tab-pane>
      <el-tab-pane label="业务详情">
      </el-tab-pane>
    </el-tabs>


    <!--        <el-dialog-->
    <!--            :title="selectUnitTitle"-->
    <!--            :visible.sync="dialogTableVisible"-->
    <!--            :close-on-click-modal="false"-->
    <!--            :close-on-press-escape="false"-->
    <!--            v-if="dialogTableVisible"-->
    <!--            width="70%"-->
    <!--            append-to-body-->
    <!--        >-->
    <!--            <DialogSelectUnit-->
    <!--                :codeId="curRow"-->
    <!--                v-on:selectSupUnit="selectSupUnit"-->
    <!--                v-on:closeBindDialog="closeBindDialog"-->
    <!--            ></DialogSelectUnit>-->
    <!--        </el-dialog>-->
    <!--        <el-dialog-->
    <!--            :title="selectRlTitle"-->
    <!--            :visible.sync="selectRlVisible"-->
    <!--            width="80%"-->
    <!--            :close-on-click-modal="false"-->
    <!--            :close-on-press-escape="false"-->
    <!--            v-if="selectRlVisible"-->
    <!--            append-to-body-->
    <!--        >-->
    <!--            <selectRlDialog-->
    <!--                :curRow="curRow"-->
    <!--                :curAction="curAction"-->
    <!--                v-on:selectBindRl="selectBindRl"-->
    <!--                v-on:closeBindDialog="closeBindDialog"-->
    <!--            ></selectRlDialog>-->
    <!--        </el-dialog>-->

    <!--        <el-dialog-->
    <!--            :title="editTitle"-->
    <!--            :visible.sync="editCodeVisible"-->
    <!--            append-to-body width="70%"-->
    <!--            :close-on-click-modal="false"-->
    <!--            :close-on-press-escape="false"-->
    <!--            v-if="editCodeVisible"-->
    <!--        >-->
    <!--            <editCodeDialog-->
    <!--                editTye="2"-->
    <!--                :closeCodeDialog="closeCodeDialog"-->
    <!--                :codeDetail="codeDetail">-->
    <!--            </editCodeDialog>-->
    <!--        </el-dialog>-->

    <!--        <el-dialog-->
    <!--            :title="editTitle"-->
    <!--            :visible.sync="editOriginCodeVisible"-->
    <!--            append-to-body width="70%"-->
    <!--            :close-on-click-modal="false"-->
    <!--            :close-on-press-escape="false"-->
    <!--            v-if="editOriginCodeVisible">-->
    <!--            <editCodeDialog-->
    <!--                :closeCodeDialog="closeCodeDialog"-->
    <!--                :repeatAddCode="repeatAddCode"-->
    <!--                :codeDetail="formData"-->
    <!--                editTye="1">-->
    <!--            </editCodeDialog>-->
    <!--        </el-dialog>-->


  </div>


</template>

<script>
import {
  errorCodeList, addOrderWeb, deleteCodesTempById, submitOrderWeb, saveOrderWeb,
  updateCodeBindSup, enterCodeWeb
} from "../../api/inout/order";
import {filterSubByInv, findByInvUser} from "../../api/system/invSubWarehouse";
import draggable from "vuedraggable";
import {parseTime} from "../../utils/coTools";
import {getBasicUnitMaintains} from "../../api/basic/basicUnitMaintain"
import {filterAllByLoc, filterAllByUser} from "@/api/system/invWarehouse";
import {getLocalJoinByUser} from "../../api/basic/busType";
// import DialogSelectUnit from "./DialogSelectUnit";
// import selectRlDialog from "./DialogSelectRl";
// import editCodeDialog from "./editCode";


import codesPanel from "./IoCreateOrderCodes"
import A from "../../plugins/KeyScaner"
import {isBlank} from "@/utils/strUtil";
import {filterDepts} from "@/api/auth/authDept";
import {selectSysParamByKey} from "@/api/param/systemParamConfig";
import store from "@/store";


export default {
  name: "idQuery",
  props: {
    closeDialog: {
      type: Function,
      required: true,
    },
    idQuery: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {

      formData: {
        billNo: null,
        corpOrderId: null,
        action: null,
        createTime: new Date(),
        invCode: null,
        fromCorp: null,
        fromInvCode: null,
        remark: null,
        code: "",
        fromType: 2,
        batchNo: null,
        produceDate: null,
        expireDate: null,
        serialNo: null,
      },
      curInvOptions: [],
      busTypeOptions: [],
      fromInvOptions: [],
      curAction: {
        corpType: 0,
        genUnit: false,
      },


      editCodeVisible: false,
      billAction: null,
      actionEnable: false,
      // formData: {
      //   corpOrderId: "",
      //   code: "",
      //   actor: "",
      //   fromCorpId: "",
      //   fromCorp: null,
      //   fromType: 2,
      //   actDate: new Date(),
      //   action: null,
      //   locStorageCode: null,
      //   outChangeEnable: false,
      //   preCheck: false,
      //   batchNo: null,
      //   produceDate: null,
      //   expireDate: null,
      //   serialNo: null,
      //   invWarehouseCode: null,
      //   subInvCode: null,
      //   fromSubInvCode: null,
      //   codeFillCheck: null,
      //   vailInv: null,
      //   deptCode: null,
      //
      // },
      editOriginCodeVisible: false,
      curId: null,
      storageList: [],

      formRules: {
        temp: [
          {required: true, message: "请输入条码", trigger: "blur"}
        ],
      },
      isScan: true,
      scanText: "扫码录入：",
      corpOrderIdDisabled: false,

      loading: false,
      index: null,
      formLoading: false,
      formVisible: false,
      deleteLoading: false,
      orderNo: null,
      fromOptions: [],
      fromStorageOptions: [],


      curRow: null,

      dialogTableVisible: false,
      sitcomScan: false,
      selectRlTitle: "绑定产品",
      selectUnitTitle: "绑定供应商",
      sictomText: "",
      originCode: "",
      checkSuccess: false,
      codeDetail: null,
      editTitle: "编辑条码",
      fromDeptOptions: [],
      enableDept: false
    };
  },
  components: {
    draggable,
    // DialogSelectUnit, selectRlDialog, editCodeDialog
    codesPanel
  },
  methods: {


    //获取用户仓库列表
    findInvByUser() {
      this.curInvOptions = [];
      filterSubByInv(query)
        .then((response) => {
          this.curInvOptions = response.data || [];
          if (this.curInvOptions != null && this.curInvOptions.length == 1) {
            this.formData.invWarehouseCode = this.curInvOptions[0].code;
            this.getBusType();
          }
        })
        .catch(() => {
        });
    },

    //仓库改变
    changeInv() {
      this.formData.action = null;
      this.getBusTypeByInv();
    },

    //根据仓库获取单据类型
    getBusTypeByInv() {
      let query = {
        code: this.formData.invCode,
      };
      findByInvUser(query)
        .then((response) => {
          this.busTypeOptions = response.data || [];
        })
        .catch(() => {
        });
    },

    //获取往来单位候选列表
    findMethod(query) {
      this.fromOptions = [];
      let cQuery = {
        key: query,
        corpType: null,
        outType: null,
        page: 1,
        limit: 20
      };
      if (this.curAction.corpType == 3) {//特殊往来
        cQuery.corpType = 4;
        this.formData.fromCorpId = this.curAction.defaultUnit;
      } else if (this.curAction.corpType == 2)//客户
      {
        cQuery.corpType = 1;
        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.list || [];
        })
        .catch(() => {
          this.loading = false;
        });
    },

    //单据类型改变
    actionChange(item) {
      this.curAction = this.getActionItem(item);

      //1.切换往来单位
      this.formData.fromCorp = null;
      this.findMethod();

      //2. 切换往来仓库
      this.formData.fromInvCode = null;


    },


    submit(formName) {
      if (this.total < 1) {
        this.$message.error('未添加条码');
        return;
      }
      let tQuery = {
        orderId: this.idQuery.id,
        locStorageCode: this.formData.locStorageCode,
        invStorageCode: this.formData.invStorageCode,
        invWarehouseCode: this.formData.invWarehouseCode,
        fromSubInvCode: this.formData.fromSubInvCode,
        subInvCode: this.formData.subInvCode,
        action: this.formData.action,
        fromCorp: this.formData.fromCorp,
        fromCorpId: this.formData.fromCorpId,
        outChangeEnable: this.formData.outChangeEnable,
        preCheck: this.formData.preCheck,
        deptCode: this.formData.deptCode,
      }
      submitOrderWeb(tQuery)
        .then((response) => {
          if (response.code === 20000) {
            this.$message.success("提交成功");
            this.closeDialog();
          } else {
            this.$message.error(response.message);
          }
          this.loading = false;
        });
    },
    saveOrder() {
      if (this.total < 1) {
        this.$message.error('未添加条码');
        return;
      }
      if (this.formData.action == null || this.formData.action == '') {
        this.$message.error('未选择扫码单据类型');
        return
      }


      if (this.formData.invWarehouseCode == null || this.formData.invWarehouseCode == '') {
        this.$message.error('当前分库不能为空');
        return;
      }
      let tQuery = Object.assign(JSON.parse(JSON.stringify(this.formData)));
      tQuery.orderId = this.idQuery.id;
      tQuery.actDate = parseTime(this.formData.actDate, '{y}-{m}-{d} {h}:{i}:{s}');
      saveOrderWeb(tQuery).then((response) => {
        if (response.code === 20000) {
          this.closeDialog();
        } else {
          this.$message.error(response.message);
        }
        this.loading = false;
      });
    },
    closeCodeDialog() {
      this.editCodeVisible = false;
      this.editOriginCodeVisible = false;
      this.getCodeList();
    },

    // 刷新表单
    resetForm() {
      if (this.$refs["dataForm"]) {
        // 清空验证信息表单
        this.$refs["dataForm"].clearValidate();
        // 刷新表单
        this.$refs["dataForm"].resetFields();
        this.getList();
      }
    },
    enterKey(event) {
      this.checkSuccess = true;
      let tQuery = {
        originCode: this.originCode,
        code: this.formData.code.trim(),
      }
      enterCodeWeb(tQuery).then((response) => {
        if (response.code === 20000) {
          this.$refs.inputRef.focus();
          this.$refs.inputRef.select();
          this.formData.code = response.data;
          this.addCode();
        } else {
          if (response.code == 502) {
            this.checkSuccess = false;
            this.formData.code = response.data;
            this.originCode = this.formData.code;
          } else if (response.code == 501) {
            this.checkSuccess = false;
            // this.formData.code = response.data;
            // this.originCode = this.formData.code;
            this.$message.error(response.message);
          } else if (response.code == 503) {
            this.checkSuccess = false;
            this.formData.code = response.data;
            this.$confirm(response.message, "提示", {
              type: "warning",
            })
              .then(() => {
                this.formData.code = response.data;
                this.addCode();
              })
              .catch(() => {
                this.formData.code = this.originCode;
              });

          } else if (response.code == 508) {
            this.originCode = "";
            this.formData.code = "01" + response.data.nameCode;
            this.originCode = this.formData.code;
          } else {
            this.$alert(response.message, '提示', {
              confirmButtonText: '确定',
              type: 'warning',
              closeOnClickModal: true,
              callback: action => {
                this.$refs.inputRef.focus();
                this.$refs.inputRef.select();
              }
            });
          }
        }
        this.loading = false;
      });
    },
    addCode(event) {
      this.originCode = "";
      this.sictomText = "";
      this.formData.corpOrderId = this.formData.corpOrderId.trim();
      this.formData.batchNo = "";
      this.formData.produceDate = "";
      this.formData.expireDate = "";
      this.formData.serialNo = "";
      this.actionEnable = true;
      if (event == null) {
      } else event.target.select();
      this.$refs.inputRef.select();
      if (this.$isBlank(this.formData.action)) {
        this.$message.warning("请选择单据类型！");
        return;
      }

      if (this.formData.invWarehouseCode == null || this.formData.invWarehouseCode == '') {
        this.$message.error('当前分库不能为空');
        return;
      }

      if (this.curAction.corpType == 1) {
        if (this.$isBlank(this.formData.fromSubInvCode)) {
          this.$message.error('当前往来分库不能为空');
          return;
        }
      }

      if (this.$isBlank(this.formData.corpOrderId)) {
        let date = new Date();
        this.formData.corpOrderId = parseTime(date, '{y}{m}{d}{h}{i}{s}') + Math.ceil(Math.random() * 89 + 10);
      }
      this.formData.code = this.formData.code.trim();
      if (this.$isBlank(this.formData.code)) return;
      this.loading = true;


      let tQuery = Object.assign(JSON.parse(JSON.stringify(this.formData)));
      tQuery.orderId = this.idQuery.id;
      tQuery.actDate = parseTime(this.formData.actDate, '{y}-{m}-{d} {h}:{i}:{s}');
      tQuery.action = this.formData.action;
      this.addCodeSubmit(tQuery);
      this.$refs.inputRef.select();
    },

    repeatAddCode(editData) {
      let tQuery = editData;
      tQuery.orderId = this.idQuery.id;
      tQuery.actDate = parseTime(this.formData.actDate, '{y}-{m}-{d} {h}:{i}:{s}');
      tQuery.action = this.formData.action;
      this.closeCodeDialog();
      this.addCodeSubmit(tQuery);

    },
    addCodeSubmit(tQuery) {
      addOrderWeb(tQuery).then((response) => {
        if (response.code === 20000) {
          this.idQuery.id = response.data.orderId;
          if (response.data.errMsg != null) {
            this.$alert(response.data.errMsg, '提示', {
              confirmButtonText: '确定',
              type: 'warning',
              closeOnClickModal: true,
              callback: action => {
              }
            });
          }
          this.corpOrderIdDisabled = true;
          this.getCodeList();
          this.$refs.inputRef.focus();
          this.$refs.inputRef.select();
        } else {
          if (response.code == 502) {
            this.curRow = response.data;
            this.idQuery.id = this.curRow.orderId;
            this.getCodeList();
            this.selectRlTitle = response.message;
            this.bindRl(response.data);
          } else if (response.code == 503) {
            this.curRow = response.data;
            this.idQuery.id = this.curRow.orderId;
            this.getCodeList();
            this.selectUnitTitle = response.message;
            this.handleUnitClick(response.data);
          } else if (response.code == 504) {

            this.$confirm(response.message, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "忽略",
              type: "error",
            }).then(() => {
              tQuery.ignoreExpire = true;
              this.addCodeSubmit(tQuery)
            }).catch(() => {

            });
          } else if (response.code == 505) {
            this.$confirm(response.message, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "忽略",
              type: "warning",
            }).then(() => {
              tQuery.ignoreRecentExpire = true;
              this.addCodeSubmit(tQuery)
            }).catch(() => {

            });
          } else if (response.code == 507) {
            this.editOriginCodeVisible = true;
            this.editTitle = response.message;
            this.formData.produceDate = response.data.produceDate;
            this.formData.expireDate = response.data.expireDate;
            this.formData.batchNo = response.data.batchNo;
            this.formData.serialNo = response.data.serialNo;

            this.$message({
              type: 'error',
              message: "提交失败！" + this.editTitle,
              customClass: 'messageIndex'
            });

            // this.$message.error("提交失败！" + this.editTitle);


          } else {
            this.$alert(response.message, '提示', {
              confirmButtonText: '确定',
              type: 'warning',
              closeOnClickModal: true,
              callback: action => {
                this.$refs.inputRef.focus();
                this.$refs.inputRef.select();
              }
            });
          }
        }
        this.loading = false;
      });
    },

    unitChange(row) {
      this.formData.fromCorpId = row.erpId;
      this.formData.fromCorp = row.name;
      this.curRow = row;
    },
    getFormStorageCode(code) {
      var row = this.fromInvOptions.find(item => item.code == code)
      this.formData.subInvCode = row.parentId
      this.formData.fromSubInvCode = row.code
      this.formData.fromCorpId = row.code;
      this.formData.fromCorp = row.warehouseName;
    },
    ksChange(code) {
      this.formData.deptCode = code;
    },


    getInputFocus(event) {
      event.currentTarget.select();
      // var inputer = document.getElementById("inputer");
      // inputer.focus();
    },
    tableSelection() {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleAllSelection();
    },
    handleSizeChange(val) {
      this.query.limit = val;
      this.getCodeList();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getCodeList();
    },

    intentBack() {
      this.$router.go(-1);
    },
    getBusType() {
      let query = {
        code: this.formData.invWarehouseCode,
        enabled: true,
        type: 1
      };
      getLocalJoinByUser(query)
        .then((response) => {
          this.busTypeOptions = response.data.list || [];
          if (this.formData.action != null) {
            this.curAction = this.getActionItem(this.formData.action);
            if (this.curAction != null) {
              this.formData.vailInv = this.curAction.vailInv;
              this.formData.codeFillCheck = this.curAction.codeFillCheck;
            } else {
              this.curAction = {corpType: 0, genUnit: false, changeEnable: false,};
              this.formData.action = null;
            }

          }
        })
        .catch(() => {
        });
    },

    geActionName(action) {
      this.busTypeOptions.forEach((obj) => {
        if (obj.action == action) {
          return obj.name;
        }
      });
    },

    locCHange() {

      if (this.$isNotBlank(this.formData.invWarehouseCode)) {
        this.formData.invWarehouseCode = "";
      }
      this.findStorageMethod();
      this.findInvByUser(this.formData.locStorageCode);
    },


    findStorageMethod() {

      if (this.formData.locStorageCode == null)
        return;
      this.fromStorageOptions = [];
      let cQuery = {
        locInvCode: this.formData.locStorageCode,
      };
      filterAllByLoc(cQuery)
        .then((response) => {
          this.fromStorageOptions = response.data || [];
        })
        .catch(() => {
        });
    },


    findSubStorageMethod(val) {
      if (this.curInvOptions.length > 0) {
        this.query.invStorageCode = this.curInvOptions.find(item => item.code == this.formData.invWarehouseCode).parentId
      }
      this.getBusType();
      let cQuery = {
        code: this.formData.invWarehouseCode,
        filter: 2,
      };
      filterSubByInv(cQuery)
        .then((response) => {

          this.fromInvOptions = response.data || [];
          if (val == 1) {

          } else
            this.formData.fromSubInvCode = this.fromInvOptions[0].code;
        })
        .catch(() => {
        });
    },


    getStorage(event) {
      this.storageList = [];
      filterAllByUser()
        .then((response) => {
          this.storageList = response.data || [];
        })
        .catch(() => {
        });
    },
    getActionName(action) {
      for (let i = 0; i < this.busTypeOptions.length; i++) {
        if (this.busTypeOptions[i].action === action) {
          return this.busTypeOptions[i].advanceType;
        }
      }
    },
    getActionItem(action) {
      for (let i = 0; i < this.busTypeOptions.length; i++) {
        if (this.busTypeOptions[i].action == action) {
          return this.busTypeOptions[i];
        }
      }
    },


    selectSupUnit(row) {
      let query = {
        id: this.curRow.id,
        supId: row.erpId,
      };
      updateCodeBindSup(query).then((response) => {
        if (response.code == 20000) {
          this.$message.success("绑定成功");
          this.idQuery.id = this.curRow.orderId;
          this.getCodeList();
        } else {
          this.$message.error(response.message);
        }
      }).catch(() => {

      });
    },


    selectBindRl(row) {
      let query = {
        id: this.curRow.id,
        relId: row.id,
        mySupId: row.unitFk,
      };
      updateCodeBindSup(query).then((response) => {
        if (response.code == 20000) {
          this.$message.success("绑定成功");
          this.idQuery.id = this.curRow.orderId;
          this.getCodeList();
        } else {
          if (response.code == 503) {
            this.curRow = response.data;
            this.idQuery.id = this.curRow.orderId;
            this.getCodeList();
            this.selectUnitTitle = response.message;
            this.handleUnitClick(response.data);
          } else
            this.$message.error(response.message);
        }
      }).catch(() => {

      });
    },
    closeBindDialog(val) {
      this.selectRlVisible = false;
      this.dialogTableVisible = false;
    },

  },
  filters: {},
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
    var that = this;
    var inputer = document.getElementById("inputer");
    window.sc = new A.KeyScaner(inputer);//传入要监听的DOM节点
    sc.onInput = function (text) {
      if (text.includes("delete")) {
        that.formData.code = "";
        that.sictomText = "";
        that.originCode = "";
        return;
      }
      if (that.sitcomScan) {
        let tempTxt = text;
        let str = tempTxt.replace(/[\r]/g, "");
        that.sictomText = that.sictomText + str;
        that.formData.code = that.sictomText;
      } else {

        that.formData.code = text;
        // setTimeout(function(){  that.formData.code = text; }, 3000);


      }
    };
    inputer.focus();
  },
  created() {

    this.formData.code = '';
    this.formData.actDate = new Date();
    this.codeArray = [];
    this.getStorage(this.formData.action);
    if (this.$isNotBlank(this.idQuery.id)) {
      this.formData.actDate = new Date(this.idQuery.actDate);
      this.formData.corpOrderId = this.idQuery.corpOrderId;
      this.corpOrderIdDisabled = true;
      this.formData.action = this.idQuery.action;
      this.formData.fromCorp = this.idQuery.fromCorp;
      this.formData.deptCode = this.idQuery.deptCode
      this.formData.fromCorpId = this.idQuery.fromCorpId;
      this.formData.locStorageCode = this.idQuery.locStorageCode;
      this.formData.invWarehouseCode = this.idQuery.invWarehouseCode;
      this.formData.fromSubInvCode = this.idQuery.fromSubInvCode;
      this.formData.outChangeEnable = this.idQuery.outChangeEnable;
      this.formData.preCheck = this.idQuery.preCheck;
      this.actionEnable = true;
      this.getCodeList();
      this.findSubStorageMethod(1);
    } else {
      this.corpOrderIdDisabled = false;
      if (JSON.stringify(this.$route.query) === '{}') {
        // this.formData.corpOrderId = new Date().getTime() + (Math.ceil(Math.random() * 10 + 10) + '');
        let date = new Date();
        this.formData.corpOrderId = parseTime(date, '{y}{m}{d}{h}{i}{s}') + Math.ceil(Math.random() * 89 + 10);
      } else {
        // 将参数拷贝进查询对象
        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.formData.invWarehouseCode = this.$store.getters.locSubInvCode;
      this.formData.locStorageCode = this.$store.getters.locInvCode;
      if (this.$isNotBlank(this.formData.locStorageCode)) {
        this.findStorageMethod();
      }
    }
    this.findInvByUser();
    this.findSubStorageMethod();
    //查询是否启用多级仓库，判断是否启用部门
    selectSysParamByKey({paramKey: "muti_inv_mode"}).then((res) => {
      if (res.code === 20000) {
        if (res.data.paramValue === "0") {
          this.enableDept = true;
        }
      }
    })
  },
};
</script>


<style>


#inputer {
  width: 100%;
  min-height: 30px;
  background-color: white;
  border: #d0d0d0;
  border-style: solid;
  border-width: 0.1px;
  color: #4a4a4a;

}

#inputer:focus {
  width: 100%;
  min-height: 30px;
  background-color: white;
  border: #0080FF;
  border-style: solid;
  border-width: 0.1px;
  color: #4a4a4a;

}

.ime-disabled {
  ime-mode: disabled;
}
</style>



