<template>
    <lj-win-index-common-list
        :title="title"
        ref="baseWin"
        dwname="web_spring_define_choose"
        :data-reset-callback="handleDataReset"
        :data-loaded-callback="handleDataLoaded"
        :binding-parms="bindingParms"
        :query-hard-parms="queryHardParms"
        :query-quick="queryQuick"
        :query-fields="queryFields"
        hint="订单号/客户名称/商品/相关号"
        :search-actions="searchActions"
        :ifShowSearchbar="false"
    >
        <!-- :searchText="keyword"
        v-on:update:searchText="emitChangeKeyword" -->
        <div slot="body_list">
            <mu-list class="lj-group">
                <template v-for="item in allData">
                    <spring-item :item="item" @click.native="handleCellClick(item)" :type-enum="springtypeEnum"></spring-item>
                </template>
            </mu-list>
        </div>
    </lj-win-index-common-list>
</template>

<script>
    import LjWinIndexCommonList from "components/lj-win-index-common-list";
    import LjSearchbar from "components/lj-searchbar";
    import SpringItem from './spring-item';

    export default {
        components: {
            LjSearchbar,
            LjWinIndexCommonList,
            SpringItem
        },
        data() {
            return {
                bindingParms: {keyword: ""},
                winMode: "",
                keyword: '',
                allData: [],
                queryHardParms: {},
                queryFields: [
                    { 
                        title: "线径MM",
                        property: "line_diameter" ,
                        initValue: "",
                        group: "弹簧属性"
                    },
                    { 
                        title: "高度CM",
                        property: "arg_height",
                        initValue: "",
                        group: "弹簧属性"
                    },
                    { 
                        title: "口经CM",
                        property: "caliber",
                        initValue: "",
                        group: "弹簧属性"
                    },
                    { 
                        title: "中心直径CM",
                        property: "center_diameter",
                        initValue: "",
                        group: "弹簧属性"
                    },
                    { 
                        title: "圈数",
                        property: "cyclenum",
                        initValue: "",
                        group: "弹簧属性"
                    },
                ],
                queryQuick: [
                    {
                        title: "分类",
                        property: "arg_springtypeid",
                        type: "radio1",
                        selectOptions: {
                            valueMap: { text: "label", value: "value"},
                        }
                    },
                ],
                searchActions: [
                    { 
                        title: "全部",
                        property: "arg_search"
                    },
                    { 
                        title: "线径MM",
                        property: "line_diameter" 
                    },
                    { 
                        title: "高度CM",
                        property: "arg_height"
                    },
                    { 
                        title: "口经CM",
                        property: "caliber"
                    },
                    { 
                        title: "中心直径CM",
                        property: "center_diameter"
                    },
                    { 
                        title: "圈数",
                        property: "cyclenum"
                    },
                ],
                springtypeEnum: []
            }
        },
        created() {
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.winMode = pageParam.winMode;
                this.bindingParms = pageParam.queryParams || {};
            }
        },
        methods: {
            getType(data) {
                let _item = data.tableinfo.columns.find(item => item.field == 'springtypeid');
                console.log("_deptidItem.enum: ", _item.enum)
                if (_item && _item.enum) {
                    for (let i = 0; i < this.queryQuick.length; i++) {
                        if (this.queryQuick[i].property == 'arg_springtypeid') {
                            this.$set(this.queryQuick[i].selectOptions, 'options', _item.enum);
                            this.springtypeEnum = _item.enum;
                            break;
                        }
                    }
                }
            },
            /**回调绑定值 */
            emitChangeKeyword(val) {
                this.keyword = val;
            },
            handleDataReset(response) {
                // alert(JSON.stringify(response.sptList));
                // alert(JSON.stringify(response));
                this.allData.length = 0;
                this.getType(response);
                if (response.datatable && response.datatable.length > 0) {
                    this.addList(response.datatable);
                }
            },
            handleDataLoaded(response) {
                this.getType(response);
                let moreSaletasks = response.datatable;
                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({keyword: text});
            },
            handleCellClick(mainObject) {
                if (this.isSelectMode) {
                    $lj.sendEvent("spring_select", mainObject);
                    $lj.closeWin();
                } else {
                    $lj.openWin("spring-detail", {mainObject: mainObject});
                }
            },
            addcus() {
                $lj.openWin("spt-detail");
            },
            handleQueryFieldClick({property}) {
                if (property === 'cusareaid') {
                    this.$refs.areaChooseDialog.open();
                }
            },
        },
        computed: {
            isSelectMode() {
                return this.winMode === "single-select";
            },
            title() {
                if (this.winMode === 'single-select') {
                    return "弹簧选择";
                } else {
                    return "弹簧";
                }
            }
        }
    }
</script>