Browse Source

feat: 添加商店位置信息和打开位置功能,优化材料详情页面

EvilDragon 3 months ago
parent
commit
948013ffe5

+ 6 - 3
packages/app/src/core/libs/models.ts

@@ -47,6 +47,8 @@ export interface MaterialDealer {
   points: number
   clockPoints: string
   orderCount: number
+  pointsExchangeRate: number
+  shopList: ShopList[]
 }
 export interface ShopList {
   id: number
@@ -55,6 +57,10 @@ export interface ShopList {
   shopName: string
   shopContactPerson: string
   shopContactPhone: string
+
+  longitude: number
+  latitude: number
+  radius: number
 }
 export interface MaterialsList {
   id: number
@@ -103,9 +109,6 @@ export interface ProductDolist {
   productTitleName: string
   productImgUrl: string
 }
-export interface MaterialDealerDetail extends MaterialDealer {
-  shopList: ShopList[]
-}
 export interface MaterialDealerHomePage {
   materialsId: any
   bannerUrl: string

+ 2 - 3
packages/app/src/core/libs/requests.ts

@@ -5,7 +5,6 @@ import {
   Content,
   DictType,
   MaterialDealer,
-  MaterialDealerDetail,
   MaterialDealerHomePage,
   MaterialDealerRes,
   Comment,
@@ -338,13 +337,13 @@ export const getMaterials = (query = {}) =>
 export const getAppMaterials = () =>
   httpGet<MaterialDealerRes[]>('/app-api/member/materials/appMaterialsList')
 export const getAppMaterial = (id: number) =>
-  httpGet<MaterialDealerDetail>('/app-api/member/materials/queryHomePage', { materialsId: id })
+  httpGet<MaterialDealer>('/app-api/member/materials/queryHomePage', { materialsId: id })
 export const getMaterialHomePage = (id: number) =>
   httpGet<Partial<MaterialDealerHomePage>>('/app-api/member/materials/queryHomePage', {
     materialsId: id,
   })
 export const getMaterialDetail = (query: { id: string }) =>
-  httpGet<MaterialDealerDetail>('/app-api/member/materials/getDetail', query)
+  httpGet<MaterialDealer>('/app-api/member/materials/getDetail', query)
 export const createMaterialsReferrer = (data) =>
   httpPost('/app-api/member/materials-referrer/create', data)
 export const getContents = (query: {

+ 14 - 0
packages/app/src/core/utils/common.ts

@@ -2,6 +2,20 @@ import dayjs from 'dayjs'
 export const handleCall = (phone: string) => {
   uni.makePhoneCall({ phoneNumber: phone })
 }
+/**
+ * 打开位置
+ */
+export const openLocation = (options: Omit<UniNamespace.OpenLocationOptions, 'success'>) => {
+  uni.openLocation({
+    ...options,
+    success: function () {
+      console.log('success')
+    },
+    fail: (fail) => {
+      console.log(fail)
+    },
+  })
+}
 export const isImageOrVideo = (url) => {
   const ext = url.split('.').pop().toLowerCase()
   if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].includes(ext)) {

+ 15 - 3
packages/app/src/pages/material/detail/index.vue

@@ -8,7 +8,7 @@ import { getMaterialDetail, getByDictType, getMaterialHomePage } from '../../../
 import NavbarEvo from '@/components/navbar-evo.vue'
 import { DictType } from '../../../core/libs/models'
 import { phone } from '../../../core/libs/svgs'
-import { handleCall } from '../../../core/utils/common'
+import { handleCall, openLocation } from '../../../core/utils/common'
 import router from '@designer-hub/assets/src/assets/svgs/router'
 
 const id = ref()
@@ -135,7 +135,7 @@ onLoad(async (query: { id: number }) => {
             </div>
           </div>
           <template
-            v-for="({ shopAddr, shopName, shopContactPhone }, i) in data?.shopList"
+            v-for="({ shopAddr, shopName, shopContactPhone, ...shop }, i) in data?.shopList"
             :key="i"
           >
             <div class="bg-neutral-50 rounded-2.5 p-3.5 flex items-center">
@@ -160,7 +160,19 @@ onLoad(async (query: { id: number }) => {
               >
                 <wd-img width="28" height="28" :src="phone"></wd-img>
               </wd-button>
-              <wd-button type="text" size="small" custom-class=" bg-[#f2f2f2]! p-0! ml-4">
+              <wd-button
+                type="text"
+                size="small"
+                custom-class=" bg-[#f2f2f2]! p-0! ml-4"
+                @click="
+                  openLocation({
+                    latitude: shop.latitude,
+                    longitude: shop.longitude,
+                    name: shopName,
+                    address: shopAddr,
+                  })
+                "
+              >
                 <wd-img width="28" height="28" :src="router"></wd-img>
               </wd-button>
             </div>

+ 16 - 27
packages/app/src/pages/material/index.vue

@@ -14,16 +14,13 @@ import Banner from '../home/components/banner.vue'
 import materialDealers from '@designer-hub/assets/src/libs/assets/materialDealers'
 import { useRouter } from '../../core/utils/router'
 import PageHelperEvo from '@/components/page-helper-evo.vue'
+import { handleCall, openLocation } from '../../core/utils/common'
 
 const router = useRouter()
 const { data: materialDealerData, run: setMaterialDealerData } = useRequest(
   () => getAppMaterials(),
   { initialData: [] },
 )
-const { data: materials, run: setMaterials } = useRequest(() => getMaterials(), {
-  initialData: { list: [] },
-})
-const { data, run } = useRequest(() => getByDictType(DictType.memberMaterialsBrandLevel))
 const { data: materialOperationTypes, run: setMaterialOperationTypes } = useRequest(
   () => getByDictType(DictType.memberMaterialsOperationType),
   { initialData: [] },
@@ -37,7 +34,7 @@ const { data: banners, run: setBanners } = useRequest(
   { initialData: [] },
 )
 const dealerPanelState = ref(false)
-const currentDeraler = ref<MaterialsList>()
+const currentDeraler = ref<MaterialDealer>()
 const pieces = ref([
   {
     title: '材料小课堂',
@@ -81,33 +78,16 @@ const toDetail = (id: number) => {
     url: `/pages/material/detail/index?id=${id}`,
   })
 }
-const handleCall = (phone: string) => {
-  uni.makePhoneCall({ phoneNumber: phone })
-}
 function handleClick(e) {
   console.log(e)
 }
 function onChange(e) {
   console.log(e)
 }
-const handleGo = ({ name, address }) => {
-  uni.openLocation({
-    latitude: 34.2593042818515,
-    longitude: 109.01031190070307,
-    address,
-    name,
-    success: function () {
-      console.log('success')
-    },
-    fail: (fail) => {
-      console.log(fail)
-    },
-  })
-}
 onMounted(async () => {
-  await run()
-  // await setMaterialDealerData()
-  await setMaterials()
+  await setMaterialDealerData()
+  console.log(materialDealerData.value)
+
   await Promise.all([setMaterialBrandTypes(), setMaterialOperationTypes(), setBanners()])
   // const reqs = data.value.map((it) =>
   //   getMaterials({ brandLevel: it.value }).then(({ data }) => data),
@@ -250,7 +230,9 @@ onMounted(async () => {
         <div class="bg-neutral-100 rounded-tl-2xl rounded-tr-2xl p-3.5" @click.stop="">
           <div class="flex flex-col">
             <template
-              v-for="({ shopAddr, shopName, shopContactPhone }, i) in currentDeraler?.shopList"
+              v-for="(
+                { shopAddr, shopName, shopContactPhone, ...shop }, i
+              ) in currentDeraler?.shopList"
               :key="i"
             >
               <div class="bg-white rounded-2.5 p-3.5 flex items-center">
@@ -281,7 +263,14 @@ onMounted(async () => {
                   type="text"
                   size="small"
                   custom-class=" bg-[#f2f2f2]! p-0! ml-4"
-                  @click="handleGo({ name: shopName, address: shopAddr })"
+                  @click="
+                    openLocation({
+                      latitude: shop.latitude,
+                      longitude: shop.longitude,
+                      name: shopName,
+                      address: shopAddr,
+                    })
+                  "
                 >
                   <wd-img width="28" height="28" :src="routerIcon"></wd-img>
                 </wd-button>