<template>
    <div>

        <el-form :model="formData" :rules="formRules" ref="dataForm">
            <el-button-group style="display: flex;margin: -50px 0 10px 80%; height: 35px">
                <el-button
                    type="primary"
                    @click.native="saveOrder()"
                >草稿保存
                </el-button
                >
                <el-button
                    v-if="visiblV === 0"
                    type="primary"
                    @click.native="submit('0')"
                >提交
                </el-button
                >

            </el-button-group>
            <el-card>
                <el-row :gutter="20">
                    <el-col :span="2">
                        <div class="ao-text">
                            <span>入库单号：</span>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item prop="corpOrderId">
                            <el-input v-model="formData.corpOrderId" auto-complete="off"
                                      :disabled="corpOrderIdDisabled"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="2">
                        <div class="ao-text">
                            <span>单据时间：</span>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item prop="actDate">
                            <el-date-picker
                                v-model="formData.actDate"
                                type="datetime"
                                placeholder="单据时间"
                                :disabled="true"
                                style="width: 100%; "
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="2">
                        <div class="ao-text">
                            <span>往来单位：</span>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item prop="fromCorp">
                            <el-input v-model="formData.fromCorp" auto-complete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="2">
                        <div class="ao-text">
                            <span>单据类型：</span>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item class="query-form-item">
                            <el-select v-model="formData.billType" placeholder="请选择单据类型" @change="actionChange"
                                       :disabled="corpOrderIdDisabled"
                                       clearable>
                                <el-option
                                    v-for="item in busTypes"
                                    :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 :gutter="20">


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

                    <el-col :span="8">
                        <el-form-item prop="locStorageCode">
                            <el-select v-model="formData.invWarehouseCode" placeholder="当前仓库信息" clearable
                                       @change="getBusType"
                                       :disabled="corpOrderIdDisabled">
                                <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-row :gutter="20">-->
                <!--          <el-col :span="12" class="el-col">-->
                <!--            <div class="text item">-->
                <!--              <el-checkbox v-model="formData.codeFillCheck"-->
                <!--              >采集UDI码时进行三期校验-->
                <!--              </el-checkbox>-->
                <!--            </div>-->

                <!--          </el-col>-->
                <!--        </el-row>-->
            </el-card>
            <el-card>
                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <el-link
                                target="_blank">{{ scanText }}
                            </el-link>
                        </div>
                    </el-col>
                    <el-col :span="16">
                        <el-form-item prop="code">
                            <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="small"
                            @click.native.stop="addCode()"
                            style="height: 31px; margin-left: 20px"
                        >添加
                        </el-button
                        >
                    </el-col>


                </el-row>
                <el-row :gutter="20">
                    <el-col :span="14" style="margin-left: 40px">
                    </el-col>
                    <el-col :span="3">
                        <div class="text item" style="margin-left: 30px"> 条码数量：{{ total }}
                        </div>
                    </el-col>

                </el-row>
                <el-table v-loading="loading" :data="codeArray" style="width: 100%;" max-height="350" height="350"
                          :row-style="rowStyle"
                          ref="multipleTable">
                    <el-table-column label="序号" type="index" width="45"></el-table-column>
                    <el-table-column
                        label="条码"
                        prop="code"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="扫码数量"
                        prop="count"
                        width="80"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="实际数量"
                        prop="reCount"
                        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="操作" fixed="right" width="250">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                size="small"
                                @click.native.stop="deleteCode(scope.$index, scope.row)"
                            >减一
                            </el-button
                            >
                            <el-button
                                type="text"
                                size="small"
                                @click.native.stop="bindRl(scope.row)"
                            >选择产品
                            </el-button
                            >
                            <el-button
                                type="text"
                                size="small"
                                @click.native.stop="editCode(scope.row)"
                            >编辑
                            </el-button
                            >
                        </template>
                    </el-table-column>
                </el-table>

                <div class="block">
                    <el-pagination
                        @current-change="handleCurrentChange"
                        layout="prev, pager, next,total"
                        :page-size="query.limit"
                        :total="total">
                    </el-pagination>
                </div>
            </el-card>
        </el-form>
        <el-dialog
            title="绑定产品ID"
            :visible.sync="selectRlVisible"
            width="80%"
            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%"
            v-if="editCodeVisible"
            @close="getCodeList"
        >
            <editCodeDialog
                editTye="2"
                :closeCodeDialog="closeCodeDialog"
                :codeDetail="codeDetail">

            </editCodeDialog>
        </el-dialog>

        <el-dialog
            :title="editTitle"
            :visible.sync="editOriginCodeVisible"
            append-to-body width="70%"
            v-if="editOriginCodeVisible">
            <editCodeDialog
                :closeCodeDialog="closeCodeDialog"
                :repeatAddCode="repeatAddCode"
                :codeDetail="formData"
                editTye="1">
            </editCodeDialog>
        </el-dialog>
    </div>
</template>

<script>
import {
    orderGetUdi,
    orderList,
    codeList,
    orderListError,
    saveOrderWeb,
    mergeOrder,
    postOrdersWeb,
    errorCodeList,
    addOrderWeb,
    deleteCodesTempById,
    submitOrderWeb,
    updateCodeBindSup,
    expireTimeCheck, enterCodeWeb
} from "../../api/warehouse/order";
import draggable from "vuedraggable";
import {saveAs} from "file-saver";
import {getBussinessType} from "../../api/basic/bussinessType";
import {parseTime} from "../../filtres/index";
import store from "../../store";
import {filterAll, filterAllByUser} from "@/api/basic/invWarehouse";
import {getLocalBusType, getLocalJoinBusType, getLocalJoinByUser} from "../../api/basic/busLocalType";
import DialogSelectUnit from "./DialogSelectUnit";
import selectRlDialog from "./DialogSelectRl";
import editCodeDialog from "./editCode";
import A from "../../plugin/KeyScaner"
import {filterSubByInv} from "@/api/basic/invSubWarehouse";

export default {
    name: "idQuery",
    props: {
        closeDialog: {
            type: Function,
            required: true,
        },
        idQuery: {
            type: Object,
            required: true,
        },
        addType: {
            type: Object,
            required: true,
        },
    },
    data() {
        return {
            codeQuery: {
                code: "",
            },
            query: {
                code: "",
                corpOrderId: "",
                page: 1,
                limit: 10,
            },
            formData: {
                corpOrderId: "",
                code: "",
                actor: "",
                fromCorpId: "",
                fromCorp: "医院",
                fromType: null,
                locStorageCode: null,
                invWarehouseCode: null,
                actDate: new Date(),
                billType: null,
                preCheck: false,
                outChangeEnable: false,
                batchNo: null,
                produceDate: null,
                expireDate: null,
                serialNo: null,
                count: null,
                codeFillCheck: null,
                vailInv: null,
                subInvCode: null,
                fromSubInvCode: null,
                invName: null,
                subInvName: null
            },
            formRules: {
                temp: [
                    {required: true, message: "请输入条码", trigger: "blur"}
                ],
            },
            isScan: true,
            scanText: "扫码录入：",
            visiblV: 0,
            corpOrderIdDisabled: false,
            codeArray: [],
            total: 0,
            loading: false,
            index: null,
            formLoading: false,
            formVisible: false,
            deleteLoading: false,
            orderNo: null,
            curRow: null,
            busTypes: [],
            storageList: [],
            subInvList: [],
            editOriginCodeVisible: false,
            curId: null,
            selectRlVisible: false,
            dialogTableVisible: false,
            sitcomScan: false,
            codeDetail: null,
            originCode: "",
            checkSuccess: false,
            editTitle: "编辑条码",
            editCodeVisible: false,
        };
    },
    components: {
        draggable, DialogSelectUnit, selectRlDialog, editCodeDialog
    },
    methods: {
        submit(formName) {
            if (this.total < 1) {
                this.$message.error('未添加条码');
                return;
            }

            let tQuery = {
                orderId: this.idQuery.id,
                action: this.formData.billType,
                locStorageCode: this.formData.locStorageCode,
                preCheck: this.formData.preCheck,
                fromCorp: this.formData.fromCorp
            }

            submitOrderWeb(tQuery)
                .then((response) => {
                    if (response.code === 20000) {
                        this.$message.success("提交成功");
                        this.closeDialog();
                    } else {
                        this.$message.error(response.message);
                    }
                    this.loading = false;
                });

        },
        scanChange() {
            this.isScan = !this.isScan;
            if (this.isScan) {
                this.scanText = "扫码录入：";

            } else {
                this.scanText = "手动录入：";
            }
        },
        saveOrder() {
            if (this.formData.billType == null || this.formData.billType == '') {
                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}');
            tQuery.action = tQuery.billType;
            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();
        },
        editCode(row) {
            this.codeDetail = row;
            this.editTitle = "编辑条码";
            this.editCodeVisible = true;
        },

        // 刷新表单
        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;
                        // this.$confirm("当前商品条码对应产品信息：\n" +
                        //     "DI标识:" + response.data.nameCode + "\n" +
                        //     "产品名称：" + response.data.cpmctymc + "\n" +
                        //     "规格型号：" + response.data.cpmctymc + "\n" +
                        //     "医疗器械注册人：" + response.data.ylqxzcrbarmc + "\n" + "是否继续添加？", "提示", {
                        //     confirmButtonText: "确定",
                        //     cancelButtonText: "取消",
                        //     type: "warning",
                        // })
                        //     .then(() => {
                        //         this.originCode = "01" + response.data.nameCode;
                        //         this.formData.code = this.originCode;
                        //     })
                        //     .catch(() => {
                        //         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) {
            console.log(this.formData)
            console.log(this.storageList)
            if (event == null) {
            } else event.target.select();
            this.sictomText = "";
            this.originCode = "";
            this.formData.corpOrderId = this.formData.corpOrderId.trim();
            this.formData.batchNo = "";
            this.formData.produceDate = "";
            this.formData.expireDate = "";
            this.formData.serialNo = "";
            this.actionEnable = true;
            this.$refs.inputRef.select();
            if (this.$isBlank(this.formData.billType)) {
                this.$message.warning("请选择单据类型！");
                return;
            }

            if (this.formData.invWarehouseCode == null || this.formData.invWarehouseCode == '') {
                this.$message.error('当前仓库不能为空');
                return;
            }
            this.formData.corpOrderId = this.formData.corpOrderId.trim();
            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 = tQuery.billType
            this.addCodeSubmit(tQuery);
            this.$refs.inputRef.select();
        },

        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();
                } else {
                    this.corpOrderIdDisabled = true;
                    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.editTitle = response.message;
                        this.editOriginCodeVisible = true;
                        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'
                        });

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

        repeatAddCode(editCode) {
            let tQuery = editCode;
            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);

        },
        deleteCode(index, row) {
            this.$confirm("是否确定移除一个条码?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.loading = true;
                let tQuery = {
                    id: row.id
                }
                deleteCodesTempById(tQuery)
                    .then((response) => {
                        if (response.code === 20000) {
                            this.getCodeList();
                        } else {
                            this.$message.error(response.message);
                        }
                        this.loading = false;
                    });
            }).catch(() => {
            });
        },
        getInputFocus(event) {
            event.currentTarget.select();
        },
        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();
        },
        getCodeList() {
            this.loading = true;
            this.query.orderId = this.idQuery.id;
            errorCodeList(this.query) //查找该单号下的所有条码
                .then((response) => {
                    this.codeArray = response.data.list || [];
                    this.total = response.data.total || 0;
                    for (let i = 0; i < this.codeArray.length; i++) {
                        this.codeArray[i].fromType = this.formData.fromType;
                        this.codeArray[i].billType = this.formData.billType;
                    }
                    this.tableSelection();
                    this.loading = false;
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },
        getBusType() {
            let query = {
                code: this.formData.invWarehouseCode,
                enabled: true,
            };
            getLocalJoinByUser(query)
                .then((response) => {
                    this.busTypes = response.data.list || [];
                    debugger
                    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(() => {
                });
        },

        findSubInvByInv(invCode) {
            this.subInvList = [];
            let query = {
                filter: 3
            };
            filterSubByInv(query)
                .then((response) => {
                    this.subInvList = response.data || [];
                    if (this.subInvList != null && this.subInvList.length == 1) {
                        this.formData.invWarehouseCode = this.subInvList[0].code;
                    }
                })
                .catch(() => {
                });
        },

        locCHange() {
            this.subInvList = [];
            this.formData.invWarehouseCode = "";
            this.findSubInvByInv(this.formData.locStorageCode);
        },

        intentBack() {
            this.$router.go(-1);
        },
        getStorage(event) {
            let query = {
                spUse: true,
            };
            this.storageList = [];
            filterAll(query)
                .then((response) => {
                    this.storageList = response.data || [];
                })
                .catch(() => {
                });
        },
        getActionName(action) {
            for (let i = 0; i < this.busTypes.length; i++) {
                if (this.busTypes[i].action === action) {
                    return this.busTypes[i].advanceType;
                }
            }
        },
        getActionItem(action) {
            for (let i = 0; i < this.busTypes.length; i++) {
                if (this.busTypes[i].action === action) {
                    return this.busTypes[i];
                }
            }
        },
        actionChange(item) {
            this.curAction = this.getActionItem(item);
            this.$set(this.formData, "codeFillCheck", this.curAction.codeFillCheck);
            // this.formData.locStorageCode = this.curAction.storageCode;
            // this.formData.fromCorp = null;
        },
        //绑定数据
        bindRl(val) {
            this.curRow = val;
            this.selectRlVisible = true;
        },


        selectBindRl(row) {
            let query = {
                id: this.curRow.id,
                relId: row.id,
            };
            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;
        },
        rowStyle({row, rowIndex}) {
            let rowBackground = {};
            if (row.supId == null || row.relId == null) {
                //rowBackground.background="#f6f5ee";
                rowBackground.color = '#f60303';
            }

            return rowBackground;
        },

    },
    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;
            }
        };
        inputer.focus();


    },
    created() {
        this.formData.code = '';
        this.formData.actDate = new Date();
        this.codeArray = [];
        this.formData.fromCorp = store.getters.companyName;// store.getters.customerId === 110 ? '医院' : store.getters.companyName;
        this.formData.fromCorpId = store.getters.customerId;
        this.formData.customerId = store.getters.customerId;
        this.getStorage();
        if (this.$isNotBlank(this.idQuery.id)) {
            this.formData.actDate = new Date(this.idQuery.actDate);
            this.formData.corpOrderId = this.idQuery.corpOrderId;
            this.formData.billType = this.idQuery.billType;
            this.findSubInvByInv(this.idQuery.locStorageCode);
            this.formData.locStorageCode = this.idQuery.locStorageCode;
            this.formData.invWarehouseCode = this.idQuery.invWarehouseCode;
            this.corpOrderIdDisabled = true;
            this.formData.preCheck = this.idQuery.preCheck;
            this.formData.invName = this.idQuery.invName;
            this.formData.subInvName = this.idQuery.subInvName;
            if (this.addType == "edit") {
                this.visiblV = 1;
            }
            this.getCodeList();
        } else {
            this.formData.locStorageCode = this.$store.getters.locInvCode;
            this.findSubInvByInv(this.$store.getters.locInvCode);
            this.formData.invWarehouseCode = this.$store.getters.locSubInvCode;
            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.getCodeList();
            }
        }
        if (this.formData.invWarehouseCode != null) {
            this.getBusType();
        }
    },
};
</script>
<style scoped>
.ao-text {
    width: 100%;
    font-size: 13px;
    font-family: "Microsoft YaHei";
    float: right;
    text-align: right;
    margin-top: 10px;
}

#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;

}

</style>



