<template>
    <lj-win-index-common :title="title"
                         api-name="GetL1SaletaskFore"
                         :addable="false"
                         :data-reset-callback="handleDataReset"
                         :data-loaded-callback="handleDataLoaded"
                         :query-hard-parms="queryHardParms"
                         :query-fields="queryFields"
                         :binding-parms="bindingParms"
                         ref="baseWin">
        <lj-searchbar slot="header_sub" hint="输入订单号/客户名称/商品进行查找" v-model="bindingParms.keyword"
                      @search="handleSearchbar"/>
        <div slot="body_list">
            <div class="lj-card-item" v-for="item in allData" @click="handleCellClick(item)">
                <div>
                    <mu-row>
                        <mu-col span="3" class="lj-card-secondary-title">订单号码：</mu-col>
                        <mu-col span="7" class="lj-card-secondary-content">{{item.taskcode}}</mu-col>
                        <mu-col span="2">
                            <lj-status-badge :value="item.statusstr"/>
                        </mu-col>
                        <mu-col span="3" class="lj-card-secondary-title">业务员：</mu-col>
                        <mu-col span="9" class="lj-card-secondary-content">{{item.assign_emp}}</mu-col>
                        <mu-col span="3" class="lj-card-secondary-title">订货日期：</mu-col>
                        <mu-col span="3" class="lj-card-secondary-content">{{item.taskdate | dateFilter}}</mu-col>
                        <mu-col span="3" class="lj-card-secondary-title">交货日期：</mu-col>
                        <mu-col span="3" class="lj-card-secondary-content">{{item.requiredate | dateFilter}}</mu-col>
                    </mu-row>
                    <div style="display:flex;" class="lj-card-tag-text lj-card-summary-light-text">
                        <div class="lj-card-tag">
                            <i class="iconfont icon-chart-line lj-card-summary-icon"></i>
                            优先级:{{item.levelStr}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </lj-win-index-common>
</template>

<script>
    import LjWinIndexCommon from "components/lj-win-index-common";
    import LjSearchbar from "components/lj-searchbar";
    import LjStatusBadge from "components/lj-status-badge";

    export default {
        components: {
            LjStatusBadge,
            LjSearchbar,
            LjWinIndexCommon
        },
        data() {
            return {
                bindingParms: {keyword: ""},
                allData: [],
                userFunids: [],
                queryHardParms: {},
                queryFields: [
                    {title: "下单日期/要求交期开始", property: "begindate", type: "date"},
                    {title: "下单日期/要求交期结束", property: "enddate", type: "date"}
                ]
            }
        },
        created() {
            this.userFunids = $lj.getStorage('user').rsltFunids;
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.winMode = pageParam.winMode;
                this.queryHardParms = pageParam.queryParams || {};
            }
        },
        methods: {
            handleDataReset(response) {
                this.allData = [];
                if (response.saletaskList && response.saletaskList.length > 0) {
                    this.addList(response.saletaskList);
                }
            },
            handleDataLoaded(response) {
                let moreSaletasks = response.saletaskList;
                if (moreSaletasks.length > 0) {
                    this.addList(moreSaletasks);
                    return true;
                }
                return false;
            },
            addList(list) {
                this.allData = this.allData.concat(list);
            },
            handleSearchbar(text) {
                this.$refs.baseWin.refresh(Object.assign({keyword: text}, this.queryHardParms));
            },
            handleCellClick(mainObject) {
                if (this.winMode === "single-select") {
                    $lj.sendEvent("saletask_select", mainObject);
                    $lj.closeWin();
                } else {
                    $lj.openWin("saletask-fore-detail", {mainObject: mainObject});
                }
            }
        },
        computed: {
            title() {
                if (this.winMode === 'single-select') {
                    return "销售预测单选择";
                } else {
                    return "销售预测单";
                }
            }
        }
    }
</script>