Files
EasyCard/frontend_miniprogram/miniprogram/pages/lawyer-list/index.ts
陈子默 9605384edc feat: 搭建微信小程序展示端
- 初始化小程序工程配置与类型声明

- 增加首页、律所、律师列表、详情与历史页面

- 补充公共组件、运行时配置与示例素材
2026-03-20 12:44:31 +08:00

148 lines
3.9 KiB
TypeScript

import { getFirmProfile, listLawyers } from '../../api/open';
import type { Lawyer } from '../../types/card';
const ALL_OFFICES = '所有办公机构';
const ALL_AREAS = '全部专业领域';
let searchDebounceTimer: number | null = null;
Page({
data: {
firmName: '',
firmAddress: '',
firmLatitude: 0,
firmLongitude: 0,
keyword: '',
selectedOffice: ALL_OFFICES,
selectedArea: ALL_AREAS,
officeOptions: [ALL_OFFICES],
areaOptions: [ALL_AREAS],
filteredLawyers: [] as Lawyer[],
hotlinePhone: '',
loading: false,
},
onLoad() {
this.initializePage();
},
async initializePage() {
this.setData({ loading: true });
try {
const firm = await getFirmProfile();
this.setData({
firmName: firm.name,
firmAddress: firm.hqAddress,
firmLatitude: firm.hqLatitude,
firmLongitude: firm.hqLongitude,
hotlinePhone: firm.hotlinePhone,
officeOptions: [ALL_OFFICES, ...firm.officeList],
areaOptions: [ALL_AREAS, ...firm.practiceAreas],
});
await this.loadLawyers();
} catch (error) {
const message = error instanceof Error ? error.message : '加载列表失败';
wx.showToast({ title: message, icon: 'none' });
} finally {
this.setData({ loading: false });
}
},
onUnload() {
if (searchDebounceTimer !== null) {
clearTimeout(searchDebounceTimer);
searchDebounceTimer = null;
}
},
onSearchInput(event: WechatMiniprogram.CustomEvent<{ value: string }>) {
const keyword = event.detail.value || '';
this.setData({ keyword });
if (searchDebounceTimer !== null) {
clearTimeout(searchDebounceTimer);
}
searchDebounceTimer = setTimeout(() => {
this.loadLawyers();
}, 250) as unknown as number;
},
handleOfficeChange(event: WechatMiniprogram.CustomEvent<{ value: string }>) {
this.setData({ selectedOffice: event.detail.value });
this.loadLawyers();
},
handleAreaChange(event: WechatMiniprogram.CustomEvent<{ value: string }>) {
this.setData({ selectedArea: event.detail.value });
this.loadLawyers();
},
async loadLawyers() {
this.setData({ loading: true });
try {
const filteredLawyers = await listLawyers({
keyword: this.data.keyword.trim() || undefined,
office: this.data.selectedOffice === ALL_OFFICES ? undefined : this.data.selectedOffice,
practiceArea: this.data.selectedArea === ALL_AREAS ? undefined : this.data.selectedArea,
});
this.setData({ filteredLawyers });
} catch (error) {
const message = error instanceof Error ? error.message : '加载律师列表失败';
wx.showToast({ title: message, icon: 'none' });
} finally {
this.setData({ loading: false });
}
},
handleLawyerSelect(event: WechatMiniprogram.CustomEvent<{ id: string }>) {
const lawyerId = event.detail.id;
if (!lawyerId) {
return;
}
wx.navigateTo({
url: `/pages/lawyer-detail/index?id=${lawyerId}`,
});
},
callHotline() {
if (!this.data.hotlinePhone) {
wx.showToast({
title: '暂无联系电话',
icon: 'none',
});
return;
}
wx.makePhoneCall({
phoneNumber: this.data.hotlinePhone,
fail: () => {
wx.showToast({ title: '拨号失败', icon: 'none' });
},
});
},
openOffice() {
if (!this.data.firmLatitude || !this.data.firmLongitude) {
wx.showToast({ title: '暂未配置地图位置', icon: 'none' });
return;
}
wx.openLocation({
latitude: this.data.firmLatitude,
longitude: this.data.firmLongitude,
name: this.data.firmName,
address: this.data.firmAddress,
scale: 18,
fail: () => {
wx.showToast({ title: '打开地图失败', icon: 'none' });
},
});
},
goHistory() {
wx.navigateTo({
url: '/pages/history/index',
});
},
});