<!--
 * @Author: PoJun
 * @Date: 2023-12-19 14:57:48
 * @LastEditors: XuanJi
 * @LastEditTime: 2024-05-21 10:32:48
 * @Message: 产品列表, 只展示5个
-->
<template>
    <uv-cell-group :border="false" :customStyle="{ padding: '5px 0' }">
        <uv-cell :border="false" :arrow="false" value="全部产品" :isLink="true" url="/subpkg/home/products">
            <uv-text slot="title" text="我的产品分类" :customStyle="{ 'font-weight': 'bold' }"></uv-text>
        </uv-cell>

        <template v-if="productsList && Object.keys(productsList).length !== 0">
            <uv-cell
                v-for="(key, value, index) in productsList"
                :key="index"
                :border="false"
                :label="key"
                :value="value"
            ></uv-cell>
        </template>

        <view v-else class="uv-m-b-50">
            <uv-empty marginTop="30" mode="data" text="暂无数据"></uv-empty>
        </view>
    </uv-cell-group>
</template>

<script>
import { getMyProductsTree } from "@/config/http.js";
export default {
    props: {
        times: {
            type: Number,
            default: 0,
        },
    },
    data() {
        return {
            productsList: null,
        };
    },
    methods: {
        // 获取产品目录, 缓存下后续直接用
        async getList() {
            try {
                const data = await getMyProductsTree();
                this.productsList = data;
            } catch (error) {
                console.log(error);
            }
        },
    },
    watch: {
        times: {
            immediate: true,
            handler: function () {
                console.log("times", this.times);
                this.getList();
            },
        },
    },
};
</script>

<style lang="scss" scoped></style>
