<template>
    <lj-win-index-common-list
        :title="title"
        api-name="GetL1QuoteList"
        :data-reset-callback="handleDataReset"
        :data-loaded-callback="handleDataLoaded"
        :query-hard-parms="queryHardParms"
        :query-fields="queryFields"
        ref="baseWin"
        hint="订单号/相关号"
        :searchText="keyword"
        v-on:update:searchText="emitChangeKeyword"
        :query-quick="queryQuick"
        :search-actions="searchActions"
        @scan-click="handleSearchScan"
        ifShowSearchbar
    >
        <div slot="body_list">
            <quote-record-item :item="item" @click.native="handleCellClick(item)" v-for="item in allData" />
        </div>
    <!-- </lj-win-index-common> -->
    </lj-win-index-common-list>
</template>

<script>
    import LjSearchbar from "components/lj-searchbar";
    import LjStatusBadge from "components/lj-status-badge";
    import LjWinIndexCommonList from "components/lj-win-index-common-list";
    import QuoteRecordItem from './quote-record-item';

    export default {
        components: {
            LjStatusBadge,
            LjSearchbar,
            LjWinIndexCommonList,
            QuoteRecordItem
        },
        data() {
            return {
                bindingParms: {keyword: ""},
                allData: [],
                userFunids: [],
                queryHardParms: {billtype: 1},
                // queryFields: [
                //     {title: "客户", property: "keyword"},
                //     {title: "下单日期/要求交期开始", property: "begindate", type: "date"},
                //     {title: "下单日期/要求交期结束", property: "enddate", type: "date"}
                // ],
                queryFields: [
                    {
                        title: "订单号",
                        property: "quotecode",
                        initValue: "",
                        group: "单据"
                    },
                    {
                        title: "相关号",
                        property: "relcode",
                        initValue: "",
                        group: "单据"
                    }
                ],
                queryQuick: [
                    {
                        title: "全部状态",
                        property: "flag",
                        type: 'radio3',
                        initValue: 0,
                        selectOptions: {
                            options: [
                                {flag: 0, dscrp: "待初审"},
                                {flag: 4, dscrp: "待终审"},
                            ], 
                            valueMap: { text: 'dscrp', value: 'flag'},
                        }
                    },
                ],
                searchActions: [
                    { 
                        title: '全部',
                        property: 'keyword'
                    },
                    { 
                        title: '订单号',
                        property: 'quotecode' 
                    },
                    { 
                        title: '相关号',
                        property: 'relcode'
                    }
                ],
                keyword: ''
            }
        },
        created() {
            this.userFunids = $lj.getStorage('user').rsltFunids;
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.winMode = pageParam.winMode;
                if(pageParam.queryParams){
                    this.queryHardParms =  Object.assign(this.queryHardParms,pageParam.queryParams);   
                }
            }    
        },
        methods: {
            /**搜索栏-扫描 */
            handleSearchScan(searchState) {
                $lj.openScanner((ret) => {
                    setTimeout(() => {
                        let obj = {};
                        obj[searchState] = ret.content.trim();
                        this.$refs.baseWin.handleSearchbar(obj, true);
                    }, 200);
                })
            },
            /**回调绑定值 */
            emitChangeKeyword(val) {
                this.keyword = val;
            },
            handleDataReset(response) {
                this.allData = [];
                if (response.quetoList && response.quetoList.length > 0) {
                    this.addList(response.quetoList);
                }
            },
            handleDataLoaded(response) {
                let moreSaletasks = response.quetoList;
                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) {
                $lj.openWin("quote-mx", {mainObject: mainObject});
            }
        },
        computed: {
            title() {
                return "销售报价记录单";
            }
        }
    }
</script>
<style lang="less">
    .lj-alert-text {
        color: @colorAlert;
    }
</style>