<template>
    <lj-win-index-common-list
        :title="title"
        ref="baseWin"
        dwname="web_mtrl_choose"
        :data-reset-callback="handleDataReset"
        :data-loaded-callback="handleDataLoaded"
        :binding-parms="bindingParms"
        :query-hard-parms="queryHardParms"
        hint="订单号/客户名称/商品/相关号"
        :searchText="keyword"
        v-on:update:searchText="emitChangeKeyword"
        ifShowSearchbar
    >
        <div slot="body_list">
            <!-- <mu-list class="lj-group"> -->
                <template v-for="item in allData">
                    <mtrldef-item :item="item" @click.native="handleCellClick(item)"></mtrldef-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 MtrldefItem from './item';

    export default {
        components: {
            LjSearchbar,
            LjWinIndexCommonList,
            MtrldefItem
        },
        data() {
            return {
                bindingParms: {keyword: ""},
                winMode: "",
                keyword: '',
                allData: [],
                queryHardParms: {},
                queryFields: [],
                springtypeEnum: [],
            }
        },
        created() {
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.winMode = pageParam.winMode;
                this.bindingParms = pageParam.queryParams || {};
            }
        },
        methods: {
            getTypename(ins_type) {
                let ls_typename = "";
                switch (ins_type) {
                    case 0:
                    ls_typename = "钢线";
                    break;
                    case 1:
                    ls_typename = "包边海绵";
                    break;
                    case 2:
                    ls_typename = "无纺布";
                    break;
                    case 3:
                    ls_typename = "布料";
                    break;
                    case 4:
                    ls_typename = "裥绵海绵";
                    break;
                    case 5:
                    ls_typename = "喷胶绵";
                    break;
                    case 6:
                    ls_typename = "垫层";
                    break;
                    case 7:
                    ls_typename = "毡类";
                    break;
                    case 8:
                    ls_typename = "床垫辅料";
                    break;
                    case 9:
                    ls_typename = "边带";
                    break;
                    case 10:
                    ls_typename = "拉手";
                    break;
                    case 11:
                    ls_typename = "刺绣位置";
                    break;
                    case 12:
                    ls_typename = "大侧*上下压线位置";
                    break;
                    case 13:
                    ls_typename = "外袋";
                    break;
                    case 14:
                    ls_typename = "内袋";
                    break;
                    case 16:
                    ls_typename = "PE";
                    break;
                    case 17:
                    ls_typename = "外层PE";
                    break;
                    case 18:
                    ls_typename = "PVC";
                    break;
                    case 19:
                    ls_typename = "卷包包装";
                    break;
                    case 20:
                    ls_typename = "牛皮纸袋";
                    break;
                    case 21:
                    ls_typename = "蓝色PE护角";
                    break;
                    case 22:
                    ls_typename = "无纺布袋";
                    break;
                    case 23:
                    ls_typename = "牛皮袋护角";
                    break;
                    case 24:
                    ls_typename = "编织袋";
                    break;
                    case 31:
                    ls_typename = "拉链";
                    break;
                    case 32:
                    ls_typename = "其他工艺";
                    break;
                    case 29:
                    ls_typename = "顶布";
                    break;
                    case 1201:
                    ls_typename = "顶布裥棉";
                    break;
                    default:
                    ls_typename = "类型未定义";
                    break;
                }
                return ls_typename;
            },
            getType(data) {
                // let _item = data.tableinfo.columns.find(item => item.field == 'springtypeid');
                // if (_item && _item.enum) {
                //     console.log("_deptidItem.enum: ", _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("mtrldef-selection", mainObject);
                    $lj.closeWin();
                } else {
                    $lj.openWin("mtrldef-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 `物料选择(${this.getTypename(this.bindingParms.arg_mtrltype)})`;
                } else {
                    return `物料列表(${this.getTypename(this.bindingParms.arg_mtrltype)})`;
                }
            }
        }
    }
</script>