<template>
    <view>
        <u-tabs lineColor="#C30D23" :activeStyle="{ color: '#C30D23', fontWeight: 'bold' }" :list="tabs"
            @click="changeCurrent" :current="current" />
        <view style="padding: 10px;background-color: #fff;">
            <My_search @onSearch="onSearch" />
        </view>
        <view style="height: 10px;" />
        <My_listbox ref="List" @getlist="getList">
            <img-list v-if="tabs[current].name == '效果图'" ref="效果图" :list="list" @addReadcount="addReadcount" />
            <design-list v-if="tabs[current].name == '设计实景'" ref="设计实景" :list="list" @toDetail="updateDesign" />
            <view v-else-if="tabs[current].name == '单品'" style="padding: 0 10px;">
                <product ref="单品" :list="list" />
            </view>
            <courseware v-else-if="tabs[current].name == '课件'" ref="课件" :list="list" />
            <commodity-list v-else-if="tabs[current].name == '商品'" ref="商品" :list="list" />
        </My_listbox>
    </view>
</template>

<script>
import imgList from '../../pages/index/index/casePages/modules/imgList.vue';
import designList from '../../components/designList.vue';
import product from "../../components/collectLists/product.vue";
import courseware from "../../components/collectLists/courseware.vue";
import commodityList from "../../pages/index/index/modules/commodityList.vue";

export default {
    components: { commodityList, imgList, product, courseware, designList },
    data() {
        return {
            current: 0,
            tabs: [{
                name: '效果图',
                id: "20240415164402"
            }, {
                name: '单品',
                id: "20240418141302"
            }, {
                name: '设计实景',
                id: "20240417144702"
            }, {
                name: '课件',
                id: "20240506100502"
            }, {
                name: '商品',
                id: '20240430094102'
            }],
            "content": {
                nocache: true,
                iscollect: 1,
                "where": {
                    iscollect: 1,
                    "condition": ""
                }
            },
            showCount: 0,
            list: []
        }
    },
    onLoad() {
        uni.setNavigationBarTitle({
            title: '我的收藏'
        });
        this.getList(true)
    },
    onShow() {
        if (this.showCount) this.updateList();
        this.showCount += 1;
    },
    methods: {
        getList(init = false) {
            let current = this.tabs[this.current];
            if (this.paging(this.content, init)) return;
            this.$Http.basic({
                "id": current.id,
                content: this.content
            }).then(res => {
                this.$refs.List.RefreshToComplete()
                console.log(`我收藏的${current.name}列表`, this.list)
                console.log(current.id)
                if (this.cutoff(res.msg)) return;
                res.data = this.$refs[current.name].handleList(res.data)
                this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                this.content = this.$refs.List.paging(this.content, res)
            })
        },
        updateList() {
            let current = this.tabs[this.current];
            if (this.content.pageNumber && this.content.pageNumber >= 2) {
                let content = this.paging(this.content, true, true)
                this.$Http.basic({
                    "id": current.id,
                    content
                }).then(res => {
                    console.log(`更新我收藏的${current.name}列表`, res)
                    if (this.cutoff(res.msg)) return;
                    res.data = this.$refs[current.name].handleList(res.data)
                    this.list = res.data;
                    this.$refs.List.paging(content, res, true)
                })
            }
        },
        changeCurrent({ index }) {
            this.current = index;
            this.list = [];
            this.getList(true)
        },
        onSearch(condition) {
            this.content.where.condition = condition;
            this.getList(true)
        },
        addReadcount(index) {
            this.$set(this.list[index], 'readcount', this.list[index].readcount - 0 + 1)
        },
        updateDesign(index, type = 1) {
            let item = this.list[index]
            if (type == 1) {
                uni.navigateTo({
                    url: `/packageA/fullView/detail?id=${item.sat_sharematerialid}`,
                });
            } else {
                uni.redirectTo({
                    url: `/packageA/fullView/detail?id=${item.sat_sharematerialid}`,
                });
            }
            this.$Http.setCount = function (detail) {
                item.collectcount = detail.collectcount;
                item.commentcount = detail.commentcount;
                item.likecount = detail.likecount;
                item.islike = detail.islike;
                item.iscollect = detail.iscollect;
                this.$set(this.list, index, item)
            }.bind(this)
        },
    },
}
</script>

<style></style>