xuruiqian
2025-02-25 e85ab165147c37b571ea67ce6f6ae9ae55a96070
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
    <view>
        <view v-if="product">
            <up-row justify="space-between">
                <up-col span="12">
                    <up-image :show-loading="true" :src="product.image" mode="widthFix"/>
                    <up-text type="info" :text="`${product.name}`"
                             customStyle="margin-top: 2px;"/>
                    <up-text type="price" :text="`¥${product.sellprice}`"
                             customStyle="margin-top: 2px;color: #8B0000;"/>
                </up-col>
            </up-row>
            <up-row justify="space-between">
                <up-col span="12">
                    <view v-for="(attribute, i) in attributes">
                        <view>
                            <span> {{attribute.name}}</span>
                        </view>
                        <view v-for="(value, j) in attribute.values">
                            <view>
                                <span> {{value.value}}</span>
                            </view>
                        </view>
                    </view>
                </up-col>
            </up-row>
        </view>
        <view v-else>
            <u-empty mode="car" icon="http://cdn.uviewui.com/uview/empty/car.png"/>
        </view>
    </view>
</template>
 
<script>
    import {ref, reactive, toRefs, onMounted, getCurrentInstance} from "vue";
    import {useBasicInfoStore} from "../../store/basicInfo"
    import {GetProductDetailByMasterId} from '../../apis/api';
    import {onLoad} from "@dcloudio/uni-app";
 
    export default {
        setup() {
            const userStore = useBasicInfoStore()
            const {proxy} = getCurrentInstance();
            const state = reactive({
                product: null,
                attributes: [],
            })
 
            onLoad((options) => {
                const dataStr = decodeURIComponent(options.data);
                const params = JSON.parse(dataStr);
 
                console.log(params); // { id: 1, name: 'Test' }
            })
 
            onMounted(() => {
                Init();
                loadData();
            });
 
            const Init = () => {
                console.log(state.product);
            }
 
            const loadData = () => {
                state.product = {};
                state.attributes = [];
 
                GetProductDetailByMasterId(userStore.product.id).then(resp => {
                    if (resp.data) {
                        state.product = resp.data;
 
                        if (state.product) {
                            state.attributes = state.product.keys;
                        }
                    }
                }).catch(err => {
                    console.error(err);
                });
            }
 
            return {...toRefs(state), userStore, loadData}
        }
    }
</script>
 
<style scoped lang="scss">
    .swiper {
        width: 100%;
        overflow: auto;
    }
</style>