<template>
    <div style="background: #fff; overflow-x: hidden; overflow-y: auto">
        <!-- 列表覆写开始 -->
        <BillListPanelV3
            ref="billqureygrid"
            v-show="!showHead"
            :config="myConfig.billQueryConfig"
            :dictData="dictData"
            :moduleMethod="moduleMethod"
            @doAction="doAction"
        />
        <!-- 列表覆写结束 -->

        <BillDetailForm
            ref="form"
            v-show="showHead"
            :config="myConfig.detailConfig"
            :dictData="dictData"
            :moduleMethod="moduleMethod"
            @handleSuccessAfter="handleSuccessAfter"
            @doAction="doAction"
        >
            <template #toolbar>
                <Card
                    v-show="showToolbar"
                    :padding="0"
                    style="padding: 14px 16px; border-radius: 0px"
                    dis-hover
                    :bordered="false"
                >
                    <DetailBtnToolbar
                        ref="menutoolbar"
                        :config="menuToolbar"
                        :moduleMethod="moduleMethod"
                        @doAction="doAction"
                    />
                    <Divider style="margin-top: 16px; margin-bottom: 0px" />
                </Card>
            </template>
        </BillDetailForm>
        <ApprovalBox ref="approval" :config="billApprovalConfig" @onSubmitBefore="onSubmitBefore" />
        <Modal
            class-name="efuture-billapprovalmainframe"
            v-model="showApproval"
            fullscreen
            title="报批单"
            footer-hide
        >
            <iframe
                frameborder="0"
                ref="billapprovalmainframe"
                style="width: 100%; height: 100%"
                border="0"
            ></iframe>
        </Modal>
        <Modal
            title="单据日志"
            v-model="showBilloperlog"
            :width="logcurrentWidth"
            :footer-hide="true"
        >
            <BillOperLog ref="billoperlog" :config="billOperLogConfig" />
        </Modal>
    </div>
</template>

<script>
import listdetails from "../listdetails.vue";
import BillListPanelV3 from "./BillListPanelV3.vue";

/**
 * listdetails V2版本
 * 解决列表查询条件暂存问题
 * 列表快捷查询、高级查询，查询条件持久化，详情返回刷新问题
 */
export default {
    name: "mListDetailsV3",
    extends: listdetails,
    components: { BillListPanelV3 },
    data() {
        return {};
    },
    computed: {},
    methods: {
        doAction(obj) {
            if (obj.name === "gridSelectionChange") {
                if (this.$parent[obj.name]) {
                    this.$parent[obj.name](obj);
                }
                return true;
            }
            const method = obj.name;
            const methodBefore = method + "Before";
            const methodAfter = method + "After";
            if (
                obj.name === "skipData" ||
                obj.name === "gridDbClick" ||
                obj.name === "backData" ||
                obj.name === "searchData" ||
                obj.name === "editData" ||
                obj.name === "addData" ||
                obj.name === "preBill" ||
                obj.name === "nextBill" ||
                obj.name === "resetData" ||
                obj.name === "openWorkFlow" ||
                obj.name === "openBillapproval" ||
                obj.name === "openBilloperlog"
            ) {
                let flag = true;
                if (this.$parent[methodBefore]) {
                    flag = this.$parent[methodBefore](obj);
                }
                if (flag) {
                    // '跳转'
                    if (obj.name === "skipData" || obj.name === "gridDbClick") {
                        this.initForm(obj.para, obj.name);
                    }
                    // '跳转'
                    if (obj.name === "openWorkFlow") {
                        this.openWorkFlow();
                    }
                    // '跳转'
                    if (obj.name === "openBillapproval") {
                        this.openBillapproval();
                    }
                    // '打开日志'
                    if (obj.name === "openBilloperlog") {
                        if (this.$parent.openBilloperlog) {
                            this.$parent.openBilloperlog();
                        } else {
                            this.openBilloperlog();
                        }
                    }

                    // '打印初期化'
                    if (obj.name === "initPrintConfig") {
                        this.initPrintConfig();
                    }
                    // 返回
                    if (obj.name === "backData") {
                        let temp = {};
                        let self = this;
                        temp.onOk = () => {
                            // =================================
                            // 重写点
                            self.$refs.billqureygrid.refurbish(
                                null,
                                "backData"
                            );
                            // =================================
                            self.$nextTick(() => {
                                self.showHead = false;
                            });
                        };
                        this.checkData(temp);
                    }
                    // 查询
                    if (obj.name === "searchData") {
                        this.$refs.billqureygrid.getQuick().filterSearch();
                        /*this.setPhkey('');
                        this.ph_key = '';
                        this.$refs.billqureygrid.refurbish();
                        */
                    }
                    // 重置
                    if (obj.name === "resetData") {
                        this.$refs.billqureygrid.getQuick().clearData();
                    }

                    // 编辑
                    if (obj.name === "editData") {
                        this.$refs.form.setReadOnly(false);
                        this.getMenuToolbar().setAllReadOnly(true);
                        this.getMenuToolbar().setReadOnly([
                            "delData",
                            "saveData",
                        ]);
                        this.showHead = true;
                    }
                    // 新增
                    if (obj.name === "addData") {
                        if (this.showHead) {
                            let temp = {};
                            let self = this;
                            temp.onOk = () => {
                                self.$refs.form.setReadOnly(false);
                                self.$refs.form.clearData();
                                self.customPrintData = null;
                                self.getMenuToolbar().setAllReadOnly(true);
                                self.getMenuToolbar().setReadOnly(
                                    "saveData",
                                    false
                                );
                                self.showHead = true;
                                self.logData = null;
                                if (self.$parent[methodAfter]) {
                                    self.$parent[methodAfter]();
                                }
                            };
                            this.checkData(temp);
                            return true;
                        } else {
                            this.$refs.form.setReadOnly(false);
                            this.$refs.form.clearData();
                            this.getMenuToolbar().setAllReadOnly(true);
                            this.getMenuToolbar().setReadOnly(
                                "saveData",
                                false
                            );
                            this.showHead = true;
                            this.logData = null;
                        }
                    }
                    // 上一单
                    if (obj.name === "preBill") {
                        this.preBill();
                    }
                    // 下一单
                    if (obj.name === "nextBill") {
                        this.nextBill();
                    }

                    if (this.$parent[methodAfter]) {
                        this.$parent[methodAfter]();
                    }
                }
            } else {
                let data = this.$refs.form.getData();
                if (obj.name === "saveData") {
                    let flag = this.$refs.form.checkValidate();
                    if (flag) {
                        this.alert("必填项不允许为空");
                        return false;
                    }
                    flag = this.$refs.form.isEdit();
                    if (flag) {
                        this.alert("存在数据未确认");
                        return false;
                    }
                    obj.para = this.$refs.form.getChangeData();
                }
                if (obj.name === "saveDetails") {
                    obj.para = this.$refs.form.getChangeData(obj.detailsname);
                    obj.name = "saveData";
                }
                if (obj.name === "delData") {
                    if (this.showHead) {
                        obj.para = data;
                        obj.para.flag = "D";
                    } else {
                        if (obj.para instanceof Array) {
                            obj.para.forEach((el) => {
                                el.flag = "D";
                            });
                        } else {
                            obj.para.flag = "D";
                            let temp = [obj.para];
                            obj.para = temp;
                        }
                    }
                }
                if (obj.name === "copyData") {
                    if (!obj.para) {
                        obj.para = {};
                    }
                    obj.para[this.billKey] = data[this.billKey];
                }
                obj.onOk = this.onOk;
                let flag = true;
                if (this.$parent[methodBefore]) {
                    flag = this.$parent[methodBefore](obj);
                }
                if (!flag) {
                    return;
                }
                if (
                    obj.name === "delData" ||
                    obj.name === "auditData" ||
                    obj.name === "cancelData" ||
                    obj.name === "revokeData"
                ) {
                    let text = "删除";
                    if (obj.name === "auditData") {
                        text = "审核";
                        obj.para = { billno: data.billno };
                    }
                    if (obj.name === "cancelData") {
                        text = "作废";
                        obj.para = { billno: data.billno };
                    }

                    if (obj.name === "revokeData") {
                        text = "撤回";
                        obj.para = { billno: data.billno };
                    }
                    if (this.$parent.getActionName) {
                        let name = this.$parent.getActionName(obj);
                        if (name) {
                            text = name;
                        }
                    }
                    let info = "确定是否" + text + "数据？";
                    let self = this;
                    self.$Modal.confirm({
                        title: "确认",
                        content: info,
                        onOk: () => {
                            self.$emit("doAction", obj);
                        },
                    });
                } else {
                    this.$emit("doAction", obj);
                }
            }
        },
        handleSuccessAfter(response, file, fileList) {
            this.$emit('handleSuccessAfter' , response, file, fileList);
        },
        onSubmitBefore() {
            let flag = true;
            if (this.$parent && typeof this.$parent.onSubmitBefore === 'function') {
                flag = this.$parent.onSubmitBefore();
            }
            return flag;
        },
    },
    mounted() {},
};
</script>

<style lang="scss" scoped></style>
