feat(custom): build
This commit is contained in:
152
src/components/MerList.vue
Normal file
152
src/components/MerList.vue
Normal file
@@ -0,0 +1,152 @@
|
||||
<template>
|
||||
<view class="goodBox">
|
||||
<view
|
||||
class="good"
|
||||
v-for="item in merdata"
|
||||
:key="item.ID"
|
||||
@click.stop="toMerDetails(item)"
|
||||
>
|
||||
<image :src="item.head_photo" />
|
||||
<view class="good-text-box">
|
||||
<text class="good-text">{{ item.name }}</text>
|
||||
<text style="color: #999"
|
||||
>距离我{{
|
||||
calculateDistance(
|
||||
userLocalNum.t,
|
||||
userLocalNum.l,
|
||||
Number(item.lat),
|
||||
Number(item.lon)
|
||||
)
|
||||
}}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import Taro from "@tarojs/taro";
|
||||
import { calculateDistance } from "@/utils";
|
||||
import { bindParent } from "@/api/user";
|
||||
import { getMerList } from "@/api/goods";
|
||||
|
||||
const props = defineProps({
|
||||
classId: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
Taro.useDidShow(async () => {
|
||||
await get_mer_list();
|
||||
if (Taro.getStorageSync("token") && Taro.getStorageSync("bind_id")) {
|
||||
try {
|
||||
const res = await bindParent({
|
||||
uid: Taro.getStorageSync("bind_id"),
|
||||
});
|
||||
Taro.showToast({
|
||||
title: res.msg,
|
||||
});
|
||||
Taro.removeStorageSync("bind_id");
|
||||
} catch (error) {
|
||||
Taro.removeStorageSync("bind_id");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
interface MerData {
|
||||
ID: number;
|
||||
name: string;
|
||||
head_photo: string;
|
||||
lat: string;
|
||||
lon: string;
|
||||
}
|
||||
|
||||
const merdata = ref<MerData[]>([]);
|
||||
|
||||
const userLocalNum = ref({
|
||||
l: 0,
|
||||
t: 0,
|
||||
});
|
||||
|
||||
const get_mer_list = async () => {
|
||||
Taro.getLocation({
|
||||
type: "wgs84",
|
||||
success: (res) => {
|
||||
userLocalNum.value.l = res.longitude;
|
||||
userLocalNum.value.t = res.latitude;
|
||||
},
|
||||
});
|
||||
|
||||
const res = await getMerList({
|
||||
PageNum: 1,
|
||||
PageSize: 10,
|
||||
class_id: props.classId,
|
||||
});
|
||||
merdata.value = res.data.data;
|
||||
};
|
||||
|
||||
const toMerDetails = (item: any) => {
|
||||
Taro.setStorageSync("mer_info", item);
|
||||
Taro.navigateTo({
|
||||
url: `/pages/mer/mer_detail/index`,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.goodBox {
|
||||
display: flex;
|
||||
padding: 20px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
|
||||
.good {
|
||||
width: 340px;
|
||||
background-color: #fff;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 10px;
|
||||
|
||||
image {
|
||||
width: 100%;
|
||||
height: 250px;
|
||||
border-top-right-radius: 10px;
|
||||
border-top-left-radius: 10px;
|
||||
}
|
||||
|
||||
.good-text-box {
|
||||
padding: 10px;
|
||||
|
||||
.good-text {
|
||||
flex-shrink: 0;
|
||||
font-size: 28px;
|
||||
color: #333;
|
||||
font-weight: 400;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 1;
|
||||
overflow: hidden;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.good-price-box {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 10px;
|
||||
|
||||
.good-text-price {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
color: #ff0000;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user