<template>
    <lj-win-index-common-list
        :title="title"
        api-name="GetQuoteHistory"
        :data-reset-callback="handleDataReset"
        :data-loaded-callback="handleDataLoaded"
        :query-fields="queryFields"
        :queryHardParms="queryHardParms"
        ifShowSearchbar
        hint="编码/品名/规格/客户编号/客户名称"
        :searchText="keyword"
        v-on:update:searchText="emitChangeKeyword"
        @scan-click="handleSearchScan"
        :query-quick="queryQuick"
        :search-actions="searchActions"
        ref="baseWin">
        <!-- <template slot="header_right">
            <mu-button icon @click="opensheet">
                <i class="iconfont icon-down"></i>
            </mu-button>
            <popup v-model="ifch" position="top"
                style="border-bottom-left-radius: 15px;border-bottom-right-radius: 15px;">
                <div class="topbar">
                    <div class="topbar_left" onclick="$lj.closeWin();">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-left"></use>
                        </svg>
                    </div>
                    <div class="topbar_middle" @click="ifch = false">
                        {{title}}
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-up"></use>
                        </svg>
                    </div>
                </div>
                <div class="quote_mask">
                    <checker v-model="mtrltype" default-item-class="demo4-item"
                        selected-item-class="demo4-item-selected">
                        <p style="padding: 0px 5px 0px 5px;color:#888;">产品分类</p>
                        <checker-item value="''"
                            @on-item-click="onItemClick('')">全部</checker-item>
                        <checker-item v-for="typeitem in mtrltypeList" :value="typeitem"
                            @on-item-click="onItemClick(typeitem)" v-if="typeitem !=''">{{typeitem}}</checker-item>
                        <p style="padding: 0px 5px 0px 5px;color:#888;">畅销类型</p>
                        <checker-item v-for="saletypeitem in saletypeList" :value="saletypeitem"
                            @on-item-click="onItemClick(saletypeitem)" v-if="saletypeitem !=''">{{saletypeitem}}</checker-item>
                    </checker>
                </div>
            </popup>
        </template>
        <lj-searchbar slot="header_sub" hint="输入编码/品名/规格/客户编号/客户名称进行查找" @search="handleSearchbar" style="width: 100%" /> -->

        <div slot="body_list">
            <mu-list class="lj-group">
                <template v-for="item in allData">
                    <quote-history-item :item="item" @ifclickbtn="btnClick" @click.native="handleCellClick(item)">
                    </quote-history-item>
                </template>
            </mu-list>
        </div>
    </lj-win-index-common-list>
</template>


<script>
    import LjWinIndexCommonList from "components/lj-win-index-common-list";
    import QuoteHistoryItem from './quote-history-item';
    export default {
        components: {
            LjWinIndexCommonList,
            QuoteHistoryItem
        },
        data() {
            return {
                cusid: 0,
                allData: [],
                mtrlPros: [],
                typename: "",
                ifch: false,
                ClickBtn: false,
                title: "报价历史",
                // mtrltypeList: [], //'经理椅','职员椅','会议椅','休闲椅','电竞椅','办公网椅','办公布椅'
                // saletypeList:[],
                // mtrltype: "",
                queryHardParms: {
                    mtrlorigin: 0
                },
                queryFields: [
                    {
                        title: "产品编码",
                        property: "mtrlcode",
                        initValue: "",
                        group: "产品"
                    },
                    {
                        title: "产品名称",
                        property: "mtrlname",
                        initValue: "",
                        group: "产品"
                    },
                    {
                        title: "规格",
                        property: "mtrlmode",
                        initValue: "",
                        group: "产品"
                    },
                    {
                        title: "客户编号",
                        property: "cuscode",
                        initValue: "",
                        group: "客户"
                    },
                    {
                        title: "客户名称",
                        property: "cusname",
                        initValue: "",
                        group: "客户"
                    },
                    {
                        title: "状态",
                        property: "isuse",
                        type: 'radio2',
                        initValue: -1,
                        selectOptions: {
                            options: [
                                {
                                    isuse: 1,
                                    dscrp: "有效"
                                },
                                {
                                    isuse: 0,
                                    dscrp: "无效"
                                }
                            ], 
                            valueMap: { text: 'dscrp', value: 'isuse'},
                        },
                        group: "状态"
                    },
                ],
                queryQuick: [
                    {
                        title: "产品分类",
                        property: "mtrltype",
                        type: 'radioFree',
                        initValue: "",
                        selectOptions: {}
                    },
                    {
                        title: "畅销类型",
                        property: "saletype",
                        type: 'radioFree',
                        initValue: "",
                        selectOptions: {}
                    },
                    {
                        title: "产品系列",
                        property: "band",
                        type: 'radioFree',
                        initValue: "",
                        selectOptions: {}
                    },
                ],
                searchActions: [
                    { 
                        title: '全部',
                        property: 'keyword'
                    },
                    { 
                        title: '产品编码',
                        property: 'mtrlcode' 
                    },
                    { 
                        title: '产品名称',
                        property: 'mtrlname'
                    },
                    { 
                        title: '规格',
                        property: 'mtrlmode'
                    },
                    { 
                        title: '客户编号',
                        property: 'cuscode'
                    },
                    { 
                        title: '客户名称',
                        property: 'cusname'
                    },
                ],
                keyword: ''
            }
        },
        created() {
            var mtrlObject = $lj.getPageParam();
            if (mtrlObject.cusid) {
                this.cusid = mtrlObject.cusid;
            }
            this.getType();
        },
        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;
            },
            getType() {
                let self = this;
                let userInfo = $lj.getStorage('userInfo');
                if (userInfo.mtrltypeList) {
                    for (let i = 0; i < self.queryQuick.length; i++) {
                        if (self.queryQuick[i].property == 'mtrltype') {
                            self.$set(self.queryQuick[i].selectOptions, 'options', userInfo.mtrltypeList);
                            break;
                        }
                    }
                }
                if (userInfo.saletypeList) {
                    for (let i = 0; i < self.queryQuick.length; i++) {
                        if (self.queryQuick[i].property == 'saletype') {
                            self.$set(self.queryQuick[i].selectOptions, 'options', userInfo.saletypeList);
                            break;
                        }
                    }
                }
                if (userInfo.bandList) {
                    for (let i = 0; i < self.queryQuick.length; i++) {
                        if (self.queryQuick[i].property == 'band') {
                            self.$set(self.queryQuick[i].selectOptions, 'options', userInfo.bandList);
                            break;
                        }
                    }
                }
            },
            handleDataReset(response) {
                this.allData = [];
                this.addList(response.quoteHistoryList);
                this.typename = response.typename;
            },
            handleDataLoaded(response) {
                let moreItems = response.quoteHistoryList;
                if (moreItems.length > 0) {
                    this.addList(moreItems);
                    return true;
                }
                return false;
            },
            // handleSearchbar(text) {
            //     this.allData = [];
            //     this.$refs.baseWin.refresh(Object.assign({
            //         keyword: text,
            //         cusid: this.cusid,
            //         isuse: 1,
            //     }, this.queryHardParms));
            // },
            addList(list) {
                this.allData = this.allData.concat(list);
            },
            // onItemClick(value) {
            //     this.allData = [];
            //     this.ifch = false;
            //     if (value == '') {
            //         this.title = '报价历史'
            //     } else {
            //         this.title = value;
            //     }
            //     this.$refs.baseWin.refresh(Object.assign({
            //         mtrltype: value,
            //         cusid: this.cusid,
            //         isuse: 1,
            //     }, this.queryHardParms));
            // },
            opensheet() {
                this.ifch = true;
            },
            btnClick(value) {
                this.ClickBtn = value;
            },
            handleCellClick(item) {
                let self = this;
                if (self.ClickBtn) {
                    self.ClickBtn = false;
                    $lj.openWin("mtrl-configuration", {
                        mainObject: item,
                        openMode: 2 //0-默认打开，为编辑状态 1-非编辑状态 2-再次报价
                    });
                } else {
                    self.ClickBtn = false;
                    let other = {
                        Tname: item.trade,
                        otheramt: item.otheramt,
                        moneyname: item.moneyname,
                        moneycode: item.code,
                        tax: item.taxrate,
                        price: item.sumprice,
                        qty: item.qty,
                        validityday: item.validityday,
                        openMode: 1,
                        woodcode: item.woodcode,
                        statusname: self.typename,
                        status: item.status,
                        dscrp: item.mxDscrp,
                        outrepcode:item.outrepcode
                    }
                    $lj.postLJRequest("GetMtrlPros", {
                        token: $lj.getStorage("token"),
                        mtrlid: item.mtrlid,
                    }, function (ret) {
                        self.ifClickBtn = false;
                        $lj.openWin("quote-final", {
                            mainObject: item,
                            mtrlPros: ret.mtrlProsList,
                            other: other
                        });
                    })
                }
                // $lj.openWin("mtrl-configuration", {
                //     mainObject: mainobject,
                //     openMode:1 //0-默认打开，为编辑状态 1-报价历史 2-再次报价
                // });
            }
        },
    }
</script>

<style>
    .topbar {
        min-height: 44px;
        border-bottom: 1px solid #e5e5e5;
        background: #fff;
        position: fixed;
        width: 100%;
        z-index: 9999;
        display: flex;
        font-size: 18px;
        align-items: center;
        margin-top: 25px;
    }

    .topbar_left {
        flex: 0 0 20px;
        margin-left: 10px;
    }

    .topbar_middle {
        text-align: center;
        flex: 0 0 89%;
    }

    .topbar_right {
        flex: 0 0 20px;
        position: absolute;
        right: 10px;
    }

    .quote_mask {
        margin-top: 60px;
        padding: 10px 10px 30px 10px;
    }

    .demo4-item {
        background-color: #ddd;
        color: #222;
        font-size: 14px;
        padding: 5px 10px;
        margin: 5px;
        line-height: 18px;
        border-radius: 15px;
    }

    .demo4-item-selected {
        background-color: #FF3B3B;
        color: #fff;
    }
</style>