<template>
    <page ref="pageRef" :nav="false">

        <view class="pagae-nav" :style="{ paddingTop: statusBarHeight + 'px' }">
            <view
                class="flex-align relative flex-align-center"
                style="height: 72rpx; padding-left: 14px"
            >
                <image :src="resource.sell_title" style="width: 300rpx; height: 42rpx" />
                <image :src="resource.icon_back" class="back translateY" @click.stop="back" />
            </view>
        </view>
        <view style="height: 72rpx"></view>
        <view class="flex-align" style="padding: 11px 14px 10px 14px">
            <view class="flex1 input-wrapper flex-align paddingL10">
                <input
                    v-model.trim="searchVal"
                    placeholder="输入搜索内容"
                    class="color-white flex1"
                />
                <view class="search-wrapper flex-align-center" @click="search">
                    <image :src="resource.weal_search" style="width: 32rpx; height: 32rpx" />
                </view>
            </view>
            <!-- <image :src="resource.sell_btn_record" style="width: 176rpx;height:84rpx" @click="showRecord" /> -->
        </view>
        <view class="flex-align-between marginX26 paddingT5 paddingB5">
            <view class="flex-column-align-center" @click="showRecord()">
                <image :src="resource.sell_fun_1" style="width: 36rpx; height: 36rpx" />
                <text class="font4 color-white paddingT10">我发布的</text>
            </view>
            <view class="flex-column-align-center" @click="showRecord(1)">
                <image :src="resource.sell_fun_2" style="width: 36rpx; height: 36rpx" />
                <text class="font4 color-white paddingT10">我出价的</text>
            </view>
            <view class="flex-column-align-center" @click="showRecord(2)">
                <image :src="resource.sell_fun_3" style="width: 36rpx; height: 36rpx" />
                <text class="font4 color-white paddingT10">我卖出的</text>
            </view>
            <view class="flex-column-align-center" @click="showRecord(3)">
                <image :src="resource.sell_fun_4" style="width: 36rpx; height: 36rpx" />
                <text class="font4 color-white paddingT10">我买到的</text>
            </view>
        </view>
        <!-- <tabbar2 custom-class="marginX14" :tabs="tabs" @change="clickTab" /> -->
        <view class="flex-wrap" style="margin: 12px 8px">
            <view style="padding: 0 3px 10px" v-for="item in tableData" :key="item.id">
                <view
                    class="cell relative"
                    :style="{ width: size.width + 'px' }"
                    @click="showDetail(item)"
                >
                    <image :src="resource.sell_bg_cell" mode="scaleToFill" class="bg" />
                    <image
                        :src="item.cover"
                        :style="{ width: '100%', height: size.imageHeight + 'px' }"
                    />
                    <view style="padding: 8px">
                        <view class="font2 line-ellipsis" style="color: #ccc">{{ item.name }}</view>
                        <view class="color-white paddingT4">
                            <text class="font0">¥</text>
                            <text class="font4 bold">{{ item.price }}</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <empty v-if="isEmpty" :top="180" />
    </page>
</template>

<script>
import resource from '@/utils/resource'
import tabbar2 from '@/components/tabbar2'
import empty from '@/components/empty'
import pageMixin from '@/mixin/page'

const Tabs = [
    { title: '全部', value: '' },
    { title: '0～9.9', priceMax: '9.9', value: '0～9.9' },
    { title: '9.9～19.9', priceMin: '10', priceMax: '19.9', value: '9.9～19.9' },
    { title: '19.9～29.9', priceMin: '20', priceMax: '29.9', value: '19.9～29.9' },
    { title: '大于29.9', priceMin: '30', value: '大于29.9' }
]

export default {
    mixins: [pageMixin],
    components: { tabbar2, empty },
    data() {
        return {
            searchVal: '',
            resource,
            tabs: Tabs,
            tab: Tabs[0],
            isRefreshClear: false
        }
    },
    computed: {
        statusBarHeight() {
            if (this.$store.state.systemInfo) {
                return this.$store.state.systemInfo.statusBarHeight
            }
            return 20
        },
        size() {
            let width = Math.floor((this.$store.state.systemInfo.screenWidth - 36) / 3)
            return { width, imageHeight: (141 / 112) * width }
        }
    },
    onLoad() {
        this.$event.on(this.$event.key.SELL_REFRESH, this.refresh)
        this.$event.on(this.$event.key.APP_SHOW, this.refresh)
    },
    onUnload() {
        this.$event.off(this.$event.key.SELL_REFRESH)
        this.$event.off(this.$event.key.APP_SHOW)
    },
    onTabItemTap() {
        this.refresh()
    },
    mounted() {
        this.refresh()
    },
    onPullDownRefresh() {
        this.refresh()
    },
    onReachBottom() {
        this.loadMore()
    },
    onShareAppMessage(res) {
        return {
            title: '燚火漫域 次元聚集地，潮玩新势力'
        }
    },
    onShareTimeline() {
        return {
            title: '燚火漫域 次元聚集地，潮玩新势力'
        }
    },
    methods: {
        back() {
            this.$router.back()
        },
        search() {
            this.refresh(true)
        },
        clickTab(item) {
            this.tab = item
            this.refresh(true)
        },
        async loadData(loading) {
            const res = await this.$service.sell.list(
                this.pageNum,
                this.pageSize,
                this.tab.priceMin,
                this.tab.priceMax,
                this.searchVal,
                loading
            )
            return res
        },
        showRecord(active = 0) {
            if (!this.$common.checkLogin()) return
            this.$router.push('sell_record', { active })
        },
        async showDetail(item) {
            if (!this.$common.checkLogin()) return
            this.$router.push('sell_detail', { id: item.id })
        }
    }
}
</script>

<style lang="scss">

</style>
<style lang="scss" scoped>
.bg {
    position: fixed;
    z-index: -1;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
}
.pagae-nav {
    height: 72rpx;
    .back {
        position: absolute;
        left: 28rpx;
        width: 48rpx;
        height: 48rpx;
        z-index: 1800;
    }
}
.input-wrapper {
    height: 68rpx;
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0px 0px 4px 2px rgba(147, 67, 255, 0.3);
    border-radius: 4px;
    border: 1px solid rgba(174, 231, 255, 0.5);
    .search-wrapper {
        height: 100%;
        width: 68rpx;
        box-shadow: inset 1px 0px 0px 0px rgba(174, 231, 255, 0.5);
    }
}
.cell {
    background: rgba($color: #000000, $alpha: 0.5);
    box-shadow: 0px 0px 3px 0px rgba(167, 110, 244, 0.5);
    border-radius: 6px;
    border: 1px solid;
    overflow: hidden;
    .bg {
        position: absolute;
        left: 0;
        width: 100%;
        top: 0;
        height: 100%;
        z-index: -1;
    }
}
</style>