<template>
    <view>
         <u-tabs :scrollable="false" lineColor="#C30D23" :activeStyle="{ color: '#C30D23', fontWeight: 'bold' }"
            :list="tabs" @click="changeCurrent" :current="current" />
        <My_listbox ref="List" @getlist="getList" bottomHeight="70">
            <designList ref="designList" :list="list" @toDetail="toDetail" showStatus />
        </My_listbox>
        <view class="footer">
            <view class="add" hover-class="navigator" @click="toUpload">
                上传
            </view>
        </view>
    </view>
</template>
<script>
import designList from "../../components/designList";
export default {
    components: { designList },
    data() {
        return {
            current: 0,
            tabs: [{
                name: '我的设计',
            }, {
                name: '我的实景',
            }],
            list: [],
            "content": {
                "where": {
                    "condition": "",
                    "type": 4 //4：设计，5：实景
                }
            }
        }
    },
    onLoad(options) {
        uni.setNavigationBarTitle({
            title: '设计实景'
        });
        this.getList(true)
    },
    methods: {
        getList(init = false) {
            if (this.paging(this.content, init)) return;
            this.$Http.basic({
                "id": "2024052413361402",
                content: this.content
            }).then(res => {
                console.log("我的设计实景列表", res)
                this.$refs.List.RefreshToComplete()
                if (this.cutoff(res.msg)) return;
                res.data = this.$refs.designList.handleList(res.data)
                this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                this.content = this.$refs.List.paging(this.content, res)
            })
        },
        changeCurrent({ name }) {
            this.content.where.type = name == '我的设计' ? 4 : 5;
            this.getList(true)
        },
        updateList(data = null) {
            if (this.content.pageNumber && this.content.pageNumber >= 2) {
                let that = this;
                let content = this.paging(this.content, true, true)
                this.$Http.basic({
                    "id": "2024052413361402",
                    content
                }).then(res => {
                    console.log("更新列表", res)
                    if (this.cutoff(res.msg)) return;
                    res.data = res.data.map(v => {
                        v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos.find(s => s.usetype == "sat_sharematerial") || v.attinfos[0]) : uni.getStorageSync("site").logo || ''
                        return v
                    })
                    this.list = res.data;
                    if (data) handle();
                })
                function handle() {
                    uni.showModal({
                        title: '提示',
                        content: '新建成功,是否立即查看',
                        cancelText: '返回列表',
                        confirmText: '查看详情',
                        success: ({ confirm }) => {
                            if (confirm) {
                                let index = that.list.findIndex(v => v.sat_sharematerialid == data.sat_sharematerialid);
                                if (index == -1) {
                                    uni.redirectTo({
                                        url: `/packageA/fullView/detail?id=${data.sat_sharematerialid}`
                                    });
                                    that.$Http.setCount = null;
                                } else {
                                    that.toDetail(index, 2)
                                }
                            } else {
                                uni.navigateBack();
                            }
                        },
                    })
                }
            }
        },
        toDetail(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)
        },
        toUpload() {
            uni.navigateTo({
                url: '/packageA/fullView/upload?pageType=' + (this.content.where.type == 4 ? '设计' : '实景'),
            })
            this.$Http.updateList = this.updateList.bind(this);
        }
    },
}
</script>

<style lang="scss" scoped>
.footer {
    position: fixed;
    bottom: 0;
    width: 100vw;
    height: 65px;
    background: #FFFFFF;
    box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
    box-sizing: border-box;
    padding: 5px 10px;
    display: flex;

    .add {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 45px;
        background: #C30D23;
        border-radius: 5px;
        font-family: PingFang SC, PingFang SC;
        font-size: 14px;
        color: #FFFFFF;
    }
}
</style>