<template>
    <lj-win-common title="指令单-选择">
        <lj-searchbar slot="header_sub" hint="输入指令单/质检单号/产品编码进行查找" @search="handleSearchbar" v-model="keyword" />
        <div slot="body">
            <template v-for="item in orderList">
                <order-selection-item :item="item" @click.native="handleCellClick(item)"></order-selection-item>
            </template>
        </div>
    </lj-win-common>
</template>

<script>
    import ljWinCommon from 'components/lj-win-common'
    import LjSearchbar from "components/lj-searchbar";
    import OrderSelectionItem from './order-selection-item';

    export default {
        components: {
            LjSearchbar,
            ljWinCommon,
            OrderSelectionItem,
        },
        created() {
            var pageParm = $lj.getPageParam();
            // this.orderList = pageParm.orderList
            this.winType = pageParm.winType;
            this.getOrderList();
        },
        data() {
            return {
                orderList: [],
                winType: 0,
                keyword: "",
            }
        },
        methods: {
            getOrderList() {
                let self = this;
                $lj.postLJRequest("GetOrderMsgByCode", {
                    token: $lj.getStorage("token"),
                }, function (ret) {
                    if (ret.ProductionQualities) {
                        self.orderList = ret.ProductionQualities;
                    }
                })
            },
            handleSearchbar() {
                let self = this;
                this.orderList = [];
                $lj.postLJRequest("GetOrderMsgByCode", {
                    token: $lj.getStorage("token"),
                    keyword: this.keyword,
                }, function (ret) {
                    if (ret.ProductionQualities) {
                        ret.ProductionQualities.forEach((item) => {
                            self.orderList.push(item);
                        })
                    }
                })
            },
            handleCellClick(mainObject) {
                if (this.winType == 0) {
                    $lj.openWin("quality-feedback-new", {order: mainObject});
                }
                else if (this.winType == 1) {
                    $lj.openWin("production-quality-new", {order: mainObject});
                }
                else if (this.winType == 2){
                    $lj.openWin("qualitycheck-workgroup-edit", {order: mainObject});
                }
            },
        },
    }
</script>

<style>

</style>