<template>
    <lj-win-common :title="title" bg-class="main-body-bg" :show-back="true" :header-bg="headerBg"
        :header-text-color="headerTextColor" :header-height="headerHeight" :show-footer="false" :show-header="true"
        :show-body="true" :show-footer-shadow="false" @fix-body="fixbody" pull-refresh simplefooter
        @onRefresh="refresh">
        <div slot="body" class="main-body flx-col h-full flx-1">
            <!-- <template>
                <mtrldef-item :item="mainObject"></mtrldef-item>
            </template> -->
            <!-- <template>
                <lj-grid :table-data="mxList" :columns="gridColumns" :editing="editEnabled"/>
            </template> -->
            <!-- <van-collapse v-model="activeName" accordion class="flx-1 flx-col">
                <van-collapse-item title="基础信息" name="base" :data-expanded="activeName == 'base'">基础信息</van-collapse-item>
                <van-collapse-item title="明细详情" name="mx" :data-expanded="activeName == 'mx'">明细详情</van-collapse-item>
            </van-collapse> -->

            <header class="eventmx-header">
                <van-cell class="lj-card__header card-header lj-cell-left">
                    <template #label>
                        <div class="flx">
                            <lj-tag-double class="flx-shrink" value="部门" type="primary"
                                :doubleValue="mainObject.deptid | enumFilter(deptEnum)"></lj-tag-double>
                            <div class="jc-card-label flx-1 flx-end">
                                <span class="title">编码: {{ mainObject.bednetcode }}</span>
                            </div>
                        </div>
                    </template>
                    <template #title>
                        <template v-if="mainObject.bednetname">
                            <span class="card-title">{{ mainObject.bednetname }}</span>
                        </template>
                        <template v-else>
                            <div class="jc-card-label">
                                <span class="title">（无名称）</span>
                            </div>
                        </template>
                    </template>
                </van-cell>
            </header>

            <LjStatistic :column-num="3" :data="cmpFormulaReplace" :statistic="statisticData"></LjStatistic>

            <van-tabs ref="vantabsRef" v-model="activeName" color="#2196f3" scrollspy sticky :offset-top="headerHeight"
                @scroll="autoScrollTabs" @rendered="autoRenderedTabs">
                <van-tab title="基础信息" name="base">
                    <rp-summary-item title="基础信息" simple></rp-summary-item>
                    <!-- <basic-group :value="mainObject" :group="basicGroup" :columns="columns"></basic-group> -->
                    <lj-base-form :data="mainObject" :group="basicGroup" :editable="false"
                        :columns="columns"></lj-base-form>
                </van-tab>
                <van-tab title="床网明细" name="mx">
                    <rp-summary-item title="多区袋装明细" simple
                        v-if="bednetMxData.length && Number(mainObject.bednettypeid) == 11 && Number(bednetMxData[0].if_part)">
                        <lj-grid :table-data="bednetMxSpringData" :columns="gridColumns_spring" />
                        <!-- editing -->
                    </rp-summary-item>
                    <rp-summary-item title="床网多网明细" simple>
                        <lj-grid :table-data="bednetMxData" :columns="gridColumns_mx" />
                    </rp-summary-item>
                </van-tab>
            </van-tabs>
        </div>
        <div class="detail-control" slot="footer">
            <template v-if="mainObject.flag == 1">
                <van-button class="btn" round block type="info" @click="gotoCheckmx">
                    查看详细报价
                </van-button>
                <van-button class="btn" round block @click="gotoCopyQuote">
                    复制报价
                </van-button>
                <van-button class="btn" round @click="showAction = true">
                    <i solt="icon" class="iconfont icon-more"></i>
                </van-button>
            </template>
            <template v-else>
                <van-button class="btn" round block type="info" @click="gotoEdit">
                    修改
                </van-button>
                <van-button class="btn" round block @click="gotoAudit(1)">
                    审核
                </van-button>
                <van-button class="btn" round @click="showAction = true">
                    <i solt="icon" class="iconfont icon-more"></i>
                </van-button>
            </template>

            <van-action-sheet v-model="showAction" :actions="billActions" cancel-text="取消" description="单据操作"
                close-on-click-action @select="onSelectAction" />
        </div>

    </lj-win-common>
</template>

<script>
import ljWinCommon from 'components/lj-win-common'
import mtrldefItem from './bednet-quote-mx-item';
import LjGrid from "components/lj-grid";
import LjTagDouble from "components/lj-tag-double";
import LjBaseForm from 'components/lj-base-form';
import LjStatistic from 'components/lj-statistic.vue';
import RpSummaryItem from 'components/report-widget/rp-summary-item';
import LjCheckbox from 'components/lj-checkbox.vue';

const ifsaleout_default = {
    commission: 1.05,
    other_rate: 1.05,
    taxrate: 1.07,
    moneyrate: 6.7
};

export default {
    components: {
        LjGrid,
        ljWinCommon,
        LjTagDouble,
        LjBaseForm,
        LjStatistic,
        RpSummaryItem,
        LjCheckbox
    },
    props: {},
    created() {
        var pageParm = $lj.getPageParam();
        this.mainObject = pageParm.mainObject;

        // if (this.mainObject.status == 0) {
        //     this.editEnabled = true;
        // }
        // this.setGridColumns(this.mainObject);
        this.refresh()
    },
    mounted() {
        let user = $lj.getStorage("user");
        this.username = user.username;

        var self = this;
        $lj.addEventListener("bednet_quote_mx_refresh", function () {
            self.refresh();
        });
    },
    // unmounted() {
    //     window.removeEventListener("scroll");
    // },
    data() {
        return {
            editEnabled: false,
            mainObject: {},
            bednetMxData: [],
            bednetMxSpringData: [],
            gridColumns_spring: [],
            gridColumns_mx: [],
            gridColumns: [
                // {label: "序", property: "printid", width: screen.width / 10 - 10},
                // {label: "成本对象", property: "order_mtrlname", width: screen.width / 5 - 10},
                // {label: "名称+规格", properties: ["mtrlname", "mtrlmode"], width: screen.width / 5 + 40},
                // {label: "单位", property: "unit", width: screen.width / 10},
                // {label: "待发料数", property: "planqty", width: screen.width / 5 - 10, type: "number"},
                // {label: "实发数", property: "qty", width: screen.width / 5 - 10, type: "number"},
                // {label: "配置", property: "status", width: screen.width / 5 - 10},
                // {label: "参考库存", property: "mtrlware_noallocqty", width: screen.width / 5},
                // {label: "编码", property: "mtrlcode", width: screen.width / 5},
                // {label: "总应发", property: "p_rqqty", width: screen.width / 5, type: "number"},
                // {label: "总已发", property: "factsclluqty", width: screen.width / 5, type: "number"},
                // {label: "工艺说明", property: "gydscrp", width: screen.width / 5}
            ],
            username: "",
            activeName: "base",
            headerHeight: 80,// header高度
            headerBg: "transparent",
            headerTextColor: "#fff",
            // headerOverHeight: 32,// header超出滚动高度
            deptEnum: [],
            bednettypeEnum: [],
            columns: [], // 表格列布局信息
            basicGroup: [], // 基础信息分组
            cmpFormulas: null, // 计算公式
            cmpFormulaReplace: null, // 计算公式替换
            showAction: false, // 是否显示操作按钮
            billActions: [
                { name: '查看详细报价' },
                { name: '复制报价' },
                { name: '删除', color: '#ee0a24' },
            ], // 单据操作按钮
            statisticData: [
                {
                    label: "【弹簧材料总成本】",
                    value: 0,
                    subtitle: "【弹簧总材料成本】",
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【弹簧总人工成本】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【总材料成本】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【不含税出厂价】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【总人力成本】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【部门不含税价】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【总费用成本】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【部门含税价】",
                    subtitle: "【部门售价】",
                    value: 0
                },
                {
                    label: "【总成本】",
                    value: 0,
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                },
                {
                    label: "【外币价】",
                    value: 0
                },
                {
                    label: "【总重量】",
                    value: 0
                }
            ],
            columnsExtraAttr: [
                {
                    title: "双簧？",
                    field: "if_doublespring",
                    basicinfo: {
                        render: function(h, scope, self) {
                            console.log('if_doublespring scope :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(scope));
                            let _render = [
                                h(LjCheckbox, {
                                    props: {
                                        value: scope.data.if_doublespring,
                                        label: "双簧",
                                        disabled: true
                                    },
                                    on: {
                                        input: function (val) {
                                            self.$emit("input", "if_doublespring", val);
                                        }
                                    }
                                }),
                                h(LjCheckbox, {
                                    props: {
                                        value: scope.data.if_rsorwa,
                                        label: "胶条 包角",
                                        disabled: true
                                    },
                                    on: {
                                        input: function (val) {
                                            self.$emit("input", "if_rsorwa", val);
                                        }
                                    }
                                }),
                                h(LjCheckbox, {
                                    props: {
                                        value: scope.data.if_sponge_drilling,
                                        label: "海绵打孔",
                                        disabled: true
                                    },
                                    on: {
                                        input: function (val) {
                                            self.$emit("input", "if_sponge_drilling", val);
                                        }
                                    }
                                }),
                                h(LjCheckbox, {
                                    props: {
                                        value: scope.data.iffork,
                                        label: "弹叉",
                                        disabled: true
                                    },
                                    on: {
                                        input: function (val) {
                                            self.$emit("input", "iffork", val);
                                        }
                                    }
                                }),
                                h(LjCheckbox, {
                                    props: {
                                        value: scope.data.if_jb,
                                        label: "卷包",
                                        disabled: true
                                    },
                                    on: {
                                        input: function (val) {
                                            self.$emit("input", "if_jb", val);
                                        }
                                    }
                                })
                            ];
                            return h("div", {
                                class: "lj-layout-grid-3"
                            }, _render)
                        }
                    }
                },
                {
                    title: "蛇线线径MM",
                    field: "snake_wire_diameter",
                    basicinfo: {
                        el: "input",
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.bednettypeid) > 11) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "弹叉数量",
                    field: "fork_qty",
                    basicinfo: {
                        el: "input",
                        editvisible: (scope) => {
                            console.log('fork_qty Number(scope.searchParam.iffork) :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(Number(scope.searchParam.iffork)));
                            if (Number(scope.searchParam.iffork)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "duo_qv_str",
                    basicinfo: {
                        el: "select",
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.bednettypeid) == 11) {
                                return true;
                            }
                            return false;
                        },
                    }
                },
                {
                    title: "包装",
                    field: "packtype",
                    basicinfo: {
                        el: "select",
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        },
                        render: function(h, scope, self) {
                            console.log('packtype packtype scope :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(scope));

                            let packmtrlEnum = [
                                {
                                    label: "编辑袋",
                                    value: "编辑袋"
                                },
                                {
                                    label: "牛皮纸",
                                    value: "牛皮纸"
                                },
                                {
                                    label: "胶袋",
                                    value: "胶袋"
                                },
                                {
                                    label: "牛皮纸袋",
                                    value: "牛皮纸袋"
                                }
                            ];


                            let _render = [
                                h("div", {
                                    class: ["flx"],
                                }, [
                                    h("div", {
                                        style: {
                                            color: "#E5E5EA"
                                        }
                                    }, "方式："),
                                    h("div", {
                                        class: ["flx-1"]
                                    }, scope.data[scope.column.field] == "" ? [h('div', { style: {color: '#E5E5EA'}}, scope.column.title )] : scope.data[scope.column.field]),
                                ]),
                                h("div", {
                                    class: ["flx"],
                                    on: {
                                        click: function (val) {
                                            self.$emit("toSelect", {field: "packmtrl", enum: packmtrlEnum, title: "包装材料"});
                                        }
                                    }
                                }, [
                                    h("div", {
                                        style: {
                                            color: "#E5E5EA"
                                        }
                                    }, "材料："),
                                    h("div", {
                                        class: ["flx-1"]
                                    }, scope.data.packmtrl == "" ? [h('span', { style: {color: '#E5E5EA'}}, "包装材料")] : scope.data.packmtrl),
                                ]),
                            ];
                            return h("div", {
                                class: "lj-layout-grid-2"
                            }, _render)
                        }
                    }
                },
                {
                    title: "包装数量",
                    field: "packqty",
                    basicinfo: {
                        el: "input",
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "运输方式",
                    field: "transport_type",
                    enum: [
                        {
                            label: "装车送货(装柜)",
                            value: "装车送货(装柜)"
                        },
                        {
                            label: "装车送货(送货运站)",
                            value: "装车送货(送货运站)"
                        }
                    ],
                    basicinfo: {
                        el: "select",
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "佣金点数",
                    field: "commission",
                    basicinfo: {
                        el: "input",
                        props: {
                            placeholder: ifsaleout_default.commission + ""
                        },
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "额外点数",
                    field: "other_rate",
                    basicinfo: {
                        el: "input",
                        props: {
                            placeholder: ifsaleout_default.other_rate + ""
                        },
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "FOB",
                    field: "fob",
                    basicinfo: {
                        el: "input",
                        // props: {
                        //     slots: {
                        //         suffix: () => {
                        //             return <>元</>;
                        //         },
                        //         append: () => {
                        //             return <>元</>;
                        //         }
                        //     }
                        // },
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "税率",
                    field: "taxrate",
                    basicinfo: {
                        el: "input",
                        props: {
                            placeholder: ifsaleout_default.taxrate + ""
                        },
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "额外费用",
                    field: "extras_cost",
                    basicinfo: {
                        el: "input",
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "汇率",
                    field: "moneyrate",
                    basicinfo: {
                        el: "input",
                        props: {
                            type: "number",
                            placeholder: ifsaleout_default.moneyrate + ""
                        },
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    title: "额外费用备注",
                    field: "extras_cost_dscrp",
                    basicinfo: {
                        el: "input",
                        props: { type: "textarea", rows: 2 },
                        editvisible: (scope) => {
                            if (Number(scope.searchParam.ifsaleout)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
            ],
            columnsExtraAttr_mx: [
                {
                    field: "pid",
                    width: screen.width / 10 - 10
                },
                {
                    field: "springname",
                    clearable: true,
                },
                {
                    field: "spring_qty_length",
                    type: "number",

                },
                {
                    field: "spring_qty_width",
                    type: "number",
                },
                {
                    field: "bednet_height",
                    type: "number",
                },
                {
                    field: "if_side_iron",
                    type: "checkbox",
                },
                {
                    field: "side_iron_qty",
                    type: "number",
                    cellEditingCall: (row, column, rowIndex) => {
                        return Number(row["if_side_iron"]) == 1;
                    },
                },
                {
                    field: "if_hard_around",
                    type: "checkbox",
                },
                {
                    field: "hard_around_row",
                    type: "number",
                    cellEditingCall: (row, column, rowIndex) => {
                        return Number(row["if_hard_around"]) == 1;
                    },
                },
                {
                    field: "hard_around_springname",
                    clearable: true,
                    cellEditingCall: (row, column, rowIndex) => {
                        return Number(row["if_hard_around"]) == 1;
                    },
                },
                {
                    field: "if_15strip",
                    type: "checkbox",
                },
                {
                    field: "fabrics2_mtrlid",
                    clearable: true,
                },
                {
                    field: "fabrics1_mtrlid",
                    clearable: true,
                },
                {
                    field: "if_part",
                    type: "checkbox",
                    cellEditingCall: (row, column, rowIndex) => {
                        return Number(row["if_hard_around"]) == 1;
                    },
                },
            ]
        }
    },
    methods: {
        refresh(cb) {
            let params = {
                arg_bednetid: this.mainObject.bednetid
            }
            $lj.postCommonLJRequest("web_bednet_define", params, "u_bednet_define", (res) => {
                if (res && res.datatable && res.datatable.length > 0) {
                    this.mainObject = res.datatable[0];

                    console.log("refresh >>>>", JSON.stringify(this.mainObject));
                    this.getType(res);
                }
                cb && cb();


                this.reload_dw2(this.mainObject, (data) => {
                    this.bednetMxData = data;
                }, (data) => {
                    this.bednetMxSpringData = data;
                });
            })

        },
        getType(data) {
            console.log("getType >>>>", Object.keys(data.tableinfo).includes("tableprop")
                && Object.keys(data.tableinfo.tableprop).includes("basicinfo")
                && data.tableinfo.tableprop.basicinfo.basicGroup, JSON.stringify(data));
            if (
                Object.keys(data.tableinfo).includes("tableprop")
                && Object.keys(data.tableinfo.tableprop).includes("basicinfo")
                && data.tableinfo.tableprop.basicinfo.basicGroup) {
                this.basicGroup = data.tableinfo.tableprop.basicinfo.basicGroup
            }

            this.columns = $lj.setExtraColumns(data.tableinfo.columns, this.columnsExtraAttr);

            let _deptidItem = data.tableinfo.columns.find(item => item.field == 'deptid');
            if (_deptidItem && _deptidItem.enum) {
                this.deptEnum = _deptidItem.enum;
            }

            let _bednettypeItem = data.tableinfo.columns.find(item => item.field == 'bednettypeid');
            if (_bednettypeItem && _bednettypeItem.enum) {
                this.bednettypeEnum = _bednettypeItem.enum;
            }

            if (this.mainObject.flag == 1) {
                // 已审核后操作按钮列表
                this.billActions = [
                    { name: '撤销审核' },
                    { name: '查看详细报价' },
                    { name: '复制报价' },
                    { name: '删除', color: '#ee0a24' },
                    // { name: '查看历史报价' }
                ]
            }
        },
        /**窗口高度 */
        fixbody(obj) {
            this.headerHeight = obj.marginTop;
        },
        autoRenderedTabs() {
            this.$refs.vantabsRef.resize();
        },
        // autoScrollBody() {  
        //     this.$nextTick(() => {
        //         let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        //         // let { scrollTop, isFixed } = data;
        //         if (this.$refs.vantabsRef) {
        //             // let offsetTop = this.$refs.vantabsRef.offsetTop.toString();
        //             let offsetTop = this.headerOverHeight;
        //             console.log("offsetTop init isFixed", offsetTop, scrollTop);
        //             offsetTop = Number(offsetTop.toString().replace("px", ""));
        //             if (scrollTop > offsetTop ) {
        //                 this.headerBg = '#fff';
        //                 this.headerTextColor = '#000';
        //             } else {
        //                 let _per = Math.round(scrollTop / offsetTop * 100) / 100;
        //                 if (_per > 1) {
        //                     _per = 1;
        //                 }
        //                 this.headerBg = `rgba(255,255,255,${_per})`;
        //                 this.headerTextColor = `rgba(255,255,255,1)`;
        //             }
        //         }
        //         console.log("autoScrollTabs inset???", this.headerBg);
        //     });
        // },
        autoScrollTabs(data) {
            this.$nextTick(() => {
                let { scrollTop, isFixed } = data;
                if (this.$refs.vantabsRef) {
                    let offsetTop = this.$refs.vantabsRef.offsetTop.toString();
                    // console.log("offsetTop init isFixed", offsetTop, isFixed, scrollTop);
                    offsetTop = Number(offsetTop.replace("px", ""));

                    if (scrollTop > 0) {
                        this.headerTextColor = '#000'
                    } else {
                        this.headerTextColor = `rgba(255,255,255,1)`;
                    }

                    if (isFixed && scrollTop > 0) {
                        this.headerBg = '#fff';
                    } else {
                        let _per = Math.round(scrollTop / offsetTop * 100) / 100;
                        if (_per > 1) {
                            _per = 1;
                        }
                        this.headerBg = `rgba(255,255,255,${_per})`;
                    }
                }
                // console.log("autoScrollTabs inset???", this.headerBg);
            });
        },
        reload_dw2(bednetData, cb, cbSpring) {

            this.bednetMxData = [];
            this.bednetMxSpringData = [];
            let params = {
                arg_bednetid: this.mainObject.bednetid
            }
            $lj.postCommonLJRequest("web_bednet_mx_add", params, "u_bednetmx", (res) => {
                if (res) {
                    this.bednetMxData = res.datatable;
                    let columns = $lj.setExtraColumns(res.tableinfo.columns, this.columnsExtraAttr_mx);
                    columns = this.wf_hide_dw2(bednetData, columns);
                    this.gridColumns_mx = $lj.getCommonColumns(columns);

                    cb && cb(res.datatable);
                }
            })

            $lj.postCommonLJRequest("web_bednet_mx_spring", params, "u_bednetmx_spring", (res) => {
                if (res) {
                    this.bednetMxSpringData = res.datatable;
                    let _columns = $lj.setExtraColumns(res.tableinfo.columns, this.columnsExtraAttr_mx);
                    this.gridColumns_spring = $lj.getCommonColumns(_columns);

                    cbSpring && cbSpring(res.datatable);
                }

                this.gotoSummy()
            })

            // let res = await getDataMxAdd(state.initParamsMx);
            // console.log("getDataMxAdd res :>> ", res);
            // let result = dataCallback(res);

            // columnsMx.value = wf_hide_dw2(bednetData, result.tableinfo.columns).map(item => {
            // let _default = columnsMx_default.value.find(t => t.field == item.field);
            // if (_default) {
            //     item = defaultsDeep(item, _default);
            // }
            // return item;
            // });
            // console.log("reset columnsMx.value :>> ", columnsMx.value, result);
            // // cb && cb(result);

            // let res2 = await getDataMxSpring(state.initParamsMx);
            // let result2 = dataCallback(res2);
            // // columnsMxSpring.value = result.tableinfo.columns;
            // columnsMxSpring.value = result2.tableinfo.columns.map(item => {
            // let _default = columnsMxSpring_default.value.find(t => t.field == item.field);
            // if (_default) {
            //     item = defaultsDeep(item, _default);
            // }
            // return item;
            // });

            // console.log("reload_dw2 columnsMxSpring.value :>> ", columnsMxSpring.value, result);
        },
        wf_hide_dw2(bednetData, columns) {
            let hFields = [];

            console.log('bednetData.typename != "袋装网" :>> ', bednetData.typename, bednetData.typename != "袋装网");

            // if (bednetData.typename != "袋装网") {
            if (Number(bednetData.bednettypeid) != 11) {
                hFields.push("if_part");
                // 圆网和拉丝网 没有 入袋无纺布和底面无纺布
                hFields.push("fabrics1_mtrlid");
                hFields.push("fabrics2_mtrlid");
            }

            //四周加硬
            if (Number(bednetData.if_hard_around) == 0) {
                hFields.push("if_hard_around");
                hFields.push("hard_around_wire_price");
                hFields.push("hard_around_mtrl_cost");
                hFields.push("hard_around_hr_cost");
                hFields.push("hard_around_springid");
                hFields.push("hard_around_row");
            }

            //四周口袋
            if (Number(bednetData.if_pocket_around) == 0) {
                hFields.push("pocket_around_springname");
                hFields.push("pocket_around_springid");
                hFields.push("pocket_around_row");
                hFields.push("pocket_around_wire_price");
                hFields.push("pocket_around_spring_cost");
                hFields.push("pocket_around_fabrics_cost");
                hFields.push("if_pocket_around");
            }

            // 边铁？
            if (Number(bednetData.if_side_iron) == 0) {
                hFields.push("if_side_iron");
                hFields.push("side_iron_qty");
                hFields.push("side_iron_mtrl_cost");
                hFields.push("side_iron_hr_cost");
            }

            let _columns = columns.map(t => {
                if (hFields.includes(t.field)) {
                    return {
                        ...t,
                        limited: true
                    };
                }
                return t;
            });

            return _columns.filter(t => !t.limited);
        },
        delBill() {
            $lj.postLJRequest("DeleteL1Outware", {
                token: $lj.getStorage("token"),
                scid: this.mainObject.scid,
                outwareid: this.mainObject.outwareid
            }, function (rsp) {
                if (rsp) {
                    $lj.toast("删除成功", 2000);
                    $lj.sendEvent("outware_scll_plan_refresh");
                    $lj.closeWin();
                }
            })
        },
        saveBill(saveType) {
            if (!$lj.checkPower(5227)) {
                alert("没有[发料单修改]的权限");
                return;
            }
            if (saveType === 1 && !$lj.checkPower(5228)) {
                alert("没有[发料单审核]的权限");
                return;
            }
            if (!this.mxList.length) {
                this.$toast("发料明细为空，请稍后重试");
                return;
            }
            $lj.postLJRequest("OutwareQtyEdit", {
                token: $lj.getStorage("token"),
                outware: this.mainObject,
                outwaremxList: this.mxList,
                saveType: saveType
            }, function (rsp) {
                if (rsp) {
                    $lj.toast("更新成功", 2000);
                    $lj.sendEvent("outware_scll_plan_refresh");
                    $lj.closeWin();
                }
            })
        },
        setGridColumns(data) {
            let result = [];
            this.uselocationState = $lj.ifUselocation(data);
            if (!this.uselocationState) {
                result = [
                    { label: "序", property: "printid", width: screen.width / 10 - 10 },
                    { label: "成本对象", property: "order_mtrlname", width: screen.width / 5 - 10 },
                    { label: "名称+规格", properties: ["mtrlname", "mtrlmode"], width: screen.width / 5 + 40 },
                    { label: "单位", property: "unit", width: screen.width / 10 },
                    { label: "待发料数", property: "planqty", width: screen.width / 5 - 10, type: "number" },
                    { label: "实发数", property: "qty", width: screen.width / 5 - 10, type: "number" },
                    { label: "配置", property: "status", width: screen.width / 5 - 10 },
                    { label: "参考库存", property: "mtrlware_noallocqty", width: screen.width / 5 },
                    { label: "编码", property: "mtrlcode", width: screen.width / 5 },
                    { label: "总应发", property: "p_rqqty", width: screen.width / 5, type: "number" },
                    { label: "总已发", property: "factsclluqty", width: screen.width / 5, type: "number" },
                    { label: "工艺说明", property: "gydscrp", width: screen.width / 5 },
                    { label: "主计划销售\r\n订单相关号", property: "taskrelcode", width: screen.width / 4 }
                ];
            } else {
                result = [
                    { label: "序", property: "printid", width: screen.width / 10 - 10 },
                    { label: "成本对象", property: "order_mtrlname", width: screen.width / 5 - 10 },
                    { label: "名称+规格", properties: ["mtrlname", "mtrlmode"], width: screen.width / 5 + 30 },
                    { label: "单位", property: "unit", width: screen.width / 10 },
                    { label: "待发料数", property: "planqty", width: screen.width / 5 - 10, type: "number" },
                    { label: "实发数", property: "qty", width: screen.width / 5 - 10, type: "number" },
                    { label: "仓位", property: "location" },
                    { label: "配置", property: "status", width: screen.width / 5 - 10 },
                    { label: "参考库存", property: "mtrlware_noallocqty", width: screen.width / 5 },
                    { label: "编码", property: "mtrlcode", width: screen.width / 5 },
                    { label: "总应发", property: "p_rqqty", width: screen.width / 5, type: "number" },
                    { label: "总已发", property: "factsclluqty", width: screen.width / 5, type: "number" },
                    { label: "工艺说明", property: "gydscrp", width: screen.width / 5 },
                    { label: "主计划销售\r\n订单相关号", property: "taskrelcode", width: screen.width / 4 }
                ];
            }
            this.gridColumns = result;
        },
        onSelectAction(item) {
            console.log('item :>> ', JSON.stringify(item));
            if (item.name == "审核") {
                this.gotoAudit(1);
            } else if (item.name == "撤销审核") {
                this.gotoAudit(0);
            } else if (item.name == "查看详细报价") {
                this.gotoCheckmx();
            } else if (item.name == "复制报价") {
                this.gotoCopyQuote();
            } else if (item.name == "删除") {
                if (!$lj.checkPower(76)) {
                    alert("你没有【报价单-删除】的使用权限");
                    return;
                }

                $lj.confirm("提示", "是否删除本单据", function () {
                    $lj.postLJRequest("DeleteBedNet", {
                        token: $lj.getStorage("token"),
                        list: [this.mainObject],
                    }, function (rsp) {
                        if (rsp) {
                            $lj.toast("删除成功", 2000);
                            $lj.sendEvent("bednet_quote_refresh");

                            $lj.closeWin();
                        }
                    })
                });
            }

            this.showAction = false;
        },
        gotoEdit(winType = 1) {
            if (!$lj.checkPower(72)) {
                alert("你没有【报价单-修改】的使用权限");
                return;
            }
            $lj.openWin("bednet-quote-new", {
                mainObject: this.mainObject,
                winType: winType
            });
        },
        gotoAudit(type) {
            let self = this;
            let title;
            if (type) {
                if (!$lj.checkPower(63)) {
                    alert("你没有【报价单-审核】的使用权限");
                    return;
                }
                title = "审核";
            } else {
                if (!$lj.checkPower(64)) {
                    alert("你没有【报价单-撤销审核】的使用权限");
                    return;
                }
                title = "撤销审核";
            }

            $lj.postLJRequest("AuditBedNet", {
                token: $lj.getStorage("token"),
                list: [this.mainObject],
                type: type
            }, function (rsp) {
                if (rsp) {
                    $lj.toast(title + "成功", 2000);
                    // $lj.sendEvent("bednet_quote_refresh");

                    self.refresh();
                }
            })
        },
        gotoCopyQuote() {
            this.gotoEdit(2);
        },
        gotoCheckmx() {
        },
        /**
         * @description 展示计算公式
         * @param timeout
         */
        gotoSummy() {
            // if (userInfo.usermode == 1) {
            //   ElMessage.error("'业务员模式不可以查看计算公式！'");
            //   return false;
            // }
            // console.log(
            //     "state.vxeTableMxRef?.element.getTableData().fullData :>> ",
            //     state.vxeTableMxRef?.element.getTableData().fullData,
            //     state.vxeTableMxRef
            // );
            let _bednet = this.mainObject;
            _bednet.if_doublenet = Number(_bednet.if_doublenet);
            _bednet.if_doublespring = Number(_bednet.if_doublespring);
            _bednet.if_side_iron = Number(_bednet.if_side_iron);
            _bednet.if_rsorwa = Number(_bednet.if_rsorwa);
            _bednet.if_sponge_drilling = Number(_bednet.if_sponge_drilling);
            _bednet.iffork = Number(_bednet.iffork);
            _bednet.ifsaleout = Number(_bednet.ifsaleout);
            _bednet.if_jb = Number(_bednet.if_jb);
            _bednet.flag = Number(_bednet.flag);

            let _params = {
                token: $lj.getStorage("token"),
                bednet: _bednet,
                bednetMx: this.bednetMxData,
                spring: this.bednetMxSpringData
            };
            
            $lj.postLJRequest("GetComputeBednet", _params, (res) => {
                if (res) {
                    console.log("GetComputeBednet res :>> ", JSON.stringify(res));
                    // let summaryData = [];
                    // let fieldParams = [];
                    // let cpData = {};
                    if (!res.message) {
                        // summaryData = res.formulas;
                        // fieldParams = res.replace;
                        // cpData = res.bednet;
                        this.cmpFormulas = res.formulas;
                        this.cmpFormulaReplace = res.replace;
                    } else {
                        setTimeout(() => {
                            if (res.message) {
                                // ElNotification({
                                //     title: "计算失败",
                                //     message: res.message,
                                //     type: "warning"
                                // });
                                this.$toast.fail("计算失败");
                            }
                        }, 100);
                        return false;
                    }
                    console.log("summaryData :>> ", JSON.stringify(this.cmpFormulas),  JSON.stringify(this.cmpFormulaReplace));
                }
            })
        }
    },
    computed: {
        title() {
            if (this.editEnabled) {
                return "床网报价确认";
            } else {
                return "床网报价详情";
            }
        },
        isoutRep() {
            return this.mainObject.outrep == this.username;
        },
        isrestr3() {
            return this.mainObject.relstr_3 == this.username;
        }
    },
    filters: {
        enumFilter(data, arr) {
            let name = "";
            arr.forEach(itm => {
                if (Number(itm.value) == Number(data)) {
                    name = itm.label;
                }
            });
            return name
        }
    }
}
</script>
<style lang="less">
.eventmx-header {
    position: relative;
    margin: 8px 12px;
    background: #fff;
    border-radius: 8px;

    .card-header {
        // padding: 15px 20px;
        overflow: unset;

        .van-cell__title {
            font-size: 24px;
            // color: #fff;

            .card-title {
                font-weight: bold;
            }
        }

        .van-cell__value {
            display: flex;
            justify-content: flex-end;
            overflow: unset;
        }

        &.van-cell::after {
            content: none;
        }

        .jc-card-label {
            .title {
                color: @light-label-secondary;
            }
        }
    }
}

.main-body {
    .van-tabs {
        .van-sticky {
            &:not(.van-sticky--fixed) {

                .van-tabs__wrap {
                    margin: 0 12px;
                    border-radius: 8px;
                }
            }
        }
    }
}
</style>
