<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.mattresscode }}</span>
                            </div>
                        </div>
                    </template>
                    <template #title>
                        <template v-if="mainObject.mattressname">
                            <span class="card-title">{{ mainObject.mattressname }}</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>
                    <lj-base-form :data="mainObject" :group="basicGroup" :editable="editEnabled"
                        :columns="columns"></lj-base-form>
                </van-tab>
                <van-tab title="面料" name="fabricMx" class="overflow-hidden">
                    <template #title>
                        <template v-if="isTabsBadge_fabric_error">
                            <van-badge :content="isTabsBadge_fabric_error + '异常'" class="tabs-badge">
                                面料
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isTabsBadge_fabric" class="tabs-badge" color="#2196f3"
                                :show-zero="false">
                                面料
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="面料明细" simple>
                        <van-tabs ref="tabsFabricMxRef" class="mattress-tabs__fabric" v-model="fabricMxTabs"
                            color="#5AC8FA" sticky :offset-top="fabricHeaderHeight">
                            <van-tab name="tabpage_8" v-if="Number(mattresstypeEnum.if_top_side) == 1">
                                <template #title>
                                    <template v-if="isFilterErrorBadge(fabricMxTab8)">
                                        裥面
                                        <van-badge :content="isFilterErrorBadge(fabricMxTab8) + '异常'"
                                            class="tabs-badge">
                                        </van-badge>
                                    </template>
                                    <template v-else>
                                        裥面
                                        <van-badge :content="isFilterSucessBadge(fabricMxTab8)" class="tabs-badge"
                                            color="#5AC8FA" :show-zero="false">
                                        </van-badge>
                                    </template>
                                </template>
                                <lj-grid :table-data="fabricMxTab8" :columns="gridColumns_mx" />
                            </van-tab>
                            <van-tab title="裥底" name="tabpage_9" v-if="Number(mattresstypeEnum.if_button_sdie) == 1">
                                <template #title>
                                    <template v-if="isFilterErrorBadge(fabricMxTab8)">
                                        裥底
                                        <van-badge :content="isFilterErrorBadge(fabricMxTab8) + '异常'"
                                            class="tabs-badge">
                                        </van-badge>
                                    </template>
                                    <template v-else>
                                        裥底
                                        <van-badge :content="isFilterSucessBadge(fabricMxTab8)" class="tabs-badge"
                                            color="#5AC8FA" :show-zero="false">
                                        </van-badge>
                                    </template>
                                </template>
                                <lj-grid :table-data="fabricMxTab9" :columns="gridColumns_mx" />
                            </van-tab>
                            <van-tab title="裥大恻" name="tabpage_10" v-if="Number(mattresstypeEnum.if_big_side) == 1">
                                <template #title>
                                    <template v-if="isFilterErrorBadge(fabricMxTab9)">
                                        裥大恻
                                        <van-badge :content="isFilterErrorBadge(fabricMxTab9) + '异常'"
                                            class="tabs-badge">
                                        </van-badge>
                                    </template>
                                    <template v-else>
                                        裥裥大恻面
                                        <van-badge :content="isFilterSucessBadge(fabricMxTab9)" class="tabs-badge"
                                            color="#5AC8FA" :show-zero="false">
                                        </van-badge>
                                    </template>
                                </template>
                                <lj-grid :table-data="fabricMxTab10" :columns="gridColumns_mx" />
                            </van-tab>
                            <van-tab title="裥小恻" name="tabpage_11" v-if="Number(mattresstypeEnum.if_small_side) == 1">
                                <template #title>
                                    <template v-if="isFilterErrorBadge(fabricMxTab10)">
                                        裥小恻
                                        <van-badge :content="isFilterErrorBadge(fabricMxTab10) + '异常'"
                                            class="tabs-badge">
                                        </van-badge>
                                    </template>
                                    <template v-else>
                                        裥小恻
                                        <van-badge :content="isFilterSucessBadge(fabricMxTab10)" class="tabs-badge"
                                            color="#5AC8FA" :show-zero="false">
                                        </van-badge>
                                    </template>
                                </template>
                                <lj-grid :table-data="fabricMxTab11" :columns="gridColumns_mx" />
                            </van-tab>
                            <van-tab title="裥V恻" name="tabpage_12" v-if="Number(mattresstypeEnum.if_v_side) == 1">
                                <template #title>
                                    <template v-if="isFilterErrorBadge(fabricMxTab11)">
                                        裥V恻
                                        <van-badge :content="isFilterErrorBadge(fabricMxTab11) + '异常'"
                                            class="tabs-badge">
                                        </van-badge>
                                    </template>
                                    <template v-else>
                                        裥V恻
                                        <van-badge :content="isFilterSucessBadge(fabricMxTab11)" class="tabs-badge"
                                            color="#5AC8FA" :show-zero="false">
                                        </van-badge>
                                    </template>
                                </template>
                                <lj-grid :table-data="fabricMxTab12" :columns="gridColumns_mx" />
                            </van-tab>
                            <van-tab title="拉手刺绣及其他工艺" name="tabpage_13">
                                <template #title>
                                    <template v-if="isFilterErrorBadge(fabricMxTab12)">
                                        拉手刺绣及其他工艺
                                        <van-badge :content="isFilterErrorBadge(fabricMxTab12) + '异常'"
                                            class="tabs-badge">
                                        </van-badge>
                                    </template>
                                    <template v-else>
                                        拉手刺绣及其他工艺
                                        <van-badge :content="isFilterSucessBadge(fabricMxTab12)" class="tabs-badge"
                                            color="#5AC8FA" :show-zero="false">
                                        </van-badge>
                                    </template>
                                </template>
                                <lj-grid :table-data="fabricMxTab13" :columns="gridColumns_mx" />
                            </van-tab>
                        </van-tabs>
                    </rp-summary-item>
                </van-tab>
                <van-tab title="床网" name="bednetMx">
                    <template #title>
                        <template v-if="isFilterErrorBadge(bednetMxData)">
                            <van-badge :content="isFilterErrorBadge(bednetMxData) + '异常'" class="tabs-badge">
                                面料
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isFilterSucessBadge(bednetMxData)" class="tabs-badge" color="#2196f3"
                                :show-zero="false">
                                面料
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="床网明细" simple>
                        <lj-grid :table-data="bednetMxData" :columns="gridColumns_bednet" />
                    </rp-summary-item>
                </van-tab>
                <van-tab title="垫层" name="cushionsMx">
                    <template #title>
                        <template v-if="isFilterErrorBadge(cushionsMxData)">
                            <van-badge :content="isFilterErrorBadge(cushionsMxData) + '异常'" class="tabs-badge">
                                垫层
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isFilterSucessBadge(cushionsMxData)" class="tabs-badge" color="#2196f3"
                                :show-zero="false">
                                垫层
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="垫层明细" simple>
                        <lj-grid :table-data="cushionsMxData" :columns="gridColumns_cushions" />
                    </rp-summary-item>
                </van-tab>
                <van-tab title="辅料" name="accessoriesMx">
                    <template #title>
                        <template v-if="isFilterErrorBadge(accessoriesMxData)">
                            <van-badge :content="isFilterErrorBadge(accessoriesMxData) + '异常'" class="tabs-badge">
                                辅料
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isFilterSucessBadge(accessoriesMxData)" class="tabs-badge"
                                color="#2196f3" :show-zero="false">
                                辅料
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="辅料明细" simple>
                        <lj-grid :table-data="accessoriesMxData" :columns="gridColumns_accessories" />
                    </rp-summary-item>
                </van-tab>
                <van-tab title="包装" name="packagMx">
                    <template #title>
                        <template v-if="isFilterErrorBadge(packagMxData)">
                            <van-badge :content="isFilterErrorBadge(packagMxData) + '异常'" class="tabs-badge">
                                包装
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isFilterSucessBadge(packagMxData)" class="tabs-badge" color="#2196f3"
                                :show-zero="false">
                                包装
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="包装明细" simple>
                        <van-form>
                            <van-cell title="包装方式" :value="mainObject.packtype | enumFilter(packtypeOptions)" is-link class="base-cell" />
                            <van-field label="卷包直径" v-model="mainObject.diameter" type="number" :disabled="!editEnabled" v-if="mainObject.packtype == 1"/>
                            <van-cell title="木托方式" :value="mainObject.woodpallettype | enumFilter(woodpallettypeOptions)" is-link class="base-cell" v-if="mainObject.packtype == 0"/>
                            <van-field label="压包数量" v-model="mainObject.packqty" type="number" :disabled="!editEnabled" v-if="mainObject.packtype == 0"/>
                            <van-cell title="地区" :value="mainObject.area | enumFilter(areaOptions)" is-link class="base-cell" />
                            <van-cell title="柜型" :value="mainObject.cabinet_type | enumFilter(cabinetTypeOptions)" is-link class="base-cell" />
                            <van-field label="体积" v-model="mainObject.cubage" type="number" :disabled="!editEnabled"/>
                        </van-form>

                        <lj-grid :table-data="packagMxData" :columns="gridColumns_packag" />
                    </rp-summary-item>
                </van-tab>
                <van-tab title="内布套" name="innerClothLayerMx" v-if="Number(mainObject.if_n_butao)">
                    <template #title>
                        <template v-if="isFilterErrorBadge(innerClothLayerMxData)">
                            <van-badge :content="isFilterErrorBadge(innerClothLayerMxData) + '异常'" class="tabs-badge">
                                内布套
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isFilterSucessBadge(innerClothLayerMxData)" class="tabs-badge"
                                color="#2196f3" :show-zero="false">
                                内布套
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="内布套明细" simple>
                        <lj-grid :table-data="innerClothLayerMxData" :columns="gridColumns_inner" />
                    </rp-summary-item>
                </van-tab>
                <van-tab title="顶布裥棉" name="topCottonMx" v-if="Number(mainObject.if_w_butao)">
                    <template #title>
                        <template v-if="isFilterErrorBadge(topCottonMxData)">
                            <van-badge :content="isFilterErrorBadge(topCottonMxData) + '异常'" class="tabs-badge">
                                顶布裥棉
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="isFilterSucessBadge(topCottonMxData)" class="tabs-badge"
                                color="#2196f3" :show-zero="false">
                                顶布裥棉
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="顶布裥棉" simple>
                        <lj-grid :table-data="topCottonMxData" :columns="gridColumns_mx" />
                    </rp-summary-item>
                </van-tab>
                <van-tab title="主副规格" name="subSpecs">
                    <template #title>
                        <template v-if="mainObject.parentid > 0">
                            <van-badge content="副" class="tabs-badge">
                                主副规格
                            </van-badge>
                        </template>
                        <template v-else>
                            <van-badge :content="subSpecsMxData.length > 0 ? subSpecsMxData.length : ''" class="tabs-badge" color="#2196f3">
                                主副规格
                            </van-badge>
                        </template>
                    </template>
                    <rp-summary-item title="主副规格" simple>
                        <lj-grid :table-data="subSpecsMxData" :columns="gridColumns_subspecs" />
                    </rp-summary-item>
                </van-tab>
            </van-tabs>
        </div>
        <div class="detail-control" slot="footer">
            <template v-if="mainObject.parentid > 0">
                <van-button class="btn" round block type="info" @click="gotoMattress">
                    查看主规格报价
                </van-button>
            </template>
            <template v-else-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-if="mainObject.xd_flag == 1">
                <van-button class="btn" round block type="info" @click="gotoAudit('flag', 1)" :disabled="isCheckPower(73)">
                    财务审核
                </van-button>
                <van-button class="btn" round block @click="gotoAudit('xd_flag', 0)" :disabled="isCheckPower(95)">
                    取消业务下单
                </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(1)">
                    修改
                </van-button>
                <van-button class="btn" round block @click="gotoAudit('xd_flag', 1)" :disabled="isCheckPower(94)">
                    业务下单
                </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 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.initLayouColumns();

        this.refresh();

        this.getFormulakindEnum();
    },
    mounted() {
        let user = $lj.getStorage("user");
        this.username = user.username;

        var self = this;
        $lj.addEventListener("mattress_quote_mx_refresh", function () {
            self.refresh();
        });


        // 赋值：面料tabs粘贴布局离顶部距离
        this.$nextTick(() => {
            let height = this.headerHeight ? this.headerHeight + "" : "0";
            height = Number(height.replace("px", ""));
            const tabsRef = this.$refs.vantabsRef;
            // 查找子元素
            const navElement = tabsRef.$el.querySelector('.van-tabs__nav');
            // 获取高度
            this.fabricHeaderHeight = navElement ? (height + navElement.offsetHeight - 15) + 'px' : (height + 44) + 'px';
        })
    },
    data() {
        return {
            editEnabled: false,
            mainObject: {},
            oriMxData: {}, // 原始明细数据
            fabricMxData: [], // 面料明细数据
            fabricMxTab8: [], // 面料明细数据
            fabricMxTab9: [], // 面料明细数据
            fabricMxTab10: [], // 面料明细数据
            fabricMxTab11: [], // 面料明细数据
            fabricMxTab12: [], // 面料明细数据
            fabricMxTab13: [], // 面料明细数据
            cushionsMxData: [], // 垫层明细数据
            accessoriesMxData: [], // 辅料明细数据
            packagMxData: [], // 包装明细数据
            bednetMxData: [], // 床网明细数据
            innerClothLayerMxData: [], // 内布套明细数据
            topCottonMxData: [], // 顶布裥棉明细数据
            subSpecsMxData: [], // 主副规格明细数据
            fabricMxTabList: [
                {
                    label: "裥面",
                    name: "tabpage_8",
                    visible: () => Number(this.mattresstypeEnum.if_top_side) == 1,
                    type: [0, 80, 40, 50, 60, 70, 9000],
                    ref: "fabricMxTab8"
                },
                {
                    label: "裥底",
                    name: "tabpage_9",
                    visible: () => Number(this.mattresstypeEnum.if_button_sdie) == 1,
                    type: [1, 81, 41, 51, 61, 71, 9001],
                    ref: "fabricMxTab9"
                },
                {
                    label: "裥大恻",
                    name: "tabpage_10",
                    visible: () => Number(this.mattresstypeEnum.if_big_side) == 1,
                    type: [2, 82, 42, 52, 62, 72, 9002],
                    ref: "fabricMxTab10"
                },
                {
                    label: "裥小恻",
                    name: "tabpage_11",
                    visible: () => Number(this.mattresstypeEnum.if_small_side) == 1,
                    type: [3, 83, 43, 53, 63, 73, 9003],
                    ref: "fabricMxTab11"
                },
                {
                    label: "裥V恻",
                    name: "tabpage_12",
                    visible: () => Number(this.mattresstypeEnum.if_v_side) == 1,
                    type: [4, 84, 44, 54, 64, 74, 9004],
                    ref: "fabricMxTab12"
                },
                {
                    label: "拉手刺绣及其他工艺",
                    name: "tabpage_13",
                    visible: () => true,
                    type: [
                        0, 80, 40, 50, 60, 70, 1, 81, 41, 51, 61, 71, 2, 82, 42, 52, 62, 72, 3, 83, 43, 53, 63, 73, 4, 84, 44, 54, 64, 74, 9000,
                        9001, 9002, 9003, 9004, 9005, 9006
                    ], // not in
                    ref: "fabricMxTab13"
                },
                {
                    label: "床网",
                    name: "bednetMx",
                    ref: "bednetMxData"
                },
                {
                    label: "垫层",
                    name: "cushionsMx",
                    ref: "cushionsMxData"
                },
                {
                    label: "辅料",
                    name: "accessoriesMx",
                    ref: "accessoriesMxData"
                },
                {
                    label: "包装",
                    name: "packagMx",
                    ref: "packagMxData"
                },
                {
                    label: "内布套",
                    name: "innerClothLayerMx",
                    ref: "innerClothLayerMxData"
                },
                {
                    label: "顶布裥棉",
                    name: "topCottonMx",
                    ref: "topCottonMxData"
                }
            ],
            otherMxTabList: [
                {
                    label: "内布套",
                    name: "tabpage_14",
                    type: [101, 102, 103, 104, 105, 106]
                },
                {
                    label: "外布套",
                    name: "tabpage_15",
                    type: [111, 112, 113, 114, 115, 116]
                }
            ],
            gridColumns_bednet: [],
            gridColumns_cushions: [],
            gridColumns_accessories: [],
            gridColumns_packag: [],
            gridColumns_inner: [],
            gridColumns_subspecs: [],
            gridColumns_mx: [],
            username: "",
            activeName: "base",
            fabricMxTabs: "",
            headerHeight: 80,// header高度
            fabricHeaderHeight: 0,
            headerBg: "transparent",
            headerTextColor: "#fff",
            // headerOverHeight: 32,// header超出滚动高度
            deptEnum: [],
            mattresstypeEnum: {},
            formulaKindEnum: [], // 计算公式类型
            formulaKindDcEnum: [], // 计算公式类型-垫层
            columns: [], // 表格列布局信息
            basicGroup: [], // 基础信息分组
            cmpFormulas: null, // 计算公式
            cmpFormulaReplace: null, // 计算公式替换
            showAction: false, // 是否显示操作按钮
            billActions: [], // 单据操作按钮
            statisticData: [
                {
                    label: "【标准金额】",
                    value: 0
                },
                {
                    label: "【大单金额】",
                    value: 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,
                    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,
                    subtitle: "报价金额",
                    power: () => {
                        let userInfo = $lj.getStorage('user');
                        return userInfo.usermode === 0;
                    }
                }
            ],
            columnsExtraAttr: [
                {
                    field: "deptid",
                    title: "部门",
                    basicinfo: {
                        el: "select",
                        // rules: [{ required: true, message: "请先选择部门", trigger: "change" }],
                        props: {
                            filterable: true,
                            clearable: false
                        },
                        order: 1,
                        group: "单据信息"
                    }
                },
                {
                    field: "mattressrelcode",
                    title: "床垫编码",
                    basicinfo: {
                        // el: "input",
                    }
                },
                {
                    field: "mattresstypeid",
                    title: "床垫类别",
                    basicinfo: {
                        el: "select",
                        // rules: [{ required: true, message: "请先选择床垫类别", trigger: "change" }],
                        props: {
                            clearable: false,
                            filterable: true,
                            // onChange: () => funcImportMattressMx()
                        }
                    }
                },
                {
                    field: "mattressname",
                    title: "床垫名称",
                    align: "left",
                    table: "u_mattress",
                    basicinfo: {
                        el: "input",
                    },
                },
                {
                    field: "dept_profitrate_rangli",
                    title: "部门让利点数",
                    basicinfo: {
                        el: "input",
                        props: { type: "number" },
                    }
                },
                {
                    field: "fees_dscrp",
                    title: "额外费用说明",
                    basicinfo: {
                        el: "input",
                        props: { type: "textarea", rows: 2 },
                    }
                },
                {
                    field: "foreign_cost",
                    title: "外币价",
                    basicinfo: {
                        // titleKey: "bi_foreign_cost" // 报价金额
                    }
                },
                {
                    field: "nottax_dept_cost",
                    title: "部门不含税价",
                    basicinfo: {
                        // titleKey: "bi_nottax_dept_cost" // 财务底价
                    }
                },
                {
                    field: "if_bcp_type",
                    title: "半成品",
                    basicinfo: {
                        labelHidden: true,
                        // render: function (h, scope, self) {
                        //     let _render = [
                        //         h(LjCheckbox, {
                        //             props: {
                        //                 value: scope.data.if_bcp_type,
                        //                 label: "半成品",
                        //                 disabled: true
                        //             },
                        //             on: {
                        //                 input: function (val) {
                        //                     self.$emit("input", "if_bcp_type", val);
                        //                 }
                        //             }
                        //         }),
                        //         h(LjCheckbox, {
                        //             props: {
                        //                 value: scope.data.if_zhedie_type,
                        //                 label: "折叠款",
                        //                 disabled: true
                        //             },
                        //             on: {
                        //                 input: function (val) {
                        //                     self.$emit("input", "if_zhedie_type", val);
                        //                 }
                        //             }
                        //         }),
                        //     ];
                        //     return h("div", {
                        //         class: "lj-layout-grid-3"
                        //     }, _render)
                        // }
                    }
                },
                {
                    field: "if_m_chai",
                    title: "面拆",
                    basicinfo: {
                        span: 2,
                        labelHidden: true,
                        // render: function (h, scope, self) {
                        //     let _render = [
                        //         h(LjCheckbox, {
                        //             props: {
                        //                 value: scope.data.if_m_chai,
                        //                 label: "面拆",
                        //                 disabled: true
                        //             },
                        //             on: {
                        //                 input: function (val) {
                        //                     self.$emit("input", "if_m_chai", val);
                        //                 }
                        //             }
                        //         }),
                        //         h(LjCheckbox, {
                        //             props: {
                        //                 value: scope.data.if_z_chai,
                        //                 label: "中拆",
                        //                 disabled: true
                        //             },
                        //             on: {
                        //                 input: function (val) {
                        //                     self.$emit("input", "if_z_chai", val);
                        //                 }
                        //             }
                        //         }),
                        //         h(LjCheckbox, {
                        //             props: {
                        //                 value: scope.data.if_d_chai,
                        //                 label: "底拆",
                        //                 disabled: true
                        //             },
                        //             on: {
                        //                 input: function (val) {
                        //                     self.$emit("input", "if_d_chai", val);
                        //                 }
                        //             }
                        //         }),
                        //     ];
                        //     return h("div", {
                        //         class: "lj-layout-grid-3"
                        //     }, _render)
                        // }
                    }
                },
                {
                    field: "mattress_width",
                    title: "床垫宽/CM",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true, placeholder: "请输入床垫宽/CM" }
                    }
                },
                {
                    field: "mattress_length",
                    title: "床垫长/CM",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true, placeholder: "请输入床垫长/CM" }
                    }
                },
                {
                    field: "mattress_height",
                    title: "床垫高/CM",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true, placeholder: "请输入床垫高/CM" }
                    }
                },
                {
                    field: "if_w_butao",
                    title: "顶布裥棉",
                    basicinfo: {
                        el: "checkbox",
                        // editable: ALLOW_EDIT_STATE
                        // render: (scope: any) => {
                        // console.log("if_w_butao scope :>> ", scope);
                        // let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
                        // return (
                        //     <>
                        //     <el-checkbox
                        //         v-model={scope.searchParam.if_w_butao}
                        //         true-value={1}
                        //         false-value={0}
                        //         disabled={_disabled}
                        //         label="顶布裥棉"
                        //         class="mr-8"
                        //     />
                        //     </>
                        // );
                        // }
                    }
                },
                {
                    field: "biandai_qty",
                    title: "边带数",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: false,
                        editvisible: () => true,
                        // editable: (scope: any) => {
                        //     let someone =
                        //         Number(scope.searchParam.if_m_chai) +
                        //         Number(scope.searchParam.if_z_chai) +
                        //         Number(scope.searchParam.if_d_chai);
                        //     if (ALLOW_EDIT_STATE.includes(scope.status) && someone > 0) {
                        //         return true;
                        //     }
                        //     return false;
                        // }
                    }
                },
                {
                    field: "if_n_butao",
                    title: "内布套",
                    basicinfo: {
                        el: "checkbox",
                        //   labelHidden: true,
                        //   render: (scope: any) => {
                        //     let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
                        //     return (
                        //       <>
                        //         <el-checkbox
                        //           v-model={scope.searchParam.if_n_butao}
                        //           true-value={1}
                        //           false-value={0}
                        //           disabled={_disabled}
                        //           label="内布套"
                        //           class="mr-8"
                        //         />
                        //       </>
                        //     );
                        //   },
                        //   editvisible: (scope: any) => {
                        //     let someone =
                        //       Number(scope.searchParam.if_m_chai) +
                        //       Number(scope.searchParam.if_z_chai) +
                        //       Number(scope.searchParam.if_d_chai);
                        //     if (someone > 0) {
                        //       return true;
                        //     }
                        //     return false;
                        //   }
                    }
                },
                {
                    field: "s_cover_qty",
                    title: "内布套上覆",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: true,
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0 && Number(scope.searchParam.if_n_butao)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "z_cover_qty",
                    title: "内布套侧覆",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: true,
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0 && Number(scope.searchParam.if_n_butao)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "x_cover_qty",
                    title: "内布套下覆",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: true,
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0 && Number(scope.searchParam.if_n_butao)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "if_m_wbutao_way",
                    title: "面料外布套做法",
                    basicinfo: {
                        el: "checkbox",
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "s_m_cover_qty",
                    title: "面层向大侧覆盖",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: true,
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0 && Number(scope.searchParam.if_m_wbutao_way)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "z_m_cover_qty",
                    title: "大侧向底层覆盖",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: true,
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0 && Number(scope.searchParam.if_m_wbutao_way)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                {
                    field: "x_m_cover_qty",
                    title: "底层向大侧覆盖",
                    basicinfo: {
                        el: "input",
                        props: { type: "number", clearable: true },
                        editable: true,
                        editvisible: (scope) => {
                            let someone =
                                Number(scope.searchParam.if_m_chai) +
                                Number(scope.searchParam.if_z_chai) +
                                Number(scope.searchParam.if_d_chai);
                            if (someone > 0 && Number(scope.searchParam.if_m_wbutao_way)) {
                                return true;
                            }
                            return false;
                        }
                    }
                },
                // {
                // field: "commission",
                // title: "佣金点数",
                // basicinfo: {
                //     el: "input-number",
                //     editable: ALLOW_EDIT_STATE
                // }
                // },
                // {
                // field: "other_rate",
                // title: "额外点数",
                // basicinfo: {
                //     el: "input-number",
                //     editable: ALLOW_EDIT_STATE
                // }
                // },
                // {
                // field: "extras_cost",
                // title: "额外费用",
                // basicinfo: {
                //     el: "input-number",
                //     editable: ALLOW_EDIT_STATE
                // }
                // },
                {
                    field: "taxes",
                    title: "税金",
                    enum: [
                        {
                            label: "不含税",
                            value: 1
                        },
                        {
                            label: "含税",
                            value: 1.07
                        }
                    ],
                    basicinfo: {
                        el: "select",
                        editable: true,
                        // render: (scope: any) => {
                        // let optionRender = [];
                        // let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
                        // console.log("taxrate scope.enum :>> ", scope.enum);
                        // scope.enum.map(item => {
                        //     optionRender.push(<el-option label={item.label} value={item.value} />);
                        // });
                        // let slotprefix = {
                        //     prefix: () => {
                        //     return <>{scope.searchParam.taxrate}</>;
                        //     }
                        // };

                        // let _taxrate = Number(scope.searchParam.taxrate);
                        // return (
                        //     <el-select
                        //     v-model={_taxrate}
                        //     v-slots={slotprefix}
                        //     class="select-text-right"
                        //     disabled={_disabled}
                        //     onChange={val => funcTaxrateChange(val, scope.searchParam)}
                        //     >
                        //     {optionRender}
                        //     </el-select>
                        // );
                        // }
                    }
                },
                {
                    field: "moneyrate",
                    title: "汇率",
                    basicinfo: {
                        el: "select",
                        editable: true,
                        // render: (scope: any) => {
                        // let optionRender = [];
                        // let _disabled = !ALLOW_EDIT_STATE.includes(scope.status);
                        // scope.enum.map(item => {
                        //     optionRender.push(<el-option label={item.label} value={item.value} />);
                        // });
                        // let slotprefix = {
                        //     prefix: () => {
                        //     return <>{scope.searchParam.moneyrate}</>;
                        //     }
                        // };

                        // return (
                        //     <el-select
                        //     v-model={scope.searchParam.if_moneyrate}
                        //     v-slots={slotprefix}
                        //     class="select-text-right"
                        //     disabled={_disabled}
                        //     onChange={val => funcMoneyrateChange(val, scope.searchParam)}
                        //     >
                        //     {optionRender}
                        //     </el-select>
                        // );
                        // }
                    }
                }
            ],
            columnsExtraAttr_mx: [
                {
                    title: "计算成功?",
                    field: "if_success",
                    datatype: "checkbox",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    },
                    // render: (scope) => {
                    //     if (Number(scope.row.if_success)) {
                    //         return (
                    //             <>
                    //             <ElTag type="danger">异常</ElTag>
                    //             </>
                    //         );
                    //     } else {
                    //         return <></>;
                    //     }
                    // }
                },
                {
                    title: "+",
                    field: "addmx",
                    width: 80,
                    // render: (scope) => {
                    //     let _if_mtrl = Number(scope.row.if_mtrl);
                    //     if (_if_mtrl > 1) {
                    //     if (state.orderStatus) {
                    //         return (
                    //         <>
                    //             <ElPopconfirm
                    //             width="220"
                    //             icon={InfoFilled}
                    //             title={t("business.tips.mattress.addMx")}
                    //             confirm-button-text={t("common.addText")}
                    //             onConfirm={() => funcAddMtrlMx(scope)}
                    //             >
                    //             {{
                    //                 reference: () => {
                    //                 return <ElButton type="primary" plain circle icon={Plus}></ElButton>;
                    //                 }
                    //             }}
                    //             </ElPopconfirm>
                    //         </>
                    //         );
                    //         // return <ElButton type="primary" plain circle icon={Plus} onClick={() => funcAddMtrlMx(scope)}></ElButton>;
                    //     } else {
                    //         return <>+</>;
                    //     }
                    //     } else {
                    //     return <></>;
                    //     }
                    // },
                    sloteditable: true,
                    slot(h, scope) {
                        return null
                    }
                },
                {
                    title: "-",
                    field: "delmx",
                    width: 80,
                    // render: (scop) => {
                    //     let _if_mtrl = Number(scope.row.if_mtrl);
                    //     if (_if_mtrl > 1) {
                    //     if (state.orderStatus) {
                    //         return (
                    //         <>
                    //             <ElPopconfirm
                    //             width="220"
                    //             icon={InfoFilled}
                    //             title={t("business.tips.mattress.delMx")}
                    //             confirm-button-text={t("common.delText")}
                    //             confirm-button-type="danger"
                    //             onConfirm={() => funcDelMtrlMx(scope)}
                    //             >
                    //             {{
                    //                 reference: () => {
                    //                 return <ElButton type="danger" plain circle icon={Minus} />;
                    //                 }
                    //             }}
                    //             </ElPopconfirm>
                    //         </>
                    //         );
                    //         // return <ElButton type="danger" plain circle icon={Minus} onClick={() => funcDelMtrlMx(scope)}></ElButton>;
                    //     } else {
                    //         return <>-</>;
                    //     }
                    //     } else {
                    //     return <></>;
                    //     }
                    // }
                },
                {
                    title: "位置",
                    field: "chastr"
                },
                {
                    title: "公式名",
                    field: "formulakind",
                    align: "left",
                    // isFilterEnum: true,
                    // fieldNames: { value: "value", label: "label" },
                    // enum: async () => {
                    //   let res = await CommonDynamicSelect({
                    //     dsname: "_Mapper_formulakind",
                    //     queryparams: {}
                    //   });
                    //   return { data: res.datatable };
                    // }
                    // render: (scope: any) => {
                    //     const { column, row, status } = scope;
                    //     let itmName = state.formulaKindEnum.find(t => t.value == row.formulakind)?.label ?? "";
                    //     return <>{itmName}</>;
                    // }
                },
                {
                    title: "按物料？",
                    field: "if_mtrl",
                    enum: [
                        {
                            value: "0",
                            label: "无物料"
                        },
                        {
                            value: "1",
                            label: "单物料"
                        },
                        {
                            value: "2",
                            label: "多物料"
                        }
                    ]
                },
                {
                    title: "厚度cm",
                    field: "thickness",
                    datatype: "number",
                },
                {
                    title: "物料",
                    field: "mtrlname",
                    // editRender: {},
                    // editColRender: (scope: any) => {
                    //     console.log("mtrlname hooks render scope :>> ", scope);
                    //     console.log("mtrlname hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
                    //     const { $table, column, row, status } = scope;
                    //     let field = column.field;
                    //     let _label = column.title;
                    //     // if (column?.format) {
                    //     //   _label = handleRowAccordingToProp(searchParam, field, column?.format);
                    //     // }
                    //     let _deptid = state.LjDetailRef._mainData.deptid;
                    //     let deptEnum = state.LjDetailRef.enumMap.get("deptid");
                    //     let _pricelistid = 0;
                    //     console.log("deptEnum :>> ", deptEnum);
                    //     if (deptEnum) {
                    //     let depItem = deptEnum.find((item: any) => item.value == _deptid);
                    //     console.log("depItem :>> ", depItem);
                    //     if (depItem) {
                    //         _pricelistid = Number(depItem.pricelistid);
                    //     }
                    //     }
                    //     console.log("_pricelistid :>> ", _pricelistid, row.formulakind);

                    //     console.log("state.mtrltypeTabList :>> ", mtrltypeTabList);

                    //     let _mtrltypeItem: any = mtrltypeTabList.find(t => t.formulakinds.includes(Number(row.formulakind)));
                    //     !_mtrltypeItem && (_mtrltypeItem = { value: -1 });

                    //     let params = {
                    //     mtrltype: _mtrltypeItem.value,
                    //     pricelistid: _pricelistid
                    //     };

                    //     return (
                    //     <>
                    //         <MtrldefSelect
                    //         value={row.mtrlid}
                    //         {...params}
                    //         clearable
                    //         placeholder={_label}
                    //         onOpenModal={() => fModelChoseMtrl(row, params, rModelSetMtrl, _mtrltypeItem.label, $table)}
                    //         onSelect={val => rModelSetMtrl(row, val, $table)}
                    //         onClear={() => rModelClearMtrl(row, $table)}
                    //         >
                    //         {{
                    //             label: () => row.mtrlname
                    //         }}
                    //         </MtrldefSelect>
                    //     </>
                    //     );
                    // }
                },
                {
                    title: "数量/长度",
                    field: "qty",
                    datatype: "number",
                },
                {
                    title: "物料单价",
                    field: "price",
                    datatype: "number",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "单位",
                    field: "priceunit"
                },
                {
                    title: "收缩率",
                    field: "shrinkage",
                    datatype: "number",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "克重",
                    field: "gram_weight",
                    datatype: "number",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "幅宽",
                    field: "cloth_width",
                    datatype: "number",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "固定厚度?",
                    field: "if_inputqty",
                    datatype: "checkbox",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "按面积单价？",
                    field: "if_areaprice",
                    datatype: "checkbox",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "成本金额",
                    field: "costamt",
                    datatype: "number",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "金额文本公式",
                    field: "formula",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "金额数字公式",
                    field: "replace_formula",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "清单用量",
                    field: "useqty",
                    datatype: "number",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "用量文本公式",
                    field: "useformula",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "用量数字公式",
                    field: "replace_useformula",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    }
                },
                {
                    title: "工艺填写说明",
                    field: "gydscrp"
                }
            ],
            bednetCoumns: [
                {
                    title: "位置",
                    field: "chastr",
                    visible: false
                },
                {
                    title: "床网",
                    field: "mtrlname",
                    // editRender: {},
                    width: 250,
                    // editColRender: (scope: any) => {
                    //     console.log("mtrlname hooks render scope :>> ", scope);
                    //     console.log("mtrlname hooks render LjDetailRef.value._mainData :>> ", state.LjDetailRef);
                    //     const { column, row, status, $table } = scope;
                    //     let _label = column.title;
                    //     let _deptid = state.LjDetailRef._mainData.deptid;

                    //     let params = {
                    //     deptid: _deptid,
                    //     mattress_width: state.LjDetailRef._mainData.mattress_width,
                    //     mattress_length: state.LjDetailRef._mainData.mattress_length
                    //     };

                    //     return (
                    //     <BednetSelect
                    //         value={row.mtrlid}
                    //         {...params}
                    //         clearable
                    //         placeholder={_label}
                    //         onOpenModal={() => fModelChoseBednet(row, params, $table)}
                    //         onSelect={(val: any) => rModelSetBednet(row, val, $table)}
                    //         onClear={() => rModelClearBednet(row, $table)}
                    //     >
                    //         {{
                    //         label: () => row.mtrlname
                    //         }}
                    //     </BednetSelect>
                    //     );
                    // }
                },
            ],
            cushionsColumns: [
                {
                    title: "位置",
                    field: "chastr",
                },
                {
                    title: "公式名",
                    field: "formulakind",
                },
                {
                    title: "+",
                    field: "addmx",
                    visible: false
                },
                {
                    title: "-",
                    field: "delmx",
                    visible: false
                },
                {
                    title: "按物料?",
                    field: "if_mtrl",
                    visible: false
                },
            ],
            accessoriesColumns: [
                {
                    title: "位置",
                    field: "chastr",
                    visible: false
                },
                {
                    title: "厚度cm",
                    field: "thickness",
                    limited: true
                }
            ],
            packagColumns: [
                {
                    title: "位置",
                    field: "chastr",
                    visible: false
                },
                {
                    title: "厚度cm",
                    field: "thickness",
                    limited: true
                }
            ],
            columnsMxInnerClothLayer: [
                {
                    title: "计算成功?",
                    field: "if_success",
                    datatype: "checkbox",
                    limited: () => {
                        let user = $lj.getStorage("user");
                        return user.usermode != 0;
                    },
                    slot(h, scope) {
                        if (Number(scope.row.if_success)) {
                            return h(VanTag, {
                                props: {
                                    type: "danger",
                                }
                            }, "异常");
                        } else {
                            return null;
                        }
                    }
                },
            ],
            packtypeOptions: [
                {
                    label: "压包",
                    value: 0
                },
                {
                    label: "卷包",
                    value: 1
                },
                {
                    label: "国内",
                    value: 2
                }
            ],
            woodpallettypeOptions: [
                {
                    label: "普通木托",
                    value: 0
                },
                {
                    label: "夹板木托",
                    value: 1
                },
                {
                    label: "铁管木托",
                    value: 2
                }
            ],
            areaOptions: [
                {
                    label: "普通地区",
                    value: "普通地区"
                },
                {
                    label: "特定地区",
                    value: "特定地区"
                }
            ],
            cabinetTypeOptions: [
                {
                    label: "大柜",
                    value: "大柜"
                },
                {
                    label: "小柜",
                    value: "小柜"
                }
            ],
        }
    },
    methods: {
        refresh(cb) {
            let params = {
                arg_mattressid: this.mainObject.mattressid
            }
            $lj.postCommonLJRequest("web_mattress", params, "u_mattress", (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.getData_innerClothLayer();
                this.getData_topCotton();

                this.afterMounted()
                // 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 _mattresstypeItem = data.tableinfo.columns.find(item => item.field == 'mattresstypeid');
            if (_mattresstypeItem && _mattresstypeItem.enum) {
                this.mattresstypeEnum = _mattresstypeItem.enum.find(o => o.value == this.mainObject.mattresstypeid);
            }

            if (this.mainObject.flag == 1) {
                // 已审核后操作按钮列表
                this.billActions = [
                    { name: '删除', color: '#ee0a24' },
                    { name: '财务撤审' },
                    // { name: '查看历史报价' }
                ]
                if (this.mainObject.xd_flag == 1) {
                    this.billActions.push( { name: '取消业务下单' })
                } else {
                    this.billActions.push( { name: '业务下单' })
                }
            } else if (this.mainObject.xd_flag == 1) {
                // 已审核后操作按钮列表
                this.billActions = [
                    { name: '删除', color: '#ee0a24' },
                    { name: '显示计算公式' },
                    { name: '复制报价' },
                    // { name: '查看历史报价' }
                ]
            } else {
                this.billActions = [
                    { name: '删除', color: '#ee0a24' },
                    { name: '显示计算公式' },
                    { name: '复制报价' },
                    // { name: '查看历史报价' }
                ]
                if (this.mainObject.flag == 1) {
                    this.billActions.push( { name: '财务撤审' })
                } else {
                    this.billActions.push( { name: '财务审核' })
                }
            }
        },
        getMattressType() {

            let _dftabs = "";
            let _fabricShowList = undefined;
            let itmshow = null;

            if (_dftabs) {
                _fabricShowList = this.fabricMxTabList
                    .map(o => Object.keys(o).includes("visible") && o.visible() && o)
                    .find(o => o.name == _dftabs);
            }
            if (_fabricShowList) {
                itmshow = _fabricShowList;
            } else {
                itmshow = this.fabricMxTabList.find(o => Object.keys(o).includes("visible") && o.visible() && o);
            }
            this.fabricMxTabs = itmshow.name
        },
        afterMounted() {
            this.getMattressType();
            this.getData_mx(() => {
                this.funcChaifenTab();

                this.getData_subSpecs();

                this.gotoSummy();
            })
        },
        getData_mx(cb) {
            let params = {
                arg_mattressid: this.mainObject.mattressid
            }
            $lj.postCommonLJRequest("web_mattress_mx", params, "u_mattress_mx_mtrl", (res) => {
                if (res && res.datatable) {
                    this.oriMxData = {
                        list: res.datatable,
                        tableinfo: res.tableinfo,
                    };

                    cb && cb()
                }
            })

        },
        /**
         * @description 拆分tab
         */
        funcChaifenTab() {
            // 面料
            this.fabricMxData = this.oriMxData.list.filter(
                t => t.formulatype == 0 || (Number(this.mainObject.if_bcp_type) == 1 && t.formulatype == 104)
            );

            console.log("funcChaifenTab fabricMxData :>> ", this.fabricMxData);
            let _mx8 = this.fabricMxTabList.find(t => t.name == "tabpage_8");
            this.fabricMxTab8 = this.fabricMxData.filter(t => _mx8.type.includes(Number(t.formulakind)));
            this.fabricMxTab8.forEach((o, i) => {
                o.xu = i + 1;
            });
            console.log("funcChaifenTab fabricMxTab8 :>> ", this.fabricMxTab8);

            let _mx9 = this.fabricMxTabList.find(t => t.name == "tabpage_9");
            this.fabricMxTab9 = this.fabricMxData.filter(t => _mx9.type.includes(Number(t.formulakind)));
            this.fabricMxTab9.forEach((o, i) => {
                o.xu = i + 1;
            });

            let _mx10 = this.fabricMxTabList.find(t => t.name == "tabpage_10");
            this.fabricMxTab10 = this.fabricMxData.filter(t => _mx10.type.includes(Number(t.formulakind)));
            this.fabricMxTab10.forEach((o, i) => {
                o.xu = i + 1;
            });

            let _mx11 = this.fabricMxTabList.find(t => t.name == "tabpage_11");
            this.fabricMxTab11 = this.fabricMxData.filter(t => _mx11.type.includes(Number(t.formulakind)));
            this.fabricMxTab11.forEach((o, i) => {
                o.xu = i + 1;
            });

            console.log("funcChaifenTab this.fabricMxTab11 :>> ", this.fabricMxTab11);

            let _mx12 = this.fabricMxTabList.find(t => t.name == "tabpage_12");
            this.fabricMxTab12 = this.fabricMxData.filter(t => _mx12.type.includes(Number(t.formulakind)));
            this.fabricMxTab12.forEach((o, i) => {
                o.xu = i + 1;
            });

            let _mx13 = this.fabricMxTabList.find(t => t.name == "tabpage_13");
            this.fabricMxTab13 = this.fabricMxData.filter(t => !_mx13.type.includes(Number(t.formulakind)));
            this.fabricMxTab13.forEach((o, i) => {
                o.xu = i + 1;
            });

            // 垫层
            this.cushionsMxData = this.oriMxData.list.filter(t => t.formulatype == 1);
            this.cushionsMxData.forEach((o, i) => {
                o.xu = i + 1;
            });
            // 辅料
            this.accessoriesMxData = this.oriMxData.list.filter(t => t.formulatype == 2);
            this.accessoriesMxData.forEach((o, i) => {
                o.xu = i + 1;
            });
            // 包装
            this.packagMxData = this.oriMxData.list.filter(t => t.formulatype == 3);
            this.packagMxData.forEach((o, i) => {
                o.xu = i + 1;
            });
            // 床网
            this.bednetMxData = this.oriMxData.list.filter(t => t.formulatype == 99);
            this.bednetMxData.forEach((o, i) => {
                o.xu = i + 1;
            });
        },
        /**窗口高度 */
        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);
            });
        },
        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();
                }
            })
        },
        onSelectAction(item) {
            console.log('item :>> ', JSON.stringify(item));
            if (item.name == "财务审核") {
                this.gotoAudit("flag", 1);
            } else if (item.name == "财务撤审") {
                this.gotoAudit("flag", 0);
            } else if (item.name == "业务下单") {
                this.gotoAudit("xd_flag", 1);
            } else if (item.name == "取消业务下单") {
                this.gotoAudit("xd_flag", 0);
            } else if (item.name == "显示计算公式") {
                this.gotoCheckmx();
            } else if (item.name == "查看历史报价") {
                this.gotoCheckmx();
            } else if (item.name == "复制报价") {
                this.gotoCopyQuote(2);
            } else if (item.name == "删除") {
                if (!$lj.checkPower(77)) {
                    alert("你没有【报价单-删除】的使用权限");
                    return;
                }

                $lj.confirm("提示", "是否删除本单据", () => {
                    $lj.postLJRequest("DelMattress", {
                        token: $lj.getStorage("token"),
                        mattressids: [this.mainObject.mattressid],
                    }, function (rsp) {
                        if (rsp) {
                            this.$toast.success("删除成功");
                            $lj.sendEvent("mattress_quote_refresh");

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

            this.showAction = false;
        },
        gotoEdit(winType = 1) {
            if (!$lj.checkPower(72)) {
                alert("你没有【报价单-修改】的使用权限");
                return;
            }
            $lj.openWin("mattress-quote-new", {
                mainObject: this.mainObject,
                winType: winType
            });
        },
        gotoAudit(type, value) {
            let self = this;
            let title;
            let _params = {};
            if (type == "xd_flag") {
                if (value) {
                    title = "业务下单";
                    if (!$lj.checkPower(94)) {
                        alert("你没有【报价单-业务下单】的使用权限");
                        return;
                    }
                } else {
                    title = "取消业务下单";
                    if (!$lj.checkPower(95)) {
                        alert("你没有【报价单-取消业务下单】的使用权限");
                        return;
                    }
                }
            } else {
                if (value) {
                    title = "财务审核";
                    if (!$lj.checkPower(73)) {
                        alert("你没有【报价单-财务审核】的使用权限");
                        return;
                    }
                } else {
                    title = "财务撤审";
                    if (!$lj.checkPower(74)) {
                        alert("你没有【报价单-财务撤审】的使用权限");
                        return;
                    }
                }
            }
            _params[type] = value;

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

                    self.refresh();
                }
            })
        },
        gotoCopyQuote() {
            this.gotoEdit(2);
        },
        gotoCheckmx() {
        },
        gotoMattress() {
            // $lj.closeWin();
            // $lj.openWin("mattress-quote-mx", {
            //     mainObject: {
            //         mattressid: this.mainObject.parentid
            //     },
            //     winType: 0
            // });

            this.mainObject.mattressid = this.mainObject.parentid;
            this.refresh();
        },
        /**
         * @description 展示计算公式
         * @param timeout
         */
        gotoSummy() {

            let _mattress = this.mainObject;
            _mattress.mattressid = Number(_mattress.mattressid);
            _mattress.xd_flag = Number(_mattress.xd_flag);
            _mattress.js1_flag = Number(_mattress.js1_flag);
            _mattress.flag = Number(_mattress.flag);

            let _mattressMx = [];
            this.fabricMxTabList.map(t => {
                if (t.ref) {
                    console.log('gotoSummy this[t.ref] :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this[t.ref]));
                    if (this[t.ref]) {
                        // let { fullData } = dynamicRef(t.ref)?.element.getTableData();
                        let fullData = this[t.ref];
                        console.log("fullData :>> ", fullData);
                        fullData = fullData.map((itm, idx) => {
                            itm.xu = idx + 1;
                            return itm;
                        });
                        _mattressMx = _mattressMx.concat(fullData);
                    }
                }
            });

            let _params = {
                token: $lj.getStorage("token"),
                mattress: _mattress,
                mattressMx: _mattressMx
            };

            $lj.postLJRequest("GetComputeMattress", _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));
                }
            })
        },
        /**
         * @description 合并表格结构数据
         */
        funcMergeColumn(columns, target) {
            return columns.map(t => {
                let itm = target.find(item => t.field === item.field);
                if (itm) {
                    t = $lj.defaultsDeep(itm, t);
                }
                return t;
            });
        },
        getFormulakindEnum() {
            $lj.postCommonLJRequest("_Mapper_formulakind", {}, "", (res) => {
                if (res && res.datatable && res.datatable.length > 0) {
                    this.formulaKindEnum = res.datatable;
                }
            })

            $lj.postCommonLJRequest("_Mapper_formulakind_dc", {}, "", (res) => {
                if (res && res.datatable && res.datatable.length > 0) {
                    this.formulaKindDcEnum = res.datatable;
                }
            })
        },
        initLayouColumns() {
            this.gridColumns_mx = $lj.getCommonColumns(this.columnsExtraAttr_mx);
            this.gridColumns_bednet = $lj.getCommonColumns(this.funcMergeColumn(this.columnsExtraAttr_mx, this.bednetCoumns));
            this.gridColumns_cushions = $lj.getCommonColumns(this.funcMergeColumn(this.columnsExtraAttr_mx, this.cushionsColumns));
            this.gridColumns_accessories = $lj.getCommonColumns(this.funcMergeColumn(this.columnsExtraAttr_mx, this.accessoriesColumns));
            this.gridColumns_packag = $lj.getCommonColumns(this.funcMergeColumn(this.columnsExtraAttr_mx, this.packagColumns));
        },
        /**
         * @description 获取内布套数据
         */
        getData_innerClothLayer() {
            if (this.mainObject.mattressid <= 0) return false;

            this.innerClothLayerMxData = [];
            let params = {
                arg_mattressid: this.mainObject.mattressid,
                arg_formulatype: [101, 102]
            }
            $lj.postCommonLJRequest("web_mattress_mx_neibutao", params, "u_mattress_mx_mtrl__neibutao", (res) => {
                if (res) {
                    this.innerClothLayerMxData = res.datatable;
                    let columns = $lj.setExtraColumns(res.tableinfo.columns, this.columnsMxInnerClothLayer);
                    this.gridColumns_inner = $lj.getCommonColumns(columns);
                }
            })
        },
        /**
         * @description 获取顶布裥棉数据
         */
        getData_topCotton() {
            if (this.mainObject.mattressid <= 0) return false;

            this.topCottonMxData = [];
            let params = {
                arg_mattressid: this.mainObject.mattressid,
                arg_formulatype: [103]
            }
            $lj.postCommonLJRequest("web_mattress_mx", params, "u_mattress_mx_mtrl", (res) => {
                if (res && res.datatable) {
                    this.topCottonMxData = res.datatable;
                }
            })
        },
        /**
         * @description 获取主副规格数据
         */
        getData_subSpecs() {
            if (this.mainObject.mattressid <= 0) return false;

            this.subSpecsMxData = [];
            let params = {
                arg_mattressid: this.mainObject.mattressid,
            }
            $lj.postCommonLJRequest("web_mattress_subspecs", params, "u_mattress_subspecs", (res) => {
                if (res && res.datatable) {
                    this.subSpecsMxData = res.datatable;
                    let columns = $lj.setExtraColumns(res.tableinfo.columns, []);
                    this.gridColumns_subspecs = $lj.getCommonColumns(columns);
                }
            })
        }
    },
    computed: {
        title() {
            if (this.editEnabled) {
                return "床垫报价确认";
            } else {
                return "床垫报价详情";
            }
        },
        isCheckPower(id) {
            return function (id) {
                return !$lj.checkPower(id);
            }
        },
        isTabsBadge_fabric() {
            let arr = [];
            arr = this.fabricMxTab8.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
            arr = arr.concat(this.fabricMxTab9.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
            arr = arr.concat(this.fabricMxTab10.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
            arr = arr.concat(this.fabricMxTab11.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
            arr = arr.concat(this.fabricMxTab12.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
            arr = arr.concat(this.fabricMxTab13.filter(t => t.mtrlid && Number(t.mtrlid) > 0));
            return arr.length > 0 ? arr.length : "";
        },
        isTabsBadge_fabric_error() {
            console.log(' this.fabricMxTab8 :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.fabricMxTab8));
            let arr = [];
            arr = this.fabricMxTab8.filter(t => Number(t.if_success));
            arr = arr.concat(this.fabricMxTab9.filter(t => Number(t.if_success)));
            arr = arr.concat(this.fabricMxTab10.filter(t => Number(t.if_success)));
            arr = arr.concat(this.fabricMxTab11.filter(t => Number(t.if_success)));
            arr = arr.concat(this.fabricMxTab12.filter(t => Number(t.if_success)));
            arr = arr.concat(this.fabricMxTab13.filter(t => Number(t.if_success)));
            return arr.length;
        },
        isFilterErrorBadge(data) {
            return function (data) {
                let arr = [];
                arr = data.filter(t => Number(t.if_success));
                return arr.length;
            }
        },
        isFilterSucessBadge(data) {
            return function (data) {
                let arr = [];
                arr = data.filter(t => t.mtrlid && Number(t.mtrlid) > 0);
                return arr.length > 0 ? arr.length : "";
            }
        },
    },
    filters: {
        enumFilter(data, arr) {
            let name = "";
            arr.forEach(itm => {
                if (Number(itm.value) == Number(data)) {
                    name = itm.label;
                } else if (itm.value == 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;
                }
            }
        }
    }
}

.mattress-tabs__fabric {
    .van-sticky--fixed {
        z-index: 89;
    }

    // .van-tab__text--ellipsis {
    //     display: block;
    // }
}
</style>
