<template>
    <div>
        <el-row :gutter="20" class="el-row" type="flex">
            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>扫码单据类型:&nbsp;</span>
                    </div>
                    <el-input
                        style="width: 200px"
                        size="small"
                        splaceholder="请输入内容"
                        v-model="inputQuery.name"
                    ></el-input>
                </div>
            </el-col>
            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>单据类型代码:&nbsp;</span>
                    </div>
                    <el-input
                        style="width: 200px"
                        :disabled="true"
                        size="small"
                        splaceholder="请输入内容"
                        v-model="inputQuery.action"
                    ></el-input>
                </div>
            </el-col>
        </el-row>

        <el-row :gutter="20" class="el-row" type="flex">
            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>出入库类型:&nbsp;</span>
                    </div>
                    <el-select v-model="inputQuery.mainAction" placeholder="出入库类型" @change="getOrderType">
                        <el-option label="入库" value="WareHouseIn"></el-option>
                        <el-option label="出库" value="WareHouseOut"></el-option>
                    </el-select>

                </div>
            </el-col>
            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>关联业务单据:&nbsp;</span>
                    </div>
                    <el-select v-model="inputQuery.localAction" placeholder="请选择" clearable>
                        <el-option
                            v-for="item in localTypes"
                            :key="item.localAction"
                            :label="item.localName"
                            :value="item.localAction">
                            <span style="float: left">{{ item.localName }}</span>
                        </el-option>
                    </el-select>
                </div>
            </el-col>
        </el-row>
        <el-row :gutter="20" class="el-row" type="flex">


            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>往来信息类型:&nbsp;</span>
                    </div>
                    <el-select v-model="inputQuery.corpType" placeholder="往来信息" @change="corpTypeChange">

                        <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>

                    </el-select>

                </div>
            </el-col>
            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>内部进出平衡补单:&nbsp;</span>
                    </div>
                    <el-select :disabled="inputQuery.corpType !=1"
                               v-model="inputQuery.supplementOrderType"
                               clearable
                               placeholder="单据类型">
                        <el-option
                            v-for="item in orderTypeList"
                            :key="item.name"
                            :label="item.name"
                            :value="item.action">
                            <span style="float: left">{{ item.name }}</span>
                        </el-option>
                    </el-select>
                </div>
            </el-col>


            <!--            <el-col :span="10" class="el-col">-->
            <!--                <div class="text item">-->
            <!--                    <div class="itemTag">-->
            <!--                        <span>当前仓库:&nbsp;</span>-->
            <!--                    </div>-->
            <!--                    <el-select clearable v-model="inputQuery.storageCode" placeholder="当前仓库信息">-->
            <!--                        <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>-->
            <!--                </div>-->
            <!--            </el-col>-->
        </el-row>
        <el-row :gutter="20" class="el-row" type="flex">

            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>特殊单据往来:&nbsp;</span>
                    </div>
                    <el-select
                        v-model="inputQuery.defaultUnit"
                        filterable
                        remote
                        :disabled="inputQuery.corpType!=3"
                        clearable="true"
                        reserve-keyword
                        :remote-method="findSpecialMethod"
                    >
                        <el-option
                            v-for="item in fromSpecialOptions"
                            :key="item.name"
                            :label="item.name"
                            :value="item.erpId"
                        >
                            <span style="float: left">{{ item.name }}</span>
                        </el-option>
                    </el-select>


                </div>
            </el-col>

            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>单据前缀:&nbsp;</span>
                    </div>
                    <el-input
                        style="width: 200px"
                        size="small"
                        splaceholder="请输入内容"
                        v-model="inputQuery.prefix"
                    ></el-input>
                </div>
            </el-col>


        </el-row>


        <el-row :gutter="20" class="el-row" type="flex">


<!--            <el-col :span="10" class="el-col">-->
<!--                <div class="text item">-->
<!--                    <div class="itemTag">-->
<!--                        <span>补单默认仓库:&nbsp;</span>-->
<!--                    </div>-->
<!--                    <el-select v-model="inputQuery.defaultInv" placeholder="默认仓库" clearable="true"-->
<!--                               @change="invChange"-->
<!--                               style="width: 30%"-->
<!--                               size="small">-->
<!--                        <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-select v-model="inputQuery.defaultSubInv" placeholder="默认分库" clearable="true"-->
<!--                               style="width: 30%"-->
<!--                               size="small">-->
<!--                        <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>-->
<!--                </div>-->
<!--            </el-col>-->

            <el-col :span="10" class="el-col">
                <div class="text item">
                    <div class="itemTag">
                        <span>备注:&nbsp;</span>
                    </div>
                    <el-input
                        style="width: 60%"
                        size="small"
                        splaceholder="请输入内容"
                        v-model="inputQuery.remark"
                    ></el-input>
                </div>
            </el-col>


        </el-row>
        <el-row :gutter="20" class="el-row" type="flex">
            <el-col :span="24" class="el-col">


                <div class="text item" style="margin-top: 6px">
                    <el-checkbox v-model="inputQuery.enable" :disabled="inputQuery.localAction==null">启用单据类型</el-checkbox>
                    <el-checkbox v-model="inputQuery.genUnit" :disabled="inputQuery.corpType !=2">允许手动输入客户信息
                    </el-checkbox>
                    <el-checkbox v-model="inputQuery.useDyCount" :disabled="inputQuery.corpType !=2">允许科室多次使用出库
                    </el-checkbox>
                    <el-checkbox v-model="inputQuery.outTospms">手持终端提交单据至自助平台
                    </el-checkbox>
                    <el-checkbox v-model="inputQuery.entrutSpms">允许验收自助平台单据
                    </el-checkbox>
                </div>
            </el-col>
        </el-row>
        <el-row :gutter="20" class="el-row" type="flex">
            <el-col :span="24" class="el-col">
                <span style="margin-left: 15px">单据详情展示方式:</span>
                <el-select v-model="inputQuery.orderVisibleType" style="margin-left: 5px"
                           placeholder="单据详情展示方式"
                           size="mini">
                    <el-option label="批次号" :value=0></el-option>
                    <el-option label="条码清单" :value=1></el-option>
                </el-select>
            </el-col>
        </el-row>

        <el-divider></el-divider>
        <span>单据默认选项：</span>
        <el-row :gutter="20" class="el-row" type="flex">
            <el-col :span="24" class="el-col">
                <div class="text item" style="margin-top: 12px">
                    <el-checkbox v-model="inputQuery.ullageFill" :disabled="!inputQuery.changeEnable">单据默认自动补单
                    </el-checkbox>
                    <el-checkbox v-model="inputQuery.scanPreIn" :disabled="inputQuery.corpType!='2'">出库时必须校验预验收库存
                    </el-checkbox>
                    <el-checkbox v-model="inputQuery.vailInv" :disabled="inputQuery.mainAction!='WareHouseOut'">是否只允许有库存产品出库
                    </el-checkbox>
                    <el-checkbox v-model="inputQuery.codeFillCheck">采集UDI码时进行三期校验
                    </el-checkbox>
                </div>
            </el-col>
        </el-row>


        <!--                <el-divider></el-divider>-->
        <!--        <el-row :gutter="20" class="el-row" type="flex">-->
        <!--            <el-col :span="4" class="el-col">-->
        <!--                <div class="text item">-->
        <!--                    <el-checkbox v-model="inputQuery.enable">启用单据类型</el-checkbox>-->
        <!--                </div>-->
        <!--            </el-col>-->


        <!--            <el-col :span="4" class="el-col">-->
        <!--                <div class="text item">-->
        <!--                    <el-checkbox v-model="inputQuery.innerOrder">标记为内部单据</el-checkbox>-->
        <!--                </div>-->
        <!--            </el-col>-->
        <!--            <el-col :span="4" class="el-col">-->
        <!--                <div class="text item">-->
        <!--                    <el-checkbox v-model="inputQuery.genUnit">允许手动输入信息</el-checkbox>-->
        <!--                </div>-->
        <!--            </el-col>-->
        <!--        </el-row>-->
        <el-divider></el-divider>
        <el-row :gutter="20" class="el-row" type="flex">
            <!--            <el-col :span="5" class="el-col">-->
            <!--                <span>选择业务单据校验的来源类型</span>-->
            <!--&lt;!&ndash;                <div class="text item">&ndash;&gt;-->
            <!--&lt;!&ndash;                    <el-checkbox v-model="inputQuery.checkEnable">必须选择业务单据校验来源</el-checkbox>&ndash;&gt;-->
            <!--&lt;!&ndash;                </div>&ndash;&gt;-->
            <!--            </el-col>-->
            <!--            @change="oneCheck"-->
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkEnable">需要选择业务单据校验的来源类型(一次复核)</el-checkbox>
                </div>
            </el-col>
        </el-row>
        <el-row :gutter="20" class="el-row" type="flex" style="margin-left: 15px">
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkWebNew" :disabled="!inputQuery.checkEnable">web端新增单据
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkPdaUn" :disabled="!inputQuery.checkEnable">手持终端未校验单据
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkPdaEd" :disabled="!inputQuery.checkEnable">手持终端已校验单据
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkUdims" :disabled="!inputQuery.checkEnable">UDIMS平台
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkPc" :disabled="!inputQuery.checkEnable">UDI扫码通</el-checkbox>
                </div>
            </el-col>

        </el-row>
        <el-row :gutter="20" class="el-row" type="flex" style="margin-left: 15px">
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkSp" :disabled="!inputQuery.checkEnable">自助平台同步</el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkChange" :disabled="!inputQuery.checkEnable">自动补单
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkBalacne" :disabled="!inputQuery.checkEnable">平衡补单
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.checkCopy" :disabled="!inputQuery.checkEnable">手动补单
                    </el-checkbox>
                </div>
            </el-col>
        </el-row>

        <el-divider></el-divider>
        <el-row :gutter="20" class="el-row" type="flex">
            <!--            <el-col :span="5" class="el-col">-->
            <!--                <span>单据需要复核的来源类型</span>-->
            <!--                &lt;!&ndash;                <div class="text item">&ndash;&gt;-->
            <!--                &lt;!&ndash;                    <el-checkbox v-model="inputQuery.checkEnable">必须选择业务单据校验来源</el-checkbox>&ndash;&gt;-->
            <!--                &lt;!&ndash;                </div>&ndash;&gt;-->
            <!--            </el-col>-->
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckEnable"
                                 :disabled="twoCheck">需要单据复核的来源类型(二次复核)
                    </el-checkbox>
                </div>
            </el-col>

        </el-row>
        <el-row :gutter="20" class="el-row" type="flex" style="margin-left: 15px">
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckWebNew" :disabled="!inputQuery.secCheckEnable">web端新增单据
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckPdaUn" :disabled="!inputQuery.secCheckEnable">手持终端未校验单据
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckPdaEd" :disabled="!inputQuery.secCheckEnable">手持终端已校验单据
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckUdims" :disabled="!inputQuery.secCheckEnable">UDIMS平台
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckPc" :disabled="!inputQuery.secCheckEnable">UDI扫码通
                    </el-checkbox>
                </div>
            </el-col>

        </el-row>
        <el-row :gutter="20" class="el-row" type="flex" style="margin-left: 15px">
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckSp" :disabled="!inputQuery.secCheckEnable">自助平台同步
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckChange" :disabled="!inputQuery.secCheckEnable">自动补单
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckBalacne" :disabled="!inputQuery.secCheckEnable">平衡补单
                    </el-checkbox>
                </div>
            </el-col>
            <el-col :span="4" class="el-col">
                <div class="text item">
                    <el-checkbox v-model="inputQuery.secCheckCopy" :disabled="!inputQuery.secCheckEnable">手动补单
                    </el-checkbox>
                </div>
            </el-col>
        </el-row>
        <el-divider></el-divider>

    </div>
</template>

<script>

import {
    getBasicThirdSys,
} from "../../api/basic/basicThirdSys";
import {getOriginBusType} from "../../api/basic/busOriginType";
import {
    getLocalJoinNoUse
} from "../../api/basic/busLocalType";
import {filterAll, filterAllByUser} from "@/api/basic/invWarehouse";
import {getCandidateBussinessType} from "../../api/basic/bussinessType";
import {getBasicUnitMaintains} from "@/api/basic/basicUnitMaintain";
import {filterSubByInv} from "@/api/basic/invSubWarehouse";

export default {
    name: "BussinessTypeModify",
    props: {
        inputQuery: {
            type: Object,
            required: true,
        },
    },

    data() {
        return {
            filterQuery: {
                enabled: true,
                isBuType: true,
                isFilterBind: true,
            },
            storageList: [],
            subInvList: [],
            orderTypeList: [],
            fromSpecialOptions: [],
            thirdSys: [],
            localTypes: [],
            originTypes: [],
            value: "",
            options: [{
                value: '0',
                label: '供应商信息'
            }, {
                value: '1',
                label: '仓库信息'
            },
                {
                    value: '2',
                    label: '客户信息'
                }, {
                    value: '3',
                    label: '特殊往来'
                }],
            twoCheck: false,

        }
    },
    methods: {
        getList() {
            let originQuery = {
                onlyMain: true,
            };
            getOriginBusType(originQuery)
                .then((response) => {
                    this.originTypes = response.data.list || [];
                })
                .catch(() => {
                });
            getBasicThirdSys(this.filterQuery)
                .then((response) => {
                    this.thirdSys = response.data.list || [];
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                });
            let query = {
                curAction: this.inputQuery.localAction,
            };
            getLocalJoinNoUse(query)
                .then((response) => {
                    this.localTypes = response.data.list || [];
                })
                .catch(() => {
                    this.loading = false;
                    this.localTypes = [];
                });
        },
        getStorage() {
            this.storageList = [];
            filterAll()
                .then((response) => {
                    this.storageList = response.data || [];
                    this.findDefaultSubInv();
                })
                .catch(() => {
                });
        },
        invChange() {
            if (this.$isNotBlank(this.inputQuery.defaultSubInv))
                this.inputQuery.defaultSubInv = null;
            this.findDefaultSubInv();
        },
        findDefaultSubInv() {
            this.subInvList = [];
            let query = {
                pcode: this.inputQuery.defaultInv
            };
            filterSubByInv(query)
                .then((response) => {
                    this.subInvList = response.data || [];
                })
                .catch(() => {
                });
        },
        findSpecialMethod() {
            let query = {
                corpType: 4,
            };
            getBasicUnitMaintains(query).then((response) => {
                this.fromSpecialOptions = response.data.page.list || [];
            }).catch(() => {

            })
        },
        oneCheck(type) {
            console.log(type);
            if (!type) {
                this.twoCheck = true;
                this.inputQuery.secCheckEnable = false;
            } else
                this.twoCheck = false;
        },
        corpTypeChange(type) {
            if (type != 2) {
                this.inputQuery.genUnit = false;
            }
        }
        ,
        //获取单据类型
        getOrderType() {

            this.orderTypeList = [];
            let query = {
                mainAction: this.inputQuery.mainAction,
                curAction: this.inputQuery.supplementOrderType,
            };
            getCandidateBussinessType(query).then((response) => {
                this.orderTypeList = response.data || [];
            }).catch(() => {

            })
        },
    },
    computed: {
        corpType() {
            return this.inputQuery.corpType;
        }
    },
    watch: {
        corpType: function (val) {
            if (val != 1) {
                this.inputQuery.orderTypeEnable = true;
                this.inputQuery.supplementOrderType = null;
            } else {
                this.inputQuery.orderTypeEnable = false;
            }
        }
    },

    created() {
        if (this.inputQuery.mainAction != null && this.inputQuery.mainAction != "") {
            this.getOrderType();
        }
        this.getList();
        this.getStorage();
        this.findSpecialMethod();

    },
};
</script>

<style scoped>
.itemTag {
    float: left;
    text-align: left;
    margin-top: 10px;
    width: 100px;
}

.text {
    font-size: 13px;
    font-family: "Microsoft YaHei";
}

.el-row {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.el-col {
    border-radius: 4px;
    flex-wrap: wrap;
}
</style>
