<template>
    <lj-win-common :title="title" :show-back="true" ref="baseWin" @fix-body="fixbody">
        <template slot="body">
            <lj-dictionary :data="ware" :columns="dictColumns" :editing="ifedit"></lj-dictionary>

            <van-tabs v-model="tabActive" v-if="ware.routemxList.length > 0" color="#2196f3" class="route-main-tabs" sticky :offset-top="headerHeight">
                <van-tab title="工艺步骤">
                    <route-item v-for="(item,index) in ware.routemxList" :data="item" :key="'routeItem' + index">

                    </route-item>
                </van-tab>
                <van-tab title="引用状况">
                    <lj-grid :tableData="ware.mtrlList" :columns="gridColumns" @cell-click="handleRowCellClick"/>
                </van-tab>
            </van-tabs>
        </template>

        <template slot="footer">
            <mu-col tag="mu-button" color="green" @click="handleModify">修改</mu-col>
        </template>
    </lj-win-common>
</template>

<script>
    import ljWinCommon from "components/lj-win-common";
    import LjDictionary from "components/lj-dictionary";
    import LjGrid from "components/lj-grid";
    import RouteItem from "./route-item"

    export default {
        components: {
            ljWinCommon,
            LjDictionary,
            LjGrid,
            RouteItem
        },
        data() {
            return {
                outwareid: 0,
                ifedit: false,
                hiscus:[],
                ware: {
                    routemxList: []
                },
                title: "工艺路线详情",
                // dictColumns: [
                //     {label: "路线编号", property: "routecode", required: -1},
                //     {label: "路线名称", property: "routename", required: -1},
                //     {label: "路线说明", property: "dscrp", type: "TextArea", required: -1,style: "height: auto;"},
                //     {label: "建立人", property: "opemp", required: -1},
                //     {label: "建立时间", property: "opdate", required: -1},
                //     {label: "修改人", property: "modemp", required: -1},
                //     {label: "修改时间", property: "moddate", required: -1},
                // ],
                gridColumns: [
                    {label: "物料编码<i class='iconfont icon-right' style='font-size: 12px'>", property: "mtrlcode"},
                    {label: "物料名称", property: "mtrlname"},
                    {label: "工价表<i class='iconfont icon-right' style='font-size: 12px'>", property: "wpcode"},
                    {label: "工序编号", property: "procode"},
                    {label: "工序名称", property: "proname"},
                    {label: "工段编号", property: "wrkgrpcode"},
                    {label: "工段名称", property: "wrkgrpname"},
                ],
                ifmodify: false,
                tabActive: 0,
                headerHeight: 80,// header高度
            }
        },
        created() {
            var pageParm = $lj.getPageParam();
            this.ware = {...pageParm.mainObject,...this.ware};
            this.GetInwareCpListmx();
            var self = this;
            $lj.addEventListener("feedback_refresh", function (rsp) {
                self.GetInwareCpListmx();
            });
        },
        computed: {
            dictColumns(){
                let result = [];
                result = [
                    {label: "路线编号", property: "routecode", required: -1},
                    {label: "路线名称", property: "routename", required: -1},
                    {label: "路线说明", property: "dscrp", type: "TextArea", required: -1,style: "height: auto;"},
                    {label: "建立人", property: "opemp", required: -1},
                    {label: "建立时间", property: "opdate", required: -1},
                ];
                if (this.ware.moddate) {
                    result.push({label: "修改人", property: "modemp", required: -1})
                    result.push({label: "修改时间", property: "moddate", required: -1})
                }
                return result
            },  
        },
        methods: {
            /**窗口高度 */
            fixbody(obj){
                this.headerHeight = obj.marginTop;
            },
            GetInwareCpListmx() {
                var self = this;
                self.ware.routemxList = [];
                self.ware.mtrlList = [];
                $lj.postLJRequest("GetL1RouteMx", {
                    token: $lj.getStorage("token"),
                    routeid: this.ware.routeid
                }, function (ret) {
                    self.$nextTick(() => {
                        self.ware.routemxList = ret.routemxList;
                        self.ware.mtrlList = ret.mtrlList;
                    })
                })
            },
            handleModify(){
                if (!$lj.checkPower(5962)) {
                    alert("没有[生产进仓单]修改的权限");
                    return;
                }

                $lj.openWin('procode-route-edit', {ware: this.ware, winType: 1})
            },
            handleRowCellClick(event) {
                if (!event) {
                    return;
                }
                let {row, column} = event;
                if (!row || !column) {
                    return;
                }
                if (column.property == "wpcode") {
                    $lj.openWin("mtrl-sc-workpricetable", {
                        mainObject: row
                    });
                } 
                if (column.property == "mtrlcode") {
                    $lj.openWin("mtrldef-fj", {mainObject: row});
                }
            },
        },
    }
</script>

<style lang="less">
.route-main-tabs {
    .van-tabs__content {
        background-color: #fff;
    }
}
</style>