This commit is contained in:
hantao 2025-08-14 10:36:06 +08:00
parent 610a06519b
commit bd8a9a4b0c
9 changed files with 135 additions and 102 deletions

View File

@ -2,8 +2,8 @@ const request = require('../../utils/request');
Page({ Page({
data: { data: {
carList: [], carList: [],
type:1, type: 1,
selectedSort: 'default', selectedSort: '',
selectedBrand: '', selectedBrand: '',
selectedPrice: '', selectedPrice: '',
filterParams: {}, filterParams: {},
@ -12,15 +12,21 @@ Page({
selectedBrandLabel:"品牌", selectedBrandLabel:"品牌",
brandTree: [], brandTree: [],
sortOptions: [ sortOptions: [
{ text: '默认排序', value: 'default' }, { text: '默认排序', value: '' },
{ text: '价格升序', value: 'priceAsc' }, { text: '最新上架', value: 'created_at-desc' },
{ text: '价格降序', value: 'priceDesc' } { text: '价格降序', value: 'price-desc' },
{ text: '价格升序', value: 'price-asc' }
], ],
priceOptions: [ priceOptions: [
{ text: '全部价格', value: '' }, { text: '全部价格', value: '' },
{ text: '5万以下', value: '<5' }, { text: '3万以下', value: '0-3' },
{ text: '5-10万', value: '5-10'}, { text: '3-5万', value: '3-5'},
{ text: '10万以上', value: '>10' } { text: '5-10万', value: '5-10' },
{ text: '10-15万', value: '10-15' },
{ text: '15-20万', value: '15-20' },
{ text: '20-30万', value: '20-30' },
{ text: '30-50万', value: '30-50' },
{ text: '50万以上', value: ' 50-10000' },
], ],
extendFields: [], // 筛选配置 extendFields: [], // 筛选配置
@ -191,21 +197,60 @@ Page({
} }
}, },
openMap() {
const { latitude, longitude, address, name } = this.data.company
wx.openLocation({
latitude,
longitude,
scale: 18,
name,
address
})
},
onLoad(options){ onLoad(options){
if (options.type) { if (options.type) {
this.setData({ this.setData({
type: options.type type: options.type
}); });
const new_car_prices = [
{ text: '全部价格', value: '' },
{ text: '5万以下', value: '0-5' },
{ text: '5-10万', value: '5-10' },
{ text: '10-15万', value: '10-15' },
{ text: '15-20万', value: '15-20' },
{ text: '20-30万', value: '20-30' },
{ text: '30-50万', value: '30-50' },
{ text: '50-100万', value: '50-100' },
{ text: '100万以上', value: '100-10000' },
];
const old_car_prices = [
{ text: '全部价格', value: '' },
{ text: '3万以下', value: '0-3' },
{ text: '3-5万', value: '3-5'},
{ text: '5-10万', value: '5-10' },
{ text: '10-15万', value: '10-15' },
{ text: '15-20万', value: '15-20' },
{ text: '20-30万', value: '20-30' },
{ text: '30-50万', value: '30-50' },
{ text: '50万以上', value: ' 50-100000' },
];
const rent_car_prices = [
{ text: '全部价格', value: '' },
{ text: '100元以下', value: '0-100' },
{ text: '100-200元', value: '100-200' },
{ text: '200-300元', value: '200-300' },
{ text: '300-500元', value: '300-500' },
{ text: '500-800元', value: '500-800' },
{ text: '800-1500元', value: '800-1500' },
{ text: '1500元以上', value: '1500-100000' },
];
if(options.type == 1){
this.setData({
priceOptions: new_car_prices
});
}else if(options.type == 2){
this.setData({
priceOptions: old_car_prices
});
}else{
this.setData({
priceOptions: rent_car_prices
});
}
} }
this.loadBrandData(); this.loadBrandData();
}, },

View File

@ -21,55 +21,7 @@
options="{{priceOptions}}" options="{{priceOptions}}"
bind:change="onPriceChange" bind:change="onPriceChange"
/> />
<van-dropdown-item title="参数"
use-slot
id="dropdownItemParam"
>
<view class="filter-extend">
<view wx:for="{{extendFields}}" wx:key="id" class="filter-group">
<view class="filter-label">{{item.label}}</view>
<!-- 多选项字段 -->
<view wx:if="{{item.type === 'checkbox'}}" class="filter-tags">
<view
wx:for="{{item.options}}"
wx:for-item="opt"
wx:key="index"
class="filter-tag-item"
data-name="{{item.name}}"
data-value="{{opt.value}}"
bind:tap="onTagToggle"
>
<van-tag
size="medium"
plain="{{!opt._checked}}"
>
{{opt.key}}
</van-tag>
</view>
</view>
<view wx:if="{{item.type === 'range'}}" class="filter-slider-group">
<view class="slider-label">
{{item.label}}{{item._rangeStart || item.options.start}}{{item.options.unit}} - {{item._rangeEnd || item.options.end}}{{item.options.unit}}
</view>
<van-slider
range
value="{{[item._rangeStart ? item._rangeStart : item.options.start, item._rangeEnd ? item._rangeEnd : item.options.end]}}"
min="{{item.options.start}}"
max="{{item.options.end}}"
data-name="{{item.name}}"
bind:change="onSliderChange"
/>
</view>
</view>
<van-button type="primary" block size="small" bind:tap="onExtendConfirm">确认</van-button>
</view>
</van-dropdown-item>
</van-dropdown-menu> </van-dropdown-menu>
</view> </view>

View File

@ -2,15 +2,12 @@ const request = require('../../utils/request');
Page({ Page({
data: { data: {
bannerList: [ bannerList: [],
'http://192.168.1.11:8089/uploads/20250630/054c53776891b766c6f1bd65059a5b27.jpg',
'http://192.168.1.11:8089/uploads/20250630/c7f45ec56c19eac42a23c5e987cacc93.jpg'
],
company: { company: {
name: '某某汽车服务有限公司', name: 'HM car center',
address: '上海市浦东新区世纪大道100号', address: 'HM car center',
latitude: 31.2304, // 地图坐标 latitude: 31.854870, // 地图坐标
longitude: 121.4737, longitude: 106.746141,
phone: '021-88888888' phone: '021-88888888'
} }
}, },
@ -18,6 +15,14 @@ Page({
// 页面显示时刷新数据 // 页面显示时刷新数据
this.loadBanner(); this.loadBanner();
}, },
onShareAppMessage() {
// 分享配置
return {
title: this.data.company.name,
path: `/pages/index`,
imageUrl: this.data.bannerList[0]
};
},
// 跳转到新车页面 // 跳转到新车页面
goToNewCar: function () { goToNewCar: function () {
wx.navigateTo({ wx.navigateTo({
@ -25,6 +30,16 @@ Page({
}); });
}, },
openMap() {
const { latitude, longitude, address, name } = this.data.company
wx.openLocation({
latitude,
longitude,
scale: 18,
name,
address
})
},
// 跳转到租车页面 // 跳转到租车页面
goToRental: function () { goToRental: function () {
wx.navigateTo({ wx.navigateTo({
@ -38,11 +53,29 @@ Page({
url: '/pages/car_new/car_new?type=' + 2 url: '/pages/car_new/car_new?type=' + 2
}); });
}, },
// 拨打电话
makePhoneCall(e) {
const phone = e.currentTarget.dataset.phone || this.data.contactPhone;
wx.makePhoneCall({
phoneNumber: phone,
success: () => {
console.log('拨打电话成功');
},
fail: (err) => {
console.error('拨打电话失败:', err);
wx.showToast({
title: '拨打失败',
icon: 'none'
});
}
});
},
async loadBanner() { async loadBanner() {
const data = await request({ const data = await request({
url: '/admin/wechat/api/banners' url: '/admin/wechat/api/banners'
}); });
this.setData({ bannerList: data }) this.setData({ bannerList: data.banner });
this.setData({ company: data.company })
} }
}) })

View File

@ -1,4 +1,5 @@
{ {
"navigationBarTitleText": "首页",
"usingComponents": { "usingComponents": {
"van-icon": "@vant/weapp/icon/index", "van-icon": "@vant/weapp/icon/index",
"van-dropdown-menu": "@vant/weapp/dropdown-menu/index", "van-dropdown-menu": "@vant/weapp/dropdown-menu/index",
@ -7,5 +8,6 @@
"van-slider": "@vant/weapp/slider/index", "van-slider": "@vant/weapp/slider/index",
"van-tag": "@vant/weapp/tag/index", "van-tag": "@vant/weapp/tag/index",
"van-button": "@vant/weapp/button/index" "van-button": "@vant/weapp/button/index"
} },
"enableShareAppMessage": true
} }

View File

@ -17,7 +17,7 @@
</view> </view>
<view class="company-actions"> <view class="company-actions">
<van-button size="small" type="primary" plain icon="location-o" bindtap="openMap">导航</van-button> <van-button size="small" type="primary" plain icon="location-o" bindtap="openMap">导航</van-button>
<van-button size="small" type="info" plain icon="phone" open-type="makePhoneCall" data-phone="{{company.phone}}">电话</van-button> <van-button size="small" type="info" plain icon="phone" bindtap="makePhoneCall" data-phone="{{company.phone}}">电话</van-button>
</view> </view>
</view> </view>
@ -52,7 +52,7 @@
</view> </view>
<!-- 热门推荐 --> <!-- 热门推荐 -->
<view class="hot-recommend"> <!-- <view class="hot-recommend">
<view class="section-title"> <view class="section-title">
<text>热门推荐</text> <text>热门推荐</text>
<van-icon name="arrow" size="16px" /> <van-icon name="arrow" size="16px" />
@ -70,4 +70,4 @@
</view> </view>
</view> </view>
</view> </view>
</view> </view> -->

View File

@ -42,6 +42,25 @@ Page({
}; };
}, },
// 拨打电话
makePhoneCall(e) {
const phone = e.currentTarget.dataset.phone
|| this.data.contactPhone || this.data.carDetail.contact.mobile;
wx.makePhoneCall({
phoneNumber: phone,
success: () => {
console.log('拨打电话成功');
},
fail: (err) => {
console.error('拨打电话失败:', err);
wx.showToast({
title: '拨打失败',
icon: 'none'
});
}
});
},
onShareTimeline() { onShareTimeline() {
// 分享到朋友圈 // 分享到朋友圈
return { return {
@ -79,7 +98,6 @@ Page({
// 模拟API调用 // 模拟API调用
const carDetail = await this.fetchCarDetail(this.data.carId); const carDetail = await this.fetchCarDetail(this.data.carId);
console.log(carDetail)
if (carDetail) { if (carDetail) {
// 计算优惠金额 // 计算优惠金额
const discountAmount = (carDetail.re_price - carDetail.price).toFixed(1); const discountAmount = (carDetail.re_price - carDetail.price).toFixed(1);
@ -198,29 +216,10 @@ Page({
}); });
}, },
// 拨打电话
makePhoneCall(e) {
const phone = e.currentTarget.dataset.phone || this.data.contactPhone;
wx.makePhoneCall({
phoneNumber: phone,
success: () => {
console.log('拨打电话成功');
},
fail: (err) => {
console.error('拨打电话失败:', err);
wx.showToast({
title: '拨打失败',
icon: 'none'
});
}
});
},
// 打开微信咨询 // 打开微信咨询
openWechat() { openWechat() {
// 方案1: 复制微信号 // 方案1: 复制微信号
const wechatId = 'car_consultant_001'; const wechatId = this.data.carDetail.contact.mobile || '';
wx.showModal({ wx.showModal({
title: '微信咨询', title: '微信咨询',

View File

@ -6,5 +6,6 @@
"van-loading": "@vant/weapp/loading/index", "van-loading": "@vant/weapp/loading/index",
"van-overlay": "@vant/weapp/overlay/index" "van-overlay": "@vant/weapp/overlay/index"
}, },
"enableShareAppMessage": true,
"disableScroll": false "disableScroll": false
} }

View File

@ -36,6 +36,6 @@
"tabIndent": "auto", "tabIndent": "auto",
"tabSize": 2 "tabSize": 2
}, },
"appid": "wx62337d2f58b2825a", "appid": "wxf656003f2a1359f5",
"simulatorPluginLibVersion": {} "simulatorPluginLibVersion": {}
} }

View File

@ -1,4 +1,5 @@
const BASE_URL = 'https://car.cherrybless.com'; // 👈 换成你的后端地址 const BASE_URL = 'https://car.cherrybless.com'; // 👈 换成你的后端地址
// const BASE_URL = 'http://127.0.0.1:8089'; // 👈 换成你的后端地址
function request({ url, method = 'GET', data = {}, header = {} }) { function request({ url, method = 'GET', data = {}, header = {} }) {
const token = ''; const token = '';