<template>
    <div>
        <el-card class="el-card">
            <el-form
                :inline="true"
                :model="query"
                class="query-form"
                size="mini"
            >
                <el-row>
                    <el-form-item class="query-form-item">
                        <el-input v-model="query.billNo" placeholder="单据号" clearable></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-select v-model="query.billType" placeholder="请选择业务类型" clearable="true" size="mini">
                            <el-option
                                v-for="item in busTypes"
                                :key="item.localName"
                                :label="item.localName"
                                :value="item.localAction">
                                <span style="float: left">{{ item.localName }}</span>
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item class="query-form-item" v-if="isSp ==110">
                        <el-input v-model="query.corpName" placeholder="往来单位" clearable></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-select v-model="query.locStorageCode"
                                   placeholder="请选择当前仓库" clearable="true" size="mini"
                                   @change="invChange">
                            <el-option
                                v-for="item in storageList"
                                :key="item.name"
                                :label="item.name"
                                :value="item.code">
                                <span style="float: left">{{ item.name }}</span>
                            </el-option>
                        </el-select>
                    </el-form-item>


                    <el-form-item class="query-form-item">
                        <el-select v-model="query.invWarehouseCode" placeholder="请选择当前分库" clearable="true"
                                   size="mini">
                            <el-option
                                v-for="item in subInvList"
                                :key="item.name"
                                :label="item.name"
                                :value="item.code">
                                <span style="float: left">{{ item.name }}</span>
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <span style="color: #000; margin-left: 10px; margin-right: 6px">单据日期:</span>
                        <el-date-picker
                            :picker-options="pickerOptions"
                            v-model="actDateRange"
                            type="daterange"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="yyyy-MM-dd"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                        >
                        </el-date-picker>
                    </el-form-item>

                    <el-form-item>
                        <el-button-group>
                            <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" icon="search" @click="newDistributionForm()" :loading="loading">
                                新增订单
                            </el-button>
                        </el-button-group>
                    </el-form-item>
                </el-row>
            </el-form>
            <el-table v-loading="loading"
                      :data="list"
                      style="width: 100%;" highlight-current-row
                      @row-click="getStockOrderDetailList" ref="multipleTable">
                <el-table-column
                    type="selection"
                    width="55">
                </el-table-column>
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column label="单据号" prop="billNo" show-overflow-tooltip></el-table-column>
                <el-table-column label="往来单位" prop="corpName" show-overflow-tooltip></el-table-column>
                <el-table-column label="单据来源" prop="sourceType" width="150">
                    <template slot-scope="scope">
                        <span>{{ sourceMap[scope.row.sourceType] }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="单据日期" prop="billdate" width="150" show-overflow-tooltip>

                    <template slot-scope="scope">
                        {{ scope.row.billdate.slice(0, 10) }}
                    </template>
                </el-table-column>
                <el-table-column label="单据状态" width="150">
                    <template slot-scope="scope">
                        {{ scope.row.status | statusFilterName }}
                    </template>
                </el-table-column>
                <el-table-column label="业务类型" prop="billType" width="150">
                    <template slot-scope="scope">
                        <span>{{ getActionName(scope.row.billType) }}</span>
                    </template>
                </el-table-column>


                <el-table-column label="当前仓库" prop="locStorageCode" width="150">
                    <template slot-scope="scope">
                        <span>{{ getStorageName(scope.row.locStorageCode) }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="当前分库" prop="invWarehouseCode" width="120">
                    <template slot-scope="scope">
                        <span>{{ getSubStorageName(scope.row.invWarehouseCode) }}</span>
                    </template>
                </el-table-column>
                <!--                <el-table-column label="采购类别" width="150">-->
                <!--                    <template slot-scope="scope">-->
                <!--                        {{ scope.row.type | typeFilterName }}-->
                <!--                    </template>-->
                <!--                </el-table-column>-->
                <el-table-column label="操作" fixed="right" width="150">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            @click.native="newDistributionForm(scope.$index, scope.row)"
                            v-if="!haveNewDistributionVisible"
                        >编辑
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small"
                            @click.native="repealSubmit(scope.row)"
                            v-if="haveNewDistributionVisible"
                        >撤销提交
                        </el-button
                        >
                        <el-button
                            type="text"
                            size="small"
                            @click.native="deleteStockOrder(scope.row)"
                            v-if="!haveNewDistributionVisible"
                        >删除
                        </el-button
                        >
                    </template>
                </el-table-column>
            </el-table>

            <el-pagination
                :page-size="query.limit"
                @current-change="handleCurrentChange"
                layout="prev, pager, next"
                :total="total"
            >
            </el-pagination>
        </el-card>

        <el-card class="el-card">
            <el-table v-loading="detailLoading"
                      :data="detailList"
                      style="width: 100%">
                <el-table-column type="index" label="序号" width="50"></el-table-column>
                <el-table-column label="产品通用名" width="150" prop="productName"></el-table-column>
                <el-table-column label="规格型号" width="150" prop="spec"></el-table-column>
                <el-table-column label="批次号" width="150" prop="batchNo"></el-table-column>
                <el-table-column label="生产日期" width="150" prop="productDate"></el-table-column>
                <el-table-column label="失效日期" width="150" prop="expireDate"></el-table-column>
                <el-table-column label="单据数量" width="150" prop="count"></el-table-column>
                <!--        <el-table-column label="实际数量" width="150" prop="reCount"></el-table-column>-->
                <el-table-column label="价格" width="150" prop="price"></el-table-column>
                <el-table-column label="生产厂家" width="150" prop="ylqxzcrbarmc"></el-table-column>
                <el-table-column label="注册/备案凭证号" width="150" prop="zczbhhzbapzbh"></el-table-column>
                <el-table-column label="操作" fixed="right" width="150">
                    <template slot-scope="scope" v-if="!haveNewDistributionVisible">
                        <el-button
                            type="text"
                            size="small"
                            @click.native="handleDetailForm(scope.$index, scope.row)"
                        >编辑
                        </el-button
                        >
                    </template>
                </el-table-column>
            </el-table>

            <el-pagination
                :page-size="detailQuery.limit"
                @current-change="detailHandleCurrentChange"
                layout="prev, pager, next"
                :total="detailTotal"
            >
            </el-pagination>
        </el-card>

        <el-dialog
            title="编辑"
            :visible.sync="newDistributionVisible"
            width="80%"
            v-if="newDistributionVisible"
            @close='closeDialog'
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :before-close="handleClose"
        >
            <stockOrderNewDistribution
                :closeDialog="closeDialog"
                :idQuery="idQuery"
                :closeConfirmFunction="closeConfirmFunction"
            ></stockOrderNewDistribution>
        </el-dialog>
        <el-dialog
            title="编辑"
            :visible.sync="newSpDistributionVisible"
            width="80%"
            v-if="newSpDistributionVisible"
            @close='closeDialog'
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :before-close="handleClose"
        >
            <stockHospOrderNew
                :closeDialog="closeDialog"
                :idQuery="idQuery"
                :closeConfirmFunction="closeConfirmFunction"
            ></stockHospOrderNew>
        </el-dialog>

        <el-dialog
            title="编辑"
            :visible.sync="detailFormVisible"
            :before-close="hideDetailForm"
            width="85%"
            top="5vh"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <el-form :model="detailFormData" :rules="detailFormRules" ref="dataForm">

                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>单据号：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="billNo">
                            <el-input v-model="formData.billNo" auto-complete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>单据状态：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="status">
                            <el-input v-model="statusMap[formData.status]" auto-complete="off"
                                      :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>单据日期：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="billdate">
                            <el-input v-model="formData.billdate" auto-complete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>供应商：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="corpName">
                            <el-input v-model="formData.corpName" auto-complete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>业务类型：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="billType">
                            <el-select v-model="formData.billType" placeholder="请选择业务类型" clearable="true"
                                       disabled="true">
                                <el-option
                                    v-for="item in busTypes"
                                    :key="item.localName"
                                    :label="item.localName"
                                    :value="item.localAction">
                                    <span style="float: left">{{ item.localName }}</span>
                                    <!--<span style="float: right; color: #8492a6; font-size: 13px">{{ item.action }}</span>-->
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>采购类别：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="type">
                            <el-input v-model="typeMap[formData.type]" auto-complete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-divider></el-divider>

                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>产品通用名：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="productName">
                            <el-input v-model="detailFormData.productName" auto-complete="off"
                                      :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>规格型号：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="spec">
                            <el-input v-model="detailFormData.spec" auto-complete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>单据数量：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="count">
                            <el-input v-model="detailFormData.count" auto-complete="off" :disabled="false"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>批次号：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="batchNo">
                            <el-input v-model="detailFormData.batchNo" auto-complete="off" :disabled="false"></el-input>
                        </el-form-item>
                    </el-col>
                    <!--                    <el-col :span="3">-->
                    <!--                        <div class="ao-text">-->
                    <!--                            <span>实际数量：</span>-->
                    <!--                        </div>-->
                    <!--                    </el-col>-->
                    <!--                    <el-col :span="7">-->
                    <!--                        <el-form-item prop="reCount">-->
                    <!--                            <el-input v-model="detailFormData.reCount" auto-complete="off"-->
                    <!--                                      oninput="value=value.replace(/[^\d]/g,'')"></el-input>-->
                    <!--                        </el-form-item>-->
                    <!--                    </el-col>-->
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>生产日期：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="productDate">
                            <el-input v-model="detailFormData.productDate" auto-complete="off"
                                      oninput="if(value.length>6)value=value.slice(0,6)"
                                      type="number"
                                      :disabled="false"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>失效日期：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="expireDate">
                            <!--              <el-input v-model="detailFormData.expireDate" auto-complete="off"-->
                            <!--                        :disabled="false"></el-input>-->

                            <el-input v-model="detailFormData.expireDate" auto-complete="off"
                                      oninput="if(value.length>6)value=value.slice(0,6)"
                                      type="number"
                                      :disabled="false"></el-input>

                            <!--                            <el-date-picker-->
                            <!--                                type="date"-->
                            <!--                                size="small" v-model="detailFormData.expireDate"-->
                            <!--                                placeholder="请选择失效日期" style="width: 80%"-->
                            <!--                                value-format="yyMMdd"-->
                            <!--                                format="yyyy-MM-dd"-->
                            <!--                            >-->
                            <!--                            </el-date-picker>-->
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="3">
                        <div class="ao-text">
                            <span>价格：</span>
                        </div>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item prop="batchNo">
                            <el-input v-model="detailFormData.price" auto-complete="off" :disabled="false"></el-input>
                        </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideDetailForm">取消</el-button>
                <el-button
                    type="primary"
                    @click.native="submitUploadDetail()"
                    :loading="detailFormLoading"
                >提交
                </el-button
                >
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {
    stockOrderList, stockOrderDetail, stockOrderDetail2,
    deleteStockOrderById, deleteStockOrderDetailById,
    copyStockOrderDetail, submitStockOrder,
    uploadStockOrderDetail, uploadStockOrderDetailCount,
    generateStockOrderQRCodeText, stockOrderDetailTemp,
    deleteStockOrderDetailTempById, repealSubmitNewStockOrder
} from "../../api/warehouse/stockOrder";
import {BASE_URL} from "../../config/app";
import stockOrderNewDistribution from "./stockOrderNewDistribution";
import stockHospOrderNew from "./stockHospOrderNew";
import store from "../../store";
import draggable from "vuedraggable";
import {getLocalJoinBusType, getLocalJoinByUser} from "../../api/basic/busLocalType";
import {selectSysParamByKey} from "../../api/param/systemParamConfig";
import {filterAll, filterAllByUser} from "@/api/basic/invWarehouse";
import {filterSubByInv} from "@/api/basic/invSubWarehouse";

export default {
    name: "stockOrder",
    data() {
        return {
            query: {
                billType: null,
                corpName: null,
                locStorageCode: this.$store.getters.locInvCode,
                invWarehouseCode: this.$store.getters.locSubInvCode,
                billNo: "",
                status: "1",
                page: 1,
                limit: 20,
                startTime: "",
                endTime: "",
            },
            detailQuery: {
                orderIdFk: "",
                page: 1,
                limit: 20
            },
            list: [],
            detailList: [],
            total: 0,
            detailTotal: 0,
            loading: false,
            detailLoading: false,
            formData: {},
            storageList: [],
            subInvList: [],
            statusMap: {
                "1": "草稿",
                "2": "未配货",
                "3": "待校验",
            },
            sourceMap: {
                "1": "web端新增单据",
                "2": "第三方系统",
                "3": "扫码单据转换",
            },
            typeMap: {
                1: "预入库",
                2: "普通采购",
            },
            idQuery: {
                id: "",
            },
            newDistributionVisible: false,
            newSpDistributionVisible: false,
            isSp: store.getters.customerId,
            detailFormRules: {
                batchNo: [
                    {required: true, message: "请输入批次号", trigger: "blur"}
                ],
                productDate: [
                    {required: true, message: "请输入生产日期", trigger: "blur"}
                ],
                expireDate: [
                    {required: true, message: "请输入失效日期", trigger: "blur"}
                ],
                sweepCount: [
                    {required: true, message: "请输入扫码数量", trigger: "blur"}
                ]
            },
            busTypes: [],
            detailFormVisible: false,
            detailFormData: {},
            detailFormLoading: false,
            haveNewDistributionVisible: false,
            qrcodeExportVisible: false,
            filterUDIType: false,
            closeConfirm: false,
            detailCountMax: false,
            actDateRange: [],
            pickerOptions: {
                shortcuts: [
                    {
                        text: "最近一周",
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit("pick", [start, end]);
                        },
                    },
                    {
                        text: "最近一个月",
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit("pick", [start, end]);
                        },
                    },
                    {
                        text: "最近三个月",
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit("pick", [start, end]);
                        },
                    },
                ],
            },
        }
    },
    methods: {
        onReset() {
            this.$router.push({
                path: ""
            });
            this.query = {
                billNo: "",
                status: "1",
                startTime: "",
                endTime: "",
                page: 1,
                limit: 20
            };
            this.getList();

            this.haveNewDistributionVisible = false;
            this.actDateRange = [];
        },
        onSubmit() {
            if (this.actDateRange !== null) {
                this.query.startTime = this.actDateRange[0];
                this.query.endTime = this.actDateRange[1];
            } else {
                this.query.startTime = null;
                this.query.endTime = null;
            }
            this.getList();
            if (this.query.status === "502") {
                this.haveNewDistributionVisible = true;
            } else {
                this.haveNewDistributionVisible = false;
            }
        },
        handleCurrentChange(val) {
            this.query.page = val;
            this.getList();
        },
        detailHandleCurrentChange(val) {
            this.query.page = val;
            this.getStockOrderDetailList();
        },
        // 刷新表单
        resetForm() {
            if (this.$refs["dataForm"]) {
                // 清空验证信息表单
                this.$refs["dataForm"].clearValidate();
                // 刷新表单
                this.$refs["dataForm"].resetFields();
                this.getList();
            }
        },
        getList() {
            this.loading = true;
            this.query.corpId = store.getters.customerId;
            stockOrderList(this.query)
                .then(response => {
                    this.loading = false;
                    this.list = response.data.list || [];
                    this.total = response.data.total || 0;
                    this.detailList = [];
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },
        newDistributionForm(index, row) {
            this.idQuery.id = '';
            if (this.$isNotBlank(row) && this.$isNotBlank(row.id)) {
                this.idQuery.id = row.id;
                this.idQuery.formData = row;
            }
            if (store.getters.customerId == 110) {
                this.newSpDistributionVisible = true;
            } else
                this.newDistributionVisible = true;
        },
        closeDialog(type) {
            this.newDistributionVisible = false;
            this.newSpDistributionVisible = false;
            this.getList();
            this.detailList = [];
            // if (this.$isNotBlank(type)) {
            //     this.detailList = [];
            // }
        },
        closeConfirmFunction(type) {
            if (this.$isNotBlank(type) && type) {
                this.closeConfirm = type;
            }
        },
        handleClose(done) {
            if (this.closeConfirm) {
                this.$confirm('数据未保存，确认关闭？')
                    .then(_ => {
                        this.closeConfirm = false;
                        done();
                    })
                    .catch(_ => {
                    });
            } else {
                this.newDistributionVisible = false;
                this.newSpDistributionVisible = false;
            }
        },
        exportQRCodeText(row) {
            this.idQuery.id = '';
            if (this.$isNotBlank(row.id)) {
                this.idQuery.id = row.id;
                this.idQuery.formData = row;
                this.qrcodeExportVisible = true;
            }
        },
        closeQRCodeExportDialog() {
            this.qrcodeExportVisible = false;
            this.getList();
        },
        getStockOrderDetailList(row) {
            if (this.$isNotBlank(row)) {
                this.detailQuery.orderIdFk = row.id;
                this.formData = row;
            }
            this.detailLoading = true;
            stockOrderDetail(this.detailQuery)
                .then((response) => {
                    this.detailLoading = false;
                    this.detailList = response.data.list || [];
                })
                .catch(() => {
                    this.detailLoading = false;
                    this.detailList = [];
                });
        },
        repealSubmit(row) {
            this.$confirm("是否撤销提交？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                let tQuery = {
                    id: row.id
                }
                this.loading = true;
                repealSubmitNewStockOrder(tQuery)
                    .then((response) => {
                        this.loading = false;
                        if (response.code === 20000) {
                            this.$message.success("撤销成功");
                            this.getList();
                            this.detailList = [];
                        } else {
                            this.$message.error(response.message);
                        }
                    });
            }).catch(() => {
                this.loading = false;
            });
        },
        deleteStockOrder(row) {
            this.$confirm("此操作将永久删除该订单, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.loading = true;
                deleteStockOrderById({id: row.id})
                    .then(response => {
                        this.loading = false;
                        if (response.code === 20000) {
                            this.$message.success(response.data);
                            this.getList();
                            this.detailList = [];
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                        this.loading = false;
                    })
            }).catch(() => {

            });
        },
        copyDetail(row) {
            this.$confirm("是否复制该记录?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                let tQuery = {
                    id: row.id
                }
                this.detailLoading = true;
                copyStockOrderDetail(tQuery)
                    .then((response) => {
                        this.detailLoading = false;
                        if (response.code === 20000) {
                            this.$message.success("复制成功");
                            this.getStockOrderDetailList();
                        } else {
                            this.$message.error(response.message);
                        }
                    });
            }).catch(() => {
            });
        },
        deleteStockOrderDetailTemp(row) {
            this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.detailLoading = true;
                deleteStockOrderDetailTempById({id: row.id})
                    .then(response => {
                        this.detailLoading = false;
                        if (response.code === 20000) {
                            this.$message.success(response.data);
                            this.getStockOrderDetailList();
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                        this.detailLoading = false;
                    })
            }).catch(() => {

            });
        },
        deleteStockOrderDetail(row) {
            this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.detailLoading = true;
                deleteStockOrderDetailById({id: row.id})
                    .then(response => {
                        this.detailLoading = false;
                        if (response.code === 20000) {
                            this.$message.success(response.data);
                            this.getStockOrderDetailList();
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                        this.detailLoading = false;
                    })
            }).catch(() => {

            });
        },
        // 显示表单
        handleDetailForm(index, row) {
            this.detailFormVisible = true;
            this.detailFormData = {};
            if (row !== null) {
                this.detailFormData = Object.assign({}, row);
            }
        },
        hideDetailForm() {
            // 更改值
            this.detailFormVisible = !this.detailFormVisible;
            return true;
        },
        getActionName(action) {
            for (let i = 0; i < this.busTypes.length; i++) {
                if (this.busTypes[i].localAction === action) {
                    return this.busTypes[i].localName;
                }
            }
        },
        getStorageName(code) {
            for (let i = 0; i < this.storageList.length; i++) {
                if (this.storageList[i].code === code) {
                    return this.storageList[i].name;
                }
            }
        },
        getSubStorageName(code) {
            for (let i = 0; i < this.subInvList.length; i++) {
                if (this.subInvList[i].code === code) {
                    return this.subInvList[i].name;
                }
            }
        },
        getBusType() {
            let query = {
                enabled: true,
            };
            getLocalJoinByUser(query)
                .then((response) => {
                    this.busTypes = response.data.list || [];
                    this.filterQuery.billAction = this.busTypes[0].action;
                    // this.getList();
                })
                .catch(() => {
                });
        },
        submitUploadDetail() {
            this.$refs["dataForm"].validate(valid => {
                if (valid) {
                    this.detailLoading = true;
                    let tQuery = this.detailFormData;
                    uploadStockOrderDetail(tQuery).then((response) => {
                        this.detailLoading = false;
                        if (response.code === 20000) {
                            this.$message.success("修改完成");
                            this.hideDetailForm();
                            this.getStockOrderDetailList();
                        } else {
                            this.$alert(response.message, '提示', {
                                confirmButtonText: '确定',
                                type: 'warning',
                                closeOnClickModal: true,
                                callback: action => {
                                    this.$refs.inputRef.focus();
                                }
                            });
                        }
                    });
                }
            });
        },

        getSysParm() {
            let query = {
                paramKey: "stock_order_detail_count_max",
            };
            selectSysParamByKey(query).then((response) => {
                if (response.code == 20000) {
                    if (response.data.paramValue == "1") {
                        this.detailCountMax = true;
                    } else
                        this.detailCountMax = false;
                }
            });
        },
        getStorage() {
            this.storageList = [];
            filterAllByUser()
                .then((response) => {
                    this.storageList = response.data || [];
                    if (this.storageList.length > 0) {
                        this.invChange();
                        this.getList();
                    }
                })
                .catch(() => {
                });
        },
        invChange() {
            this.query.invWarehouseCode = "";
            this.subInvList = [];
            let query = {
                pcode: this.query.locStorageCode
            };
            filterSubByInv(query)
                .then((response) => {
                    this.subInvList = response.data || [];
                })
                .catch(() => {
                });
        },

    },
    components: {
        draggable,
        stockOrderNewDistribution, stockHospOrderNew
    },
    filters: {
        statusFilterType(status) {
            const statusMap = {
                0: "gray",
                1: "success"
            };
            return statusMap[status];
        },
        statusFilterName(status) {
            const statusMap = {
                "1": "草稿",
                "2": "未配货",
                "3": "待校验",
            };
            return statusMap[status];
        },
        typeFilterName(type) {
            const typeMap = {
                1: "预入库",
                2: "普通采购",
            };
            return typeMap[type];
        }
    },
    created() {
        this.getBusType();
        this.getStorage();
        let end = new Date();
        let start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
        this.actDateRange = [start, end];

    }
}
</script>

<style scoped>

</style>
