<template>
    <div>
        <el-card>
            <el-form :inline="true" :model="query" class="query-form" size="mini">
                <el-form-item class="query-form-item">
                    <el-input
                        v-model="query.name"
                        clearable
                        placeholder="仓库名称"
                        style="width: 400px"
                    ></el-input>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-select v-model="query.advanceType" placeholder="仓库类型" clearable>
                        <el-option label="全部" value=""></el-option>
                        <el-option label="寄售" value=true></el-option>
                        <el-option label="仓库" value=false></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item class="query-form-item">
                    <el-select v-model="query.status" placeholder="仓库状态" clearable>
                        <el-option label="全部" value=""></el-option>
                        <el-option label="正常" value='1'></el-option>
                        <el-option label="禁用" value='0'></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button-group style="margin-left: 10px;display:flex;">
                        <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
                        <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
                        <el-button type="primary" @click.native="handleForm(null, null,'addTop')"
                                   :disabled="!configParms.basicInv"
                        >添加仓库
                        </el-button
                        >
                        <el-upload
                            :action="uploadFileUrl"
                            multiple
                            :limit="1"
                            :headers="headers"
                            :data="uploadData"
                            :show-file-list="false"
                            :on-success="handleChange"
                            :file-list="fileList"
                        >
                            <el-button size="mini" type="primary" :disabled="!configParms.basicInv">导入</el-button>
                        </el-upload>
                        <el-button type="primary" icon="search" @click="exportInvwarehouse"
                                   :disabled="!configParms.basicInv">导出
                        </el-button>
                    </el-button-group>
                </el-form-item>
            </el-form>
            <el-table
                :data="mergeList"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border
                ref="table"
                highlight-current-row
                @current-change="handInvCurrentChange">
                <el-table-column label width="45">
                    <template slot-scope="scope">
                        <el-radio :label="scope.row.id" v-model="radioCheck"><span></span></el-radio>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="code"
                    label="仓库编码"
                    width="120"
                >
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="仓库名称"
                    width="250"
                >
                </el-table-column>
                <el-table-column
                    prop="advanceType"
                    width="120"
                    label="仓库类型">
                    <template slot-scope="scope">
                        <span>{{ enableMap[scope.row.advanceType] }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="level"
                    width="120"
                    label="仓库等级"
                >
                </el-table-column>
                <el-table-column
                    prop="pname"
                    width="250"
                    label="上级仓库"
                >
                </el-table-column>

                <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">

                        <el-button
                            type="text"
                            size="small"
                            :disabled="scope.row.pid!=0 ||!configParms.basicInv"
                            @click.native.stop="handleSubForm(scope.row, 'add')"
                        >添加分库
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small" :disabled="!configParms.basicInv"
                            @click.native.stop="handleForm( scope.row, 'edit')"
                        >编辑
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small"
                            :disabled="scope.row.code==1000 ||scope.row.code==1001 || !configParms.basicInv"
                            @click.native.stop="handleDel(node,scope.row)"
                        >删除
                        </el-button
                        >
                    </template>

                </el-table-column>
            </el-table>

            <el-table
                :data="subList"
                border
                highlight-current-row
                @current-change="handSubInvCurrentChange"
                style="width: 100%;">

                <el-table-column label width="45">
                    <template slot-scope="scope">
                        <el-radio :label="scope.row.id" v-model="subRadioCheck"><span></span></el-radio>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="code"
                    label="分库编码"
                >
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="分库名称"
                >
                </el-table-column>
                <el-table-column
                    prop="parentName"
                    label="所属仓库"
                >
                </el-table-column>
                <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">

                        <el-button
                            type="text"
                            size="small" :disabled="!configParms.basicInv"
                            @click.native.stop="addUser(scope.row)"
                        >管理用户
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small" :disabled="!configParms.basicInv"
                            @click.native.stop="selsectBussinessType(scope.row)"
                        >管理单据类型
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small"
                            @click.native.stop="invSpaceManage(scope.row)"
                        >管理货位
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small" :disabled="!configParms.basicInv"
                            @click.native.stop="handleSubForm( scope.row, 'edit')"
                        >编辑
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small"
                            :disabled="!configParms.basicInv"
                            @click.native.stop="handleSubDel(scope.row)"
                        >删除
                        </el-button
                        >
                    </template>

                </el-table-column>
            </el-table>
        </el-card>


        <div>
            <el-card style="width: 49%; float: left; margin-right: 0px;">
                <el-table
                    :data="userData"
                    key="row.id"
                    style="width: 100%"
                    highlight-current-row
                    @current-change="loadUserBusType"
                >
                    <el-table-column label="序号" type="index"></el-table-column>
                    <el-table-column
                        prop="username"
                        label="账号"
                        min-width="20%">
                    </el-table-column>
                    <el-table-column
                        prop="employeeName"
                        label="用户名"
                        min-width="30%">
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        min-width="30%"
                    >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                size="small" :disabled="!configParms.basicInv"
                                @click.native="relBusttype(scope.row)">
                                关联单据类型
                            </el-button>


                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    :page-size="userQuery.limit"
                    @current-change="loadUserList"
                    layout="prev, pager, next"
                    :total="userTotal"
                    :current-page="userQuery.page"
                >
                </el-pagination>
            </el-card>

            <el-card style="width: 49%; float: right; margin-left: 0px;">
                <div slot="header" class="clearfix">
                    <span>{{ busTableTitle }}</span>
                </div>
                <el-table
                    :data="bussinessTypeData"
                    key="row.id"
                    style="width: 100%">
                    <el-table-column label="序号" type="index"></el-table-column>
                    <el-table-column
                        prop="action"
                        label="单据类型编码"
                        min-width="30%">
                    </el-table-column>
                    <el-table-column
                        prop="name"
                        label="单据类型名称"
                        min-width="30%">
                    </el-table-column>
                </el-table>

                <el-pagination
                    :page-size="busQuery.limit"
                    @current-change="loadBusList"
                    layout="prev, pager, next"
                    :total="busTotal"
                    :current-page="busQuery.page"
                >
                </el-pagination>
            </el-card>
        </div>

        <!--添加用户弹窗-->
        <el-dialog
            v-if="userFormVisible"
            title="用户列表"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="userFormVisible"
        >
            <el-table v-loading="loading" :data="userList" ref="checkUserList"
                      @selection-change="handleUserSelectionChange"
                      style="width: 100%">
                <el-table-column
                    type="selection"
                    :reserve-selection="false"
                    width="55">
                </el-table-column>
                <el-table-column label="账号" prop="userName" fixed></el-table-column>
                <el-table-column label="用户名" prop="employeeName" fixed></el-table-column>
            </el-table>

            <div slot="footer" class="dialog-footer">
                <el-button @click.native="userFormVisible = !userFormVisible"
                >取消
                </el-button
                >
                <el-button
                    type="primary"
                    @click.native="addUserData()"
                >提交
                </el-button>
            </div>

        </el-dialog>
        <!--添加单据类型弹窗-->
        <el-dialog
            title="单据类型"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="bussinessTypeFormVisible"
        >
            <el-table v-loading="loading" :data="bussinessTypeList" ref="typeList"
                      @selection-change="handleBussinessTypeSelectionChange"
                      style="width: 100%">
                <el-table-column
                    type="selection"
                    :reserve-selection="true"
                    width="55">
                </el-table-column>
                <el-table-column label="单据类型编码" prop="action" fixed></el-table-column>
                <el-table-column label="单据类型名称" prop="name" fixed></el-table-column>
            </el-table>

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

            <div slot="footer" class="dialog-footer">
                <el-button @click.native="bussinessTypeFormVisible = !bussinessTypeFormVisible"
                >取消
                </el-button
                >
                <el-button
                    type="primary"
                    @click.native="addBussinessTypeData()"
                >提交
                </el-button>
            </div>

        </el-dialog>

        <!--添加单据类型弹窗---->
 <!--添加单据类型弹窗-->
 <el-dialog
            title="仓库关联单据类型"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="userBussinessTypeFormVisible"
        >
        <el-row type="flex" justify="end">
                <el-button-group style="display: flex;margin-bottom: 15px; margin-right: 50px">
                    <el-button
                        type="primary"
                        @click.native="addBussinessType()"
                        :loading="loading"
                    >选入
                    </el-button
                    >
                </el-button-group>
            </el-row>
            <el-table v-loading="loading" :data="userBussinessTypeList" ref="typeList"
                      style="width: 100%">
                <el-table-column label="单据类型编码" prop="action" fixed></el-table-column>
                <el-table-column label="单据类型名称" prop="name" fixed></el-table-column>
                <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            :disabled="!configParms.basicInv"
                            @click.native.stop="delWarehouseBussinessType(scope.row.id)"
                        >移除
                        </el-button
                        >
                    </template>

                </el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="userBussinessTypeFormVisible = !userBussinessTypeFormVisible"
                >取消
                </el-button
                >
            </div>

        </el-dialog>

        <!--表单界面-->
        <el-dialog
            :title="formMap[formName]"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="subFormVisible"
            :before-close="hideForm"
            width="60%"
            top="5vh"
        >
            <el-form :model="subData" ref="dataForm">
                <el-form-item label="所属仓库" prop="pid">
                    <el-select v-model="subData.parentId" placeholder="顶级" disabled>
                        <el-option
                            v-for="item in mergeList"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                        >
                          <span style="float: left"
                          ><span v-html="item.html"></span>{{ item.name }}</span
                          >
                        </el-option>
                    </el-select>
                </el-form-item>


                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="12" class="el-col">
                        <el-form-item label="分库编码" prop="title" class="query-form-item">
                            <el-input
                                disabled
                                v-model="subData.code" style="width: 80%"
                                auto-complete="off"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="el-col">
                        <el-form-item label="分库名称" prop="name" class="query-form-item">
                            <el-input
                                v-model="subData.name" style="width: 80%"
                                auto-complete="off"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-table :data="sysSubList" style="width: 100%; margin-bottom: 30px;" border>
                    <el-table-column label="序号" type="index"></el-table-column>
                    <el-table-column
                        label="第三方系统名称"
                        prop="sysName"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="第三方仓库ID"
                        prop="thirdId"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="第三方仓库名称"
                        prop="thirdName"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column label="操作" fixed="right">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                size="small"
                                :disabled="!configParms.basicInv"
                                @click="intentSubSelect(scope.row)"
                            >关联
                            </el-button
                            >
                            <el-button type="text" size="small" @click.native.stop="unbindSubThrWarehouse(scope.row)"
                                       :disabled="scope.row.thirdId=='' ||scope.row.thirdId==null ||!configParms.basicInv"
                            >解绑
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideForm">取消</el-button>
                <el-button
                    type="primary"
                    @click.native="forSubSubmit()"
                    :loading="formLoading"
                >提交
                </el-button
                >
            </div>
        </el-dialog>

        <!-- 添加仓库弹窗-->
        <el-dialog
            :title="formMap[formName]"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :visible.sync="formVisible"
            :before-close="hideForm"
            width="60%"
            top="5vh"
        >

            <el-table v-if="thirdSysVisible" :data="sysList" style="width: 100%; margin-bottom: 30px;" border>
                <el-table-column label="序号" type="index"></el-table-column>
                <el-table-column
                    label="第三方系统名称"
                    prop="sysName"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    label="第三方仓库ID"
                    prop="thirdId"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    label="第三方仓库名称"
                    prop="thirdName"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            :disabled="!configParms.basicInv"
                            @click="intentSelect(scope.row)"
                        >关联
                        </el-button
                        >
                        <el-button type="text" size="small" @click.native.stop="unbindThrWarehouse(scope.row)"
                                   :disabled="scope.row.thirdId=='' ||scope.row.thirdId==null ||!configParms.basicInv"
                        >解绑
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <el-form :model="formData" :rules="formRules" ref="dataForm">


                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="12" class="el-col">
                        <el-form-item label="仓库编码" prop="title" class="query-form-item">
                            <el-input
                                v-model="formData.code" style="width: 80%"
                                auto-complete="off"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="el-col">
                        <el-form-item label="仓库名称" prop="name" class="query-form-item">
                            <el-input
                                v-model="formData.name" style="width: 80%"
                                auto-complete="off"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="12" class="el-col">
                        <el-form-item class="query-form-item" label="仓库等级:">
                            <el-select v-model="formData.level" placeholder="仓库等级" clearable @change="changeLevel"
                                       :disabled="mutiInvMode">
                                <el-option label="1 级库" :value='1'></el-option>
                                <el-option label="2 级库" :value='2'></el-option>
                                <el-option label="3 级库" :value='3'></el-option>
                                <el-option label="4 级库" :value='4'></el-option>
                                <el-option label="5 级库" :value='5'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="el-col">
                        <el-form-item class="query-form-item" label="上级仓库:">
                            <el-select v-model="formData.pcode" placeholder="请选择当前仓库"
                                       :disabled="!mutiInvMode"
                                       clearable="true" size="mini" @change="pcodeChange">
                                <el-option
                                    v-for="item in pCodes"
                                    :key="item.name"
                                    :label="item.name"
                                    :value="item.code">
                                    <span style="float: left">{{ item.name }}</span>
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="12" class="el-col">
                        <el-form-item class="query-form-item" label="仓库类型:">
                            <el-select v-model="formData.advanceType" placeholder="仓库类型"
                                       :disabled="formName =='edit'">
                                <el-option label="寄售" :value='true'></el-option>
                                <el-option label="仓库" :value='false'></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="el-col">
                        <el-form-item label="状态:" prop="status" class="query-form-item">
                            <el-radio-group v-model="formData.status" @change="statusChange"
                                            :disabled="formName!='edit'">
                                <el-radio :label="0">禁用</el-radio>
                                <el-radio :label="1">正常</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20" class="el-row" type="flex">
                    <el-col :span="12" class="el-col">
                        <div class="text item">
                            <el-checkbox v-model="formData.spUse" :disabled="formData.level!='1'">是否允许供应商使用
                            </el-checkbox>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideForm">取消</el-button>
                <el-button
                    type="primary"
                    :disabled="!configParms.basicInv"
                    @click.native="formSubmit()"
                    :loading="formLoading"
                >提交
                </el-button
                >
            </div>
        </el-dialog>
        <el-dialog title="关联仓库" :visible.sync="thrWareHouseVisible"
                   :close-on-click-modal="false"
                   :close-on-press-escape="false">
            <el-form :inline="true" :model="query" class="query-form" size="mini">
                <el-form-item class="query-form-item">
                    <el-input
                        v-model="thirdQuery.key"
                        clearable
                        placeholder="仓库名称"
                        style="width: 400px"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button-group>
                        <el-button type="primary" icon="search" @click="thrInvsearch">查询</el-button>
                    </el-button-group>
                </el-form-item>
            </el-form>
            <el-table
                :data="thrWarehouseData"
                style="width: 100%;margin-top: 10px;"
                row-key="id"
                border
                highlight-current-row
                @current-change="changeThrWarehouse"
                default-expand-all
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column
                    type="index"
                    label="序号"
                >
                </el-table-column>
                <el-table-column
                    prop="code"
                    label="仓库编码"
                >
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="仓库名称"
                >

                </el-table-column>
                <el-table-column
                    prop="advanceType"
                    label="仓库类型">
                    <template slot-scope="scope">
                        <span>{{ enableMap[scope.row.advanceType] }}</span>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                :page-size="query.limit"
                @current-change="handleCurrentChange"
                layout="prev, pager, next"
                :total="total"
                :current-page="query.page"
            >
            </el-pagination>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideThrWarehouseTable()">取消</el-button>
                <el-button
                    type="primary"
                    @click.native="bindThrWarehouse()"
                    :loading="formLoading"
                >提交
                </el-button>
            </div>
        </el-dialog>
        <el-dialog title="关联分库" :visible.sync="thrSubWareHouseVisible">
            <el-form :inline="true" :model="thirdSubQuery" class="query-form" size="mini">
                <el-form-item class="query-form-item">
                    <el-input
                        v-model="thirdSubQuery.name"
                        clearable
                        placeholder="分库名称"
                        style="width: 400px"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button-group>
                        <el-button type="primary" icon="search" @click="intentSubSelect">查询</el-button>
                    </el-button-group>
                </el-form-item>
            </el-form>
            <el-table
                :data="thrSubWarehouseData"
                style="width: 100%;margin-top: 10px;"
                row-key="id"
                border
                highlight-current-row
                @current-change="changeSubThrWarehouse"
            >
                <el-table-column
                    type="index"
                    label="序号"
                >
                </el-table-column>
                <el-table-column
                    prop="code"
                    label="分库编码"
                >
                </el-table-column>
                <el-table-column
                    prop="name"
                    label="分库名称"
                >
                </el-table-column>
            </el-table>
            <el-pagination
                :page-size="thirdSubQuery.limit"
                @current-change="handleSubCurrentChange"
                layout="prev, pager, next"
                :total="subTotal"
                :current-page="thirdSubQuery.page"
            >
            </el-pagination>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideThrWarehouseTable()">取消</el-button>
                <el-button
                    type="primary"
                    @click.native="bindSubThrWarehouse()"
                    :loading="formLoading"
                >提交
                </el-button>
            </div>
        </el-dialog>

        <!--用户关联单据类型-->
        <el-dialog
            title="业务类型关联"
            :visible.sync="relBusUserVisile"
            width="70%"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            v-if="relBusUserVisile"
        >
            <relBusUserDialog :inputQuery="curSeleUser" :closeDialog="cancelRelBusDiaolog"></relBusUserDialog>
        </el-dialog>

        <!--货位管理-->
        <el-dialog
            title="货位管理"
            :visible.sync="invSpaceManageVisible"
            width="70%"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            v-if="invSpaceManageVisible"
        >
            <invSpaceManage :invInfo="currentInvInfo" ></invSpaceManage>
        </el-dialog>

    </div>
</template>

<script>
import {
    filterList, filterAll,
    saveWarehouse, exportJson, uploadStatus,
    deleteWarehouse, warehouseBussinessTypeList,
    warehouseUserList, saveWarehouseBussinessType,
    saveWarehouseUser, updateDirector, disableWarehouse,
    deleteWarehouseBussinessType,
    bindThrWarehouse, unbindThrWarehouse, filterThridSubByInv, getThrsysDetail,delWarehouseBussinessType
} from "../../api/basic/invWarehouse";
import {
    filterSubAll, saveSubWarehouse, deleteSubWarehouse,
    getSubThrsysDetail, bindThrSubWarehouse, unbindSubThrWarehouse
} from "../../api/basic/invSubWarehouse";
import {filterThrList} from "@/api/thrsys/thrInvWarehouse";
import {getHospitalUserList} from "../../api/auth/authUser";
import {getJoinBussinessType} from "../../api/basic/bussinessType";
import {formatDate} from "@/utils/date";
import axios from "axios";
import store from "@/store";
import {findConfig} from "@/api/thrsys/spsSyncStatus";
import {isBlank} from "@/utils/strUtil";
import relBusUserDialog from "./invWarehouseRelBusTypes";
import {selectSysParamByKey} from "@/api/param/systemParamConfig";
import {filterUserBusTypeList} from "@/api/inventory/invRelBusTypes";
import invSpaceManage from "@/views/inventory/InvSpaceManage";

const formJson = {
    id: null,
    pid: null,
    name: null,
    code: null,
    status: 1,
    advanceType: false,
    isDefault: false,
    level: 1,
    spUse: false,
};
export default {
    data() {
        return {
            radioCheck: null,
            subRadioCheck: null,
            query: {
                id: null,
                pid: null,
                name: null,
                code: null,
                status: "1",
                advanceType: null,
                isDefault: null
            },
            headers: {},
            mergeList: [],
            subList: [],
            node: null,
            defaultProps: {
                children: "children",
                label: "name"
            },
            // setDictor: "设为主管",
            fileList: [],
            pCodes: [],
            uploadData: {},
            loading: true,
            index: null,
            formName: null,
            formMap: {
                addTop: "添加分库",
                add: "添加货位",
                edit: "编辑"
            },
            enableMap: {
                true: "寄售",
                false: "仓库",
            },
            directorMap: {
                true: "取消主管",
                false: "设为主管",
            },
            formLoading: false,
            subFormVisible: false,
            formVisible: false,
            formData: formJson,
            formRules: {
                name: [
                    {required: true, message: "请输入仓库货位名", trigger: "blur"}
                ],
                code: [
                    {required: true, message: "请输入仓库货位代码", trigger: "blur"}
                ]
            },
            pidData: {},
            deleteLoading: false,
            uploadFileUrl: null,
            userData: [],
            bussinessTypeData: [],
            userList: null,
            bussinessTypeList: null,
            userFormVisible: false,
            relBusUserVisile: false,
            currentCode: null,
            superRow: null,
            currentRow: {status: 1},
            selectUserList: [],
            selectBussinessTypeList: [],
            bussinessTypeFormVisible: false,
            thrWarehouseData: [],
            thrSubWarehouseData: [],
            currentId: null,
            currentSubId: null,
            thrWareHouseVisible: false,
            thrSubWareHouseVisible: false,
            userBussinessTypeList:[],
            userBussinessTypeFormVisible:false,
            sysList: [],
            sysSubList: [],
            checkThrWarehouseRow: null,
            checkSubThrWarehouseRow: null,
            currentSysId: null,
            thirdSysVisible: false,
            total: 0,
            subTotal: 0,
            thirdQuery: {
                key: null,
                page: 1,
                limit: 10,
                thirdSysFk: "thirdId",
            },
            thirdSubQuery: {
                parentId: null,
                name: null,
                page: 1,
                limit: 10,
                thirdSysFk: "thirdId",
            },
            configParms: {},

            mutiInvMode: true,
            subData: {},
            subFromName: "add",
            userQuery: {
                code: null,
                page: 1,
                limit: 10
            },
            userTotal: 0,
            busQuery: {
                code: null,
                page: 1,
                limit: 10
            },
            busTotal: 0,
            hospitalUserQuery: {
                page: 1,
                limit: 10
            },
            hospitalUserTotal: 0,
            bussinessTypeQuery: {
                enabled: true,
                page: 1,
                limit: 10,
                ids:""
            },
            bussinessTypeTotal: 0,
            curSeleUser: null,
            busTableTitle: null,
            currentInvInfo: {
                invStorageCode: null,
                invWarehouseCode: null
            },
            invSpaceManageVisible: false
        };
    },
    methods: {
        onReset() {
            this.$router.push({
                path: "",
            });
            this.query = {
                name: "",
                status: "",
            };
            this.userQuery.page = 1;
            this.busQuery.page = 1;
            this.getList();

            this.$refs.table.clearSelection();
        },
        onSubmit() {
            this.$refs.table.setCurrentRow();
            this.getList();
        },
        getList() {
            this.loading = true;
            filterList(this.query)
                .then((response) => {
                    this.loading = false;
                    this.mergeList = response.data.list || [];
                    this.subList = [];
                })
                .catch(() => {
                    this.loading = false;
                    this.mergeList = [];
                });
        },
        // 刷新表单
        resetForm() {
            if (this.$refs["dataForm"]) {
                // 清空验证信息表单
                this.$refs["dataForm"].clearValidate();
                // 刷新表单
                this.$refs["dataForm"].resetFields();
                this.getList();
            }
        },
        // 隐藏表单
        hideForm() {
            // 更改值
            this.formVisible = false;
            this.subFormVisible = false;
            // this.loadSubData(this.currentCode);
            return true;
        },
        // 显示表单
        handleForm(data, formName) {
            if (null != data) {
                this.currentId = data.id;
                this.thirdSysVisible = true;
            } else {
                this.thirdSysVisible = false;
            }
            this.pidData = data || null;
            formJson.pid = (data && parseInt(data.id)) || "";
            this.formData = JSON.parse(JSON.stringify(formJson));
            if (formName === "edit") {
                if (data.pid == 0) {
                    this.formVisible = true;
                } else {
                    this.subFormVisible = true;
                }

                this.formData = Object.assign({}, data);
            } else {
                this.formVisible = true;
            }
            this.formName = formName;
            this.getParentInv(this.formData.level);
            this.getThrsysDetailData();
        },
        getThrsysDetailData() {
            let params = {
                id: this.currentId
            };
            getThrsysDetail(params)
                .then((response) => {
                    this.loading = false;
                    this.sysList = response.data.list || [];
                })
                .catch(() => {
                    this.loading = false;
                    this.sysList = [];
                });
        },
        getSubThrsysDetailData() {
            let params = {
                id: this.subData.code,
            };
            getSubThrsysDetail(params)
                .then((response) => {
                    this.loading = false;
                    this.sysSubList = response.data.list || [];
                })
                .catch(() => {
                    this.loading = false;
                    this.sysSubList = [];
                });
        },

        handleSubForm(data, formName) {
            this.subFromName = formName;

            if (formName === "edit") {
                this.subData = JSON.parse(JSON.stringify(data));
            } else if (formName === "add") {
                this.subData = {};
                this.subData.parentId = data.code;
            }
            ;
            this.subFormVisible = true;
            this.getSubThrsysDetailData();
        },
        //添加仓库
        formSubmit() {
            this.$refs["dataForm"].validate((valid) => {

                if (valid) {
                    if (isBlank(this.formData.pcode) && this.formData.level != 1) {
                        this.$message.warning("上级仓库不能为空");
                        return;
                    }
                    if (isBlank(this.formData.name)) {
                        this.$message.warning("仓库名称不能为空");
                        return;
                    }
                    this.formLoading = true;
                    let data = Object.assign({}, this.formData);
                    saveWarehouse(data, this.formName)
                        .then((response) => {
                            this.formLoading = false;
                            this.subFormVisible = false;
                            if (response.code !== 20000) {
                                this.$message.error(response.message);
                                return false;
                            }
                            this.$message.success("操作成功");
                            this.formVisible = false;

                            if (this.formName !== "edit") {

                                if (response.data && response.data.id) {
                                    data.id = response.data.id;
                                    if (this.pidData) {
                                        if (!this.pidData.children) {
                                            this.$set(this.pidData, "children", []);
                                        }
                                        this.pidData.children.push(data);
                                    } else {
                                        this.mergeList.push(data);
                                    }
                                }
                            } else {
                            }
                            // 刷新表单
                            this.resetForm();
                            this.getList();
                        })
                        .catch(() => {
                            this.formLoading = false;
                            this.subFormVisible = false;
                        });
                }
            });
        },

        //添加分库
        forSubSubmit() {

            if (this.$isBlank(this.subData.name)) {
                this.$message.error("分库名称不能为空！");
                return;
            }
            saveSubWarehouse(this.subData, this.subFromName).then((response) => {
                if (response.code == 20000) {
                    this.loadSubData(this.subData.parentId);
                    this.subFormVisible = false;
                } else {
                    this.$message.error(response.message);
                    this.subFormVisible = false;
                }
            }).catch(() => {
                this.subFormVisible = false;
            });

        },
        // 删除
        handleDel(node, data) {
            if (data.children && data.children.length > 0) {
                this.$alert("请先删除子节点", "提示", {
                    confirmButtonText: "确定",
                });
                return false;
            }
            if (data.id) {
                this.$confirm("确认删除该仓库吗?", "提示", {
                    type: "warning",
                })
                    .then(() => {
                        this.deleteLoading = true;
                        let para = {id: data.id};
                        deleteWarehouse(para)
                            .then((response) => {
                                this.deleteLoading = false;
                                if (response.code !== 20000) {
                                    this.$message.error(response.message);
                                    return false;
                                }
                                this.$message.success("删除成功");
                                this.getList();
                                const parent = node.parent;
                                const children = parent.data.children || parent.data;
                                const index = children.findIndex((d) => d.id === data.id);
                                children.splice(index, 1);
                            })
                            .catch(() => {
                                this.deleteLoading = false;
                            });
                    })
                    .catch(() => {
                        this.$message.info("取消删除");
                    });
            }
        },


        handleSubDel(row) {
            if (row.id) {
                this.$confirm("确认删除该分库吗?", "提示", {
                    type: "warning",
                })
                    .then(() => {
                        this.deleteLoading = true;
                        let para = {id: row.id};
                        deleteSubWarehouse(para)
                            .then((response) => {
                                this.deleteLoading = false;
                                if (response.code !== 20000) {
                                    this.$message.error(response.message);
                                    return false;
                                }
                                this.$message.success("删除成功");
                                this.loadSubData(row.parentId);
                            })
                            .catch(() => {
                                this.deleteLoading = false;
                            });
                    })
                    .catch(() => {
                        this.$message.info("取消删除");
                    });
            }
        },

        getProjectNum() {
            const projectTime = new Date() // 当前中国标准时间
            const Year = projectTime.getFullYear() // 获取当前年份 支持IE和火狐浏览器.
            const Month = projectTime.getMonth() + 1 // 获取中国区月份
            const Day = projectTime.getDate() // 获取几号
            var CurrentDate = Year
            if (Month >= 10) { // 判断月份和几号是否大于10或者小于10
                CurrentDate += Month
            } else {
                CurrentDate += '0' + Month
            }
            if (Day >= 10) {
                CurrentDate += Day
            } else {
                CurrentDate += '0' + Day
            }
            return CurrentDate
        },

        uploadInvwarehouse() {
            let tempQuery = {};
            uploadStatus(tempQuery)
                .then((response) => {
                    if (response.code == 20000) {
                        this.$message.success(response.data);
                    } else {
                        this.$message.error(response.message);
                    }
                })
                .catch(() => {
                });
        },

        exportInvwarehouse() {
            let tquery = {};
            exportJson(tquery).then((response) => {
                const binaryData = [];
                binaryData.push(response);
                let url = window.URL.createObjectURL(
                    new Blob(binaryData, {type: "application/json"})
                );
                this.loading = false;
                const eleLink = document.createElement('a');
                var timestamp = formatDate(new Date(), "yyyyMMddhhmmss")
                // eleLink.download = "仓库信息导出" + timestamp + ".udi";
                eleLink.download = "BaseWarehouse_" + timestamp + ".LowerIn";
                eleLink.style.display = 'none';
                eleLink.href = url;
                document.body.appendChild(eleLink)
                eleLink.click()
                document.body.removeChild(eleLink)
            }).catch(() => {
                this.loading = false;
            });

        },
        handleChange(response, files, fileList) {
            if (response.code != 20000) {
                this.$message.error(response.message);
            } else {
                this.$message.success(response.data);
                this.getList();
            }
        },


        init() {
            axios.get("./config.json").then(res => {
                // 基础地址
                let response = res.data.BASE_URL;
                this.uploadFileUrl = response + "/spms/inv/warehouse/uploadJson";
            });
            this.headers = {
                ADMIN_ID: store.getters.adminId,
                ADMIN_TOKEN: store.getters.token,
            };
        },

        getParentInv(data) {
            this.pCodes = [];
            let query = {level: data - 1};
            filterAll(query)
                .then((response) => {
                    this.pCodes = response.data || [];
                })
                .catch(() => {
                });
        },
        changeLevel(row) {
            this.formData.pcode = null;
            //TODO
            this.getParentInv(this.formData.level);
        },

        pcodeChange() {
            this.$forceUpdate()
        },

        handInvCurrentChange(row) {
            this.radioCheck = row.id;
            this.subList = [];
            this.userList = null;
            this.bussinessTypeList = null;
            this.superRow = row;
            this.loadSubData(row.code);
        },

        handSubInvCurrentChange(row) {
            this.subRadioCheck = row.id;
            this.currentCode = row.code;
            this.currentRow = row;
            this.curSeleUser = null;
            this.busTableTitle = "仓库 " + '"' + row.name + '"' + ": 关联单据类型";
            this.loadLinkData(row)
        },

        loadSubData(parentId) {
            this.userData = [];
            this.bussinessTypeData = [];
            let subQuery = {
                parentId: parentId,
            }
            filterSubAll(subQuery).then((res) => {
                if (res.code == 20000) {
                    this.subList = res.data;
                }
            }).catch((error) => {
            });
        },

        loadLinkData(row) {
            this.userQuery.page = 1;
            this.busQuery.page = 1;
            this.userQuery.code = row.code;
            this.busQuery.code = row.code;
            this.curSeleUser = null;
            //加载用户数据
            this.loadUserList();

            //加载单据类型数据
            this.loadBusList();
        },
        loadUserList(val) {
            if (val != null) {
                this.userQuery.page = val;
            }
            //加载用户数据
            warehouseUserList(this.userQuery).then((res) => {
                this.userData = res.data.list;
                this.userTotal = res.data.total;
            }).catch((error) => {
                this.$message.error("用户数据加载失败")
            });
        },
        loadBusList(val) {
            //根据是否选择用户切换不同的分页方法
            if (this.curSeleUser == null) {
                if (val != null) {
                    this.busQuery.page = val;
                }
                //加载单据类型数据
                warehouseBussinessTypeList(this.busQuery).then((res) => {
                    this.bussinessTypeData = res.data.list;
                    this.busTotal = res.data.total;
                }).catch((error) => {
                    this.$message.error("单据类型数据加载失败")
                });
            } else {
                this.getUserBusTypeList(val);
            }
        },
        addUser(row) {
            this.currentCode = row.code;
            this.currentRow = row;
            this.loadLinkData(row);
            if (this.currentCode == null || this.currentCode == '') {
                this.$message.error("请先选择分库");
            } else if (this.currentCode != row.code) {
                this.$message.error("请先选择当前分库！")
            } else {
                this.userFormVisible = true;
                this.hospitalUserQuery.page = 1;
                this.getHospitalUser();
            }
        },
        cancelRelBusDiaolog() {
            this.relBusUserVisile = false;
            this.getUserBusTypeList(1);
        },
        getHospitalUser(val) {
            if (val != null) {
                this.hospitalUserQuery.page = val;
            }
            getHospitalUserList(this.hospitalUserQuery).then((res) => {
                this.selectUserList = [];
                this.userList = res.data;
                this.hospitalUserTotal = res.data.total;
                var that = this;
                that.$nextTick(() => {
                    if (that.$refs.checkUserList) {
                        that.$refs.checkUserList.clearSelection();
                    }
                    that.userList.forEach(row => {
                        for (let j in that.userData) {
                            if (row.id == that.userData[j].userid) {
                                that.$refs.checkUserList.toggleRowSelection(row, true);
                            }
                        }
                    });
                })
            });
        },
        getBussinessType(val,obj) {
            if (val != null) {
                this.bussinessTypeQuery.page = val;
            }
            if(obj!=undefined){
                var action=obj.toString();
                this.bussinessTypeQuery.ids=action;
            }

            this.bussinessTypeQuery.code=this.busQuery.code;
            getJoinBussinessType(this.bussinessTypeQuery).then((res) => {
                this.selectBussinessTypeList = [];
                this.bussinessTypeList = res.data.list;
                this.bussinessTypeTotal = res.data.total;
                var that = this;
                that.$nextTick(() => {
                    if (that.$refs.typeList) {
                        that.$refs.typeList.clearSelection();
                    }
                    that.bussinessTypeList.forEach(row => {
                        if (row.checkSelect==true) {
                                that.$refs.typeList.toggleRowSelection(row, true);
                        }
                    });
                });
            }).catch((error) => {
            });
        },
        handleUserSelectionChange(row) {
            let _this = this;
            _this.selectUserList = [];
            row.forEach((item) => {
                _this.selectUserList.push(item);
            })
        },
        handleBussinessTypeSelectionChange(row) {
            let _this = this;
            _this.selectBussinessTypeList = [];
            row.forEach((item) => {
                _this.selectBussinessTypeList.push(item);
            })
        },
        addUserData() {
            let query = {
                code: this.currentCode,
                userList: JSON.stringify(this.selectUserList)
            };
            saveWarehouseUser(query).then((res) => {
                if (res.code === 20000) {
                    this.userFormVisible = false;
                    this.$message.success("添加成功");
                    this.userQuery = {
                        code: this.currentCode,
                        page: 1,
                        limit: 10
                    }
                    //重新加载数据
                    warehouseUserList(this.userQuery).then((res) => {
                        this.userData = res.data.list;
                        this.userTotal = res.data.total;
                    }).catch((error) => {
                        this.userData = [];
                        this.userTotal = 0;
                    });
                } else {
                    this.$message.error(res.message);
                }
            }).catch((error) => {
                this.$message.error("添加失败");
            });
        },
        statusChange() {
            if (this.formData.status == 0) {
                let query = {
                    code: this.formData.code,
                }
                disableWarehouse(query).then((res) => {
                    if (res.code != 20000) {
                        this.formData.status = 1;
                        this.$message.error(res.message);
                    }
                }).catch((error) => {
                });
            }
        },
        // addBussinessType(row) {
        //     this.currentCode = row.code;
        //     this.currentRow = row;
        //     this.loadLinkData(row);
        //     if (this.currentCode == null || this.currentCode == '') {
        //         this.$message.error('请先选择仓库');
        //     } else if (this.currentCode != row.code) {
        //         this.$message.error("请先选择当前分库！")
        //     } else {
        //         this.bussinessTypeFormVisible = true;
        //         this.bussinessTypeQuery.page = 1;
        //         this.getBussinessType();
        //     }
        // },
        addBussinessType(row) {
            var action=[];
                for(var i=0;i<this.userBussinessTypeList.length;i++){
                    action.push(this.userBussinessTypeList[i].action);
                }
                this.bussinessTypeFormVisible = true;
                this.bussinessTypeQuery.page = 1;
                this.getBussinessType(1,action);
        },
        selsectBussinessType(row){
            if (this.currentRow.id !== row.id) {
                this.$message.error("请先选择需要操作的分库！");
                return;
            }
          var busQuery = {
                      code: this.currentCode,
                      page: 1,
                      limit: 50
                  }

          warehouseBussinessTypeList(busQuery).then((res) => {
                  this.userBussinessTypeList = res.data.list;
              }).catch((error) => {
                  this.$message.error("单据类型数据加载失败")
              });
          this.userBussinessTypeFormVisible = true;
      },
        addBussinessTypeData() {
            // if (this.selectBussinessTypeList.length == 0) {
            //     this.$message.error("请选择单据类型")
            // } else {
            this.bussinessTypeFormVisible = false;
            let query = {
                code: this.currentCode,
                bussinessTypes: JSON.stringify(this.selectBussinessTypeList)
            };
            saveWarehouseBussinessType(query).then((res) => {

                if (res.code == 20000) {
                    this.$message.success("修改成功！");
                    //重新加载数据表格
                    this.busQuery = {
                        code: this.currentCode,
                        page: 1,
                        limit: 10
                    }
                    warehouseBussinessTypeList(this.busQuery).then((res) => {
                        this.bussinessTypeData = res.data.list;
                        this.busTotal = res.data.total;
                    }).catch((error) => {
                        this.bussinessTypeData = [];
                        this.busTotal = 0;
                    });
                    this.selectWhouseBussinessType();
                } else {
                    this.$message.error(res.message);
                }


            }).catch((error) => {
            });
            // }
        },
        selectWhouseBussinessType(){
            var busQuery = {
                        code: this.currentCode,
                        page: 1,
                        limit: 50
                    }
                    warehouseBussinessTypeList(busQuery).then((res) => {

                        this.userBussinessTypeList = res.data.list || [];
                    }).catch((error) => {
                    });
        },
        updateDirector(row) {
            row.director = !row.director;
            updateDirector(row).then((res) => {
                this.$message.success("设置成功");
                //重新加载表格数据
                let loadParam = {
                    code: this.currentCode
                };
                //重新加载数据
                warehouseUserList(loadParam).then((res) => {
                    this.userData = res.data;
                }).catch((error) => {
                });
            }).catch((error) => {
                this.$message.error("设置失败");
            });
        },

        relBusttype(row) {
            this.curSeleUser = row;
            this.relBusUserVisile = true;
        },
       //删除仓库关联单据
       handleUserSubDel(row){
            if (row.id) {
                this.$confirm("确认移除单据吗?", "提示", {
                    type: "warning",
                })
                    .then(() => {
                        this.deleteLoading = true;
                        let para = {id: row.id};
                        deleteSubWarehouse(para)
                            .then((response) => {
                                this.deleteLoading = false;
                                if (response.code !== 20000) {
                                    this.$message.error(response.message);
                                    return false;
                                }
                                this.$message.success("删除成功");
                                this.loadSubData(row.parentId);
                            })
                            .catch(() => {
                                this.deleteLoading = false;
                            });
                    })
                    .catch(() => {
                        this.$message.info("取消删除");
                    });
            }
        },

        delWarehouseBussinessType(id) {
            let params = {id: id};
            deleteWarehouseBussinessType(params).then((res) => {
                if (res.code == 20000) {
                    this.$message.success("已移除");
                    this.bussinessTypeData = [];
                    this.selectWhouseBussinessType();
              var busQuerys = {
                        code: this.currentCode,
                        page: 1,
                        limit: 10
                    }
            warehouseBussinessTypeList(busQuerys).then((res) => {
                    this.bussinessTypeData = res.data.list;
                }).catch((error) => {
                    this.$message.error("单据类型数据加载失败")
                });

                } else {
                    this.$message.error(res.message);
                }
            }).catch((error) => {
                this.$message.error("移除失败");
            })
        },
        //绑定第三方仓库
        bindThrWarehouse() {

            if (this.checkThrWarehouseRow == null) {
                this.$message.error("请先选择绑定仓库！");
                return;
            }

            this.thrWareHouseVisible = false;
            let params = {
                id: this.currentId,
                thridWarehouseId: this.checkThrWarehouseRow.code,
                sysId: this.currentSysId
            }
            bindThrWarehouse(params).then((res) => {
                if (res.code == 20000) {
                    this.$message.success("绑定成功")
                    this.getThrsysDetailData();
                }

            }).catch((error) => {
                this.$message.error("绑定失败")
            })
        },
        //解绑第三方仓库
        unbindThrWarehouse(row) {
            let params = {
                id: this.currentId,
                sysId: row.sysId
            };
            unbindThrWarehouse(params).then((res) => {
                this.$message.success("解绑成功");
                this.getThrsysDetailData();
            }).catch((error) => {
                this.$message.error("解绑失败");
            })
        },

        //绑定第三方分库
        bindSubThrWarehouse() {

            let params = {
                id: this.subData.id,
                thridWarehouseId: this.checkSubThrWarehouseRow.code,
                sysId: this.checkSubThrWarehouseRow.thirdSysFk
            }
            bindThrSubWarehouse(params).then((res) => {
                if (res.code == 20000) {
                    this.$message.success("绑定成功")
                    this.getSubThrsysDetailData();
                }
                this.thrSubWareHouseVisible = false;
            }).catch((error) => {
                this.$message.error("绑定失败");
                this.thrSubWareHouseVisible = false;
            })
        },
        //解绑第三方分库
        unbindSubThrWarehouse(row) {
            let params = {
                id: this.subData.id,
                sysId: row.sysId
            };
            unbindSubThrWarehouse(params).then((res) => {
                this.$message.success("解绑成功");
                this.getSubThrsysDetailData();
            }).catch((error) => {
                this.$message.error("解绑失败");
            })
        },

        thrInvsearch() {
            filterThrList(this.thirdQuery).then((res) => {
                this.thrWarehouseData = res.data.list;
                this.total = res.data.total || 0;

            }).catch((error) => {
                this.thrWarehouseData = [];
                this.total = 0;
                this.$message.error("第三方仓库数据加载失败");
            });
            this.$forceUpdate();
        },

        intentSelect(row) {
            this.thrWareHouseVisible = true;
            if (row != null) {
                this.currentSysId = row.sysId;
                this.thirdQuery.thirdSysFk = this.currentSysId;
            }

            console.log("  this.currentSysId = " + this.currentSysId);
            //加载第三方仓库数据

            this.thrWarehouseData = [];
            filterThrList(this.thirdQuery).then((res) => {
                this.thrWarehouseData = res.data.list;
                this.total = res.data.total || 0;

            }).catch((error) => {
                this.thrWarehouseData = [];
                this.total = 0;
                this.$message.error("第三方仓库数据加载失败");
            });
            this.$forceUpdate();
        },

        intentSubSelect(row) {
            if (row != null) {
                this.thirdSubQuery.parentId = this.superRow.code;
                if (row.sysId != null && row.sysId != undefined) {
                    this.thirdSubQuery.thirdSysFk = row.sysId;
                }
            }
            this.thrSubWarehouseData = [];
            this.thrSubWareHouseVisible = true;
            filterThridSubByInv(this.thirdSubQuery).then((res) => {
                if (res.code == 20000) {
                    this.thrSubWarehouseData = res.data.list;
                    this.subTotal = res.data.total || 0;
                } else {
                    this.$message.error(res.message);
                }

            }).catch((error) => {
                this.thrWarehouseData = [];
                this.subTotal = 0;
                this.$message.error("第三方分库库数据加载失败");
            });
        },


        handleCurrentChange(val) {
            this.thirdQuery.page = val;
            this.intentSelect();
        },
        handleSubCurrentChange(val) {
            this.thirdSubQuery.page = val;
            this.intentSubSelect();
        },
        changeThrWarehouse(row) {
            this.checkThrWarehouseRow = row;
        },
        changeSubThrWarehouse(row) {
            this.checkSubThrWarehouseRow = row;
        },
        hideThrWarehouseTable() {
            this.thrWareHouseVisible = false;
            this.thrSubWareHouseVisible = false;
        },
        getSyncConfig() {
            findConfig()
                .then((response) => {
                    if (response.code == 20000) {
                        this.configParms = response.data;
                    }
                })
                .catch(() => {
                });


            let query = {
                paramKey: "muti_inv_mode",
            };
            selectSysParamByKey(query).then((response) => {
                if (response.code == 20000) {
                    if (response.data.paramValue == "1") {
                        this.mutiInvMode = true;
                    } else {
                        this.mutiInvMode = false;
                    }
                }
            });
        },
        loadUserBusType(row) {
            this.busTableTitle = "用户 " + '"' + row.employeeName + '"' + ": 关联单据类型";
            this.curSeleUser = row;
            this.getUserBusTypeList(1);
        },

        getUserBusTypeList(page) {
            let queryParam = {
                subInvCode: this.currentCode,
                userId: this.curSeleUser.userid,
                page: page,
                limit: 10
            };
            filterUserBusTypeList(queryParam).then((res) => {
                if (res.code === 20000) {
                    this.bussinessTypeData = res.data.list || [];
                    this.busTotal = res.data.total || 0;
                }
            }).catch((error) => {
            })
        },
        invSpaceManage(row) {
            this.currentInvInfo = {
                invStorageCode: row.parentId,
                invWarehouseCode: row.code
            };
            this.invSpaceManageVisible = true;
        },
    },
    filters: {
        statusFilterType(status) {
            const statusMap = {
                0: "gray",
                1: "success",
            };
            return statusMap[status];
        },
        statusFilterName(status) {
            const statusMap = {
                0: "禁用",
                1: "正常",
            };
            return statusMap[status];
        }
    },
    mounted() {
    },
    components: {
        relBusUserDialog,
        invSpaceManage
    },
    created() {
        // 加载表格数据
        this.init();
        this.getList();
        this.getSyncConfig();
    }
};
</script>

<style type="text/scss" lang="scss">

</style>
