<template>
    <lj-win-index-common-list
        :title="title"
        api-name="GetL1SaleOutCC"
        :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">
            <div class="lj-card-item marginTop-8px" 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="5" class="lj-card-secondary-content">{{item.taskcode}}</mu-col>
                        <mu-col span="4">
                            <lj-status-badge :value="item.flagstr"/>
                        </mu-col>
                        <mu-col span="3" class="lj-card-secondary-title">客户名称：</mu-col>
                        <mu-col span="9" class="lj-card-secondary-content">{{item.cusname}}</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.viewdate | dateFilter}}</mu-col>
                        <mu-col span="3" class="lj-card-secondary-title" v-if="userFunids.indexOf(122) < 0">金额：</mu-col>
                        <mu-col span="3" class="lj-card-secondary-content lj-sharp-red-text" v-if="userFunids.indexOf(122) < 0">
                            {{item.moneysign}}{{item.takeamt}}
                        </mu-col>
                        <mu-col span="3" class="lj-card-secondary-title" v-if="userFunids.indexOf(122) < 0">发货金额：</mu-col>
                        <mu-col span="3" class="lj-card-secondary-content lj-sharp-red-text" v-if="userFunids.indexOf(122) < 0">
                            {{item.moneysign}}{{item.outamt}}
                        </mu-col>
                    </mu-row>
                    <div class="lj-card-tag-text lj-card-summary-light-text flex">
                        <div class="lj-card-tag">
                            <i class="iconfont icon-grid lj-card-summary-icon"></i>
                            {{item.typename}}
                        </div>
                        <div class="lj-card-tag">
                            <i class="iconfont icon-cash lj-card-summary-icon"></i>
                            {{item.banktypestr}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </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";

    export default {
        components: {
            LjStatusBadge,
            LjSearchbar,
            LjWinIndexCommonList
        },
        data() {
            return {
                bindingParms: {keyword: ""},
                allData: [],
                userFunids: [],
                queryHardParms: {},
                queryFields: [
                    {
                        title: "出运单号",
                        property: "taskcode",
                        initValue: "",
                        group: "单据"
                    },
                    {
                        title: "客户名称",
                        property: "custname",
                        initValue: "",
                        group: "单据"
                    },
                    {
                        title: "业务员名称",
                        property: "assignEmp",
                        initValue: "",
                        group: "单据"
                    },
                    {
                        title: "订单号",
                        property: "relcode",
                        initValue: "",
                        group: "单据"
                    },
                    {
                        title: "开始",
                        property: "begindate",
                        type: "date",
                        group: "下单日期/要求交期"
                    },
                    {
                        title: "结束",
                        property: "enddate",
                        type: "date",
                        group: "下单日期/要求交期"
                    },
                ],
                queryQuick: [
                    {
                        title: "全部状态",
                        property: "flag",
                        type: 'radio3',
                        initValue: -1,
                        selectOptions: {
                            options: [
                                {flag: 0, dscrp: "待初审"},
                                {flag: 1, dscrp: "待出货"},
                                {flag: 4, dscrp: "待终审"},
                                {flag: 5, dscrp: "已出货"}
                            ], 
                            valueMap: { text: 'dscrp', value: 'flag'},
                            // valueMap: ["flag", "dscrp"],·
                        }
                    },
                ],
                searchActions: [
                    { 
                        title: '全部',
                        property: 'keyword'
                    },
                    { 
                        title: '出运单号',
                        property: 'taskcode' 
                    },
                    { 
                        title: '客户',
                        property: 'custname'
                    },
                    { 
                        title: '订单号',
                        property: 'relcode'
                    }
                ],
                keyword: '',
                saleInfo: []
            }
        },
        created() {
            this.userFunids = $lj.getStorage('user').rsltFunids;
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.winMode = pageParam.winMode;
                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.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("sale-out-cc-detail", {mainObject: mainObject});
                }
            }
        },
        computed: {
            title() {
                if (this.winMode === 'single-select') {
                    return "出运单选择";
                } else {
                    return "出运单";
                }
            }
        }
    }
</script>
<style lang="less">
    .lj-alert-text {
        color: @colorAlert;
    }
    .steps-list {
        padding-top: 4px;
        .van-steps__items {
            margin-bottom: 0;
        }
    }
    .marginTop-5px {
        margin-top: 5px;
    }
    .marginTop-8px {
        margin-top: 8px;
    }
</style>