<template>
    <view>
        <My_listbox ref="List" @getlist="getList">
            <view class="item" @click="changeShop(index)" v-for="(item, index) in list" :key="item.sa_storeid"
                hover-class="navigator-hover">
                <image class="logo" :src="item.cover" />
                <view class="content">
                    <view class="label u-line-1">
                        {{ item.storename }}
                    </view>
                    <view class="icons">
                        <view class="icon-box" hover-class="navigator-hover" @click.stop="goAtOnce(item)">
                            <text class="iconfont icon-dizhi-hui" />
                        </view>
                        <view v-if="item.phonenumber" class="icon-box" hover-class="navigator-hover"
                            @click.stop="callPhone(item.phonenumber)">
                            <text class="iconfont icon-dianhua" />
                        </view>
                    </view>
                </view>
            </view>
        </My_listbox>
    </view>
</template>

<script>
export default {
    data() {
        return {
            "content": {
                "pageNumber": 1,
                "pageSize": 20
            },
            list: [],
        }
    }, onLoad(options) {
        this.getList(true)
        uni.setNavigationBarTitle({
            title: options.title || '历史足迹',
        })
    },
    methods: {
        async getList(init = false) {
            if (this.paging(this.content, init)) return;
            if (init) {
                let s = await this.getLocation();
                this.content.longitude = s.longitude;
                this.content.latitude = s.latitude;
            }
            this.$Http.basic({
                "id": 20240416162002,
                content: this.content
            }).then(res => {
                this.$refs.List.RefreshToComplete()
                console.log("获取历史足迹", res)
                if (this.cutoff(res.msg)) return;
                res.data = res.data.map(v => {
                    v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos[0]) : uni.getStorageSync('site').logo || '';
                    v.distance = v.distance > 1000 ? ((v.distance / 1000).toFixed(2) - 0) + 'km' : ((v.distance).toFixed(2) - 0) + 'm'
                    return v
                })
                this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
                this.content = this.$refs.List.paging(this.content, res)
            })
        },
        goAtOnce(item) {
            uni.openLocation({
                latitude: item.latitude - 0,
                longitude: item.longitude - 0,
                address: item.address,
                name: item.storename,
                success: function () {
                    console.log('success');
                },
                fail: (fail) => {
                    console.log('fail', fail)
                },
            });
        },
        changeShop(index) {
            this.$Http.changeShop && this.$Http.changeShop(this.list[index]);
        }
    },
}
</script>

<style lang="scss">
.item {
    display: flex;
    width: 100vw;
    height: 84px;
    background: #FFFFFF;
    margin-top: 10px;
    padding: 10px;
    box-sizing: border-box;

    .logo {
        width: 64px;
        height: 64px;
        background: #FFFFFF;
        border-radius: 5px;
        border: 1px solid #CCCCCC;
        box-sizing: border-box;
    }

    .content {
        margin-left: 26px;

        .label {
            line-height: 20px;
            font-family: Source Han Sans SC, Source Han Sans SC;
            font-weight: bold;
            font-size: 14px;
            color: #333333;
        }

        .icons {
            display: flex;
            margin-top: 12px;

            .icon-box {
                width: 32px;
                height: 32px;
                background: #F2F2F2;
                text-align: center;
                line-height: 32px;
                margin-right: 10px;
                border-radius: 50%;

                .iconfont {
                    font-size: 14px;
                    color: #666666;
                }
            }
        }
    }
}
</style>