名片部分页面。地图定位。国家下拉搜索 回收站

This commit is contained in:
浅念
2025-03-25 13:12:24 +08:00
parent f7ff9d65a5
commit e3abe0bf18
18 changed files with 747 additions and 606 deletions
+103 -15
View File
@@ -117,21 +117,37 @@
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showmagnitude" @cancel="cancel('showmagnitude')" @close="close('showmagnitude')" :columns="magnitudeList" keyName="name" @confirm="magnitudeChange"></u-picker>
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showcartype" @cancel="cancel('showcartype')" @close="close('showcartype')" :columns="carTypeList" keyName="name" @confirm="cartypesChange"></u-picker>
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showgrade" @cancel="cancel('showgrade')" @close="close('showgrade')" :columns="getGradeList" keyName="name" @confirm="gradeHandler"></u-picker>
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showarea" @cancel="cancel('showarea')" @close="close('showarea')" :columns="areaList" keyName="name" @confirm="areaChange"></u-picker>
<!-- <u-popup :show="showmap" :round="10" mode="bottom" @close="mapclose" width="90%" height="70%">
<view class="mapcont">
<view class="header">
<view class="cancel" @click="mapclose">取消</view>
<view class="title">地图位置</view>
<view class="confirm" @click="mapconfirm">确定</view>
</view>
<view class="map" id="map">
</view>
<!-- <u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showarea" @cancel="cancel('showarea')" @close="close('showarea')" :columns="areaList" keyName="name" @confirm="areaChange"></u-picker> -->
<u-popup closeOnClickOverlay :show="showarea" mode="bottom" :round="10" @close="close('showarea')">
<view class="text">
<view class="qx" @click="close('showarea') ">{{$t('cancel')}}</view>
<view class="qd" @click="arerfn">{{$t('confirm')}}</view>
</view>
</u-popup> -->
<view class="popup-content">
<!-- 搜索框 -->
<u-input
v-model="searchKeyword"
:placeholder="$t('keyword')"
@input="handleSearch"
></u-input>
<!-- 选项列表 -->
<scroll-view scroll-y class="option-list">
<view
v-for="(item, index) in filteredOptions"
:key="index"
class="option-item"
@click="handleSelect(item)"
:class="actives==item.id?'actives':''"
>
{{ item.name }}
</view>
<view v-if="filteredOptions.length === 0" class="no-data">
{{$t('noresults')}}
</view>
</scroll-view>
</view>
</u-popup>
</view>
</template>
@@ -140,7 +156,11 @@
export default {
data() {
return {
mapUrl: '',
actives:'',
searchKeyword: "", // 搜索关键词
selectedLabel: "", // 选中的值(显示在输入框中)
filteredOptions: [], // 过滤后的数据
mapUrl: '',
showmap: false,
showmagnitude: false,
showgrade: false,
@@ -259,7 +279,8 @@
method:'get',
}).then(res => {
var list = res.data.data
this.areaList = [list]
this.areaList = list
this.filteredOptions = list;
})
},
//商机
@@ -302,6 +323,31 @@
this.car_type_name = val.value[0].name
this.showcartype = false
},
// 国家搜索处理函数
handleSearch() {
if (this.searchKeyword) {
console.log(this.searchKeyword)
this.filteredOptions = this.areaList.filter((item) =>
item.name.includes(this.searchKeyword)
);
console.log(this.filteredOptions)
} else {
// 如果搜索框为空,显示全部数据
this.filteredOptions = this.areaList;
}
},
// 选择选项
handleSelect(item) {
this.selectedLabel = item.name; // 回显选中的值
this.actives = item.id
console.log("选中的值:", item.id);
console.log("选中的值:", item.name);
},
arerfn(){
this.showarea = false; // 关闭弹窗
this.country_name = this.selectedLabel
this.form.country_id = this.actives
},
cancel(val){
this[val] = false
},
@@ -436,4 +482,46 @@
height: 350px;
}
}
//
.actives{
background-color: #dfdfdf;
}
.text{
display: flex;
align-items: center;
justify-content: space-between;
line-height: 30px;
padding: 10px 15px 0px;
.qd{
color: #3471FF;
}
}
.popup-content {
padding: 20px;
background-color: #fff;
}
.option-list {
max-height: 400rpx;
margin-top: 20rpx;
}
.option-item {
padding: 20rpx;
border-bottom: 1rpx solid #eee;
}
.option-item:last-child {
border-bottom: none;
}
.no-data {
text-align: center;
padding: 20rpx;
color: #999;
}
</style>
+118 -43
View File
@@ -67,14 +67,6 @@
<u-icon class="arrowright" name="arrow-right" size="18" color="#747474"></u-icon>
</view>
</view>
<!-- <u-line></u-line>
<view class="cell">
<view class="item">{{$t('customer.Cstomerfj')}}</view>
<view class="right select" @click="showgrade = true">
<view class="" :class="['content2', { placeholder: !grade_name }]">{{grade_name || $t('customer.Cstomerfjinput')}}</view>
<u-icon class="arrowright" name="arrow-right" size="18" color="#747474"></u-icon>
</view>
</view> -->
<u-line></u-line>
<view class="cell">
<view class="item">{{$t('customer.Country')}}</view>
@@ -109,20 +101,37 @@
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :defaultIndex="defaultIndexsj" :show="showmagnitude" @cancel="cancel('showmagnitude')" @close="close('showmagnitude')" :columns="magnitudeList" keyName="name" @confirm="magnitudeChange"></u-picker>
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')":defaultIndex="defaultIndexph" :show="showcartype" @cancel="cancel('showcartype')" @close="close('showcartype')" :columns="carTypeList" keyName="name" @confirm="cartypesChange"></u-picker>
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :defaultIndex="defaultIndexfj" :show="showgrade" @cancel="cancel('showgrade')" @close="close('showgrade')" :columns="getGradeList" keyName="name" @confirm="gradeHandler"></u-picker>
<u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :defaultIndex="defaultIndexgj" :show="showarea" @cancel="cancel('showarea')" @close="close('showarea')" :columns="areaList" keyName="name" @confirm="areaChange"></u-picker>
<!-- <u-popup :show="showmap" :round="10" mode="bottom" @close="mapclose">
<view class="mapcont">
<view class="header">
<view class="cancel" @click="mapclose">取消</view>
<view class="title">地图位置</view>
<view class="confirm" @click="mapconfirm">确定</view>
</view>
<view class="map">
</view>
<!-- <u-picker closeOnClickOverlay :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :defaultIndex="defaultIndexgj" :show="showarea" @cancel="cancel('showarea')" @close="close('showarea')" :columns="areaList" keyName="name" @confirm="areaChange"></u-picker> -->
<u-popup closeOnClickOverlay :show="showarea" mode="bottom" :round="10" @close="close('showarea')">
<view class="text">
<view class="qx" @click="close('showarea') ">{{$t('cancel')}}</view>
<view class="qd" @click="arerfn">{{$t('confirm')}}</view>
</view>
</u-popup> -->
<view class="popup-content">
<!-- 搜索框 -->
<u-input
v-model="searchKeyword"
:placeholder="$t('keyword')"
@input="handleSearch"
></u-input>
<!-- 选项列表 -->
<scroll-view scroll-y class="option-list">
<view
v-for="(item, index) in filteredOptions"
:key="index"
class="option-item"
@click="handleSelect(item)"
:class="actives==item.id?'actives':''"
>
{{ item.name }}
</view>
<view v-if="filteredOptions.length === 0" class="no-data">
{{$t('noresults')}}
</view>
</scroll-view>
</view>
</u-popup>
</view>
</template>
@@ -133,6 +142,10 @@
return {
id:'',
followList:[],
actives:'',
searchKeyword: "", // 搜索关键词
selectedLabel: "", // 选中的值(显示在输入框中)
filteredOptions: [], // 过滤后的数据
showmap: false,
showmagnitude: false,
showgrade: false,
@@ -184,7 +197,6 @@
var that = this
this.getChannel()
this.getMagnitude()
// this.getGrade()
this.carType()
this.area()
this.customerdetailfn()
@@ -207,7 +219,7 @@
gomap(){
// #ifdef H5
uni.navigateTo({
url: '/pages/customer/maph5'
url: '/pages/customer/maph5?lat='+this.form.lat+'&lng='+this.form.lng
});
// #endif
// #ifdef APP-PLUS
@@ -224,12 +236,6 @@
that.defaultIndexqd=[index]
}
})
// that.getGradeList1.forEach((item,index) => {
// if(item.id == that.form.grade){
// that.grade_name = item.name
// that.defaultIndexfj=[index]
// }
// })
that.carTypeList1.forEach((item,index) => {
if(item.id == that.form.car_type_id){
that.car_type_name = item.name
@@ -242,13 +248,6 @@
that.defaultIndexsj=[index]
}
})
that.areaList1.forEach((item,index) => {
if(item.id == that.form.country_id){
that.country_name = item.name
that.defaultIndexgj=[index]
console.log(that.country_name)
}
})
},
//客户详情
customerdetailfn(){
@@ -262,6 +261,8 @@
}).then(res => {
that.datas = res.data.data
that.form = res.data.data
this.actives = res.data.data.country_id
this.country_name = res.data.data.country_name
that.select()
})
},
@@ -332,7 +333,8 @@
var list = res.data.data
this.areaList1 = list
this.areaList = [list]
this.select()
this.filteredOptions = list;
// this.select()
})
},
//商机
@@ -364,18 +366,46 @@
this.grade_name = val.value[0].name
this.showgrade = false
},
//国家切换事件
areaChange(val){
this.form.country_id = val.value[0].id
this.country_name = val.value[0].name
this.showarea = false
},
// //国家切换事件
// areaChange(val){
// this.form.country_id = val.value[0].id
// this.country_name = val.value[0].name
// this.showarea = false
// },
//偏好切换事件
cartypesChange(val){
this.form.car_type_id = val.value[0].id
this.car_type_name = val.value[0].name
this.showcartype = false
},
// 搜索处理函数
handleSearch() {
if (this.searchKeyword) {
console.log(this.searchKeyword)
this.filteredOptions = this.areaList1.filter((item) =>
item.name.includes(this.searchKeyword)
);
console.log(this.filteredOptions)
} else {
// 如果搜索框为空,显示全部数据
this.filteredOptions = this.areaList1;
}
},
// 选择选项
handleSelect(item) {
this.selectedLabel = item.name; // 回显选中的值
// this.searchKeyword = item.name
this.actives = item.id
// this.showPicker = false; // 关闭弹窗
console.log("选中的值:", item.id);
console.log("选中的值:", item.name);
},
arerfn(){
this.showarea = false; // 关闭弹窗
this.country_name = this.selectedLabel
this.form.country_id = this.actives
},
cancel(val){
this[val] = false
},
@@ -481,4 +511,49 @@
margin-bottom: 40px;
margin: 15px 4%;
}
.actives{
background-color: #dfdfdf;
}
.text{
display: flex;
align-items: center;
justify-content: space-between;
line-height: 30px;
padding: 10px 15px 0px;
.qd{
color: #3471FF;
}
}
.popup-content {
padding: 20px;
background-color: #fff;
}
.option-list {
max-height: 400rpx;
margin-top: 20rpx;
}
.option-item {
padding: 20rpx;
border-bottom: 1rpx solid #eee;
}
.option-item:last-child {
border-bottom: none;
}
.no-data {
text-align: center;
padding: 20rpx;
color: #999;
}
</style>
+43 -54
View File
@@ -187,11 +187,12 @@
},
onLoad(options) {
console.log(options);
this.getlocahost()
this.id = options.id;
this.form.customer_id = options.id;
var that = this
this.getGrade()
this.getlocahost()
this.customerdetailfn()
this.followlistfn()
},
@@ -281,62 +282,50 @@
},
});
},
getlocahost(){
// 检查定位权限
uni.getSetting({
success: (res) => {
if (!res.authSetting['scope.userLocation']) {
// 未授权,请求权限
uni.authorize({
scope: 'scope.userLocation',
success: () => {
this.getlocahost();
},
fail: () => {
getlocahost() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
console.log('当前位置的经度:' + position.coords.longitude);
console.log('当前位置的纬度:' + position.coords.latitude);
this.getarrd(position.coords.longitude,position.coords.latitude)
this.error = '';
console.log("获取位置成功:", position);
},
(error) => {
this.error = this.getErrorMessage(error);
uni.showToast({
title: '定位权限未授权',
icon: 'none',
title: this.error,
icon: 'none'
});
},
});
} else {
// 已授权,直接获取定位
this.getlocahost();
}
},
});
console.error("获取位置失败:", error);
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
}
);
} else {
this.error = "浏览器不支持 Geolocation API";
uni.showToast({
title: this.error,
icon: 'none'
});
console.error("浏览器不支持 Geolocation API");
}
},
getlocahost(){
var that = this
uni.getLocation({
type: 'wgs84', // 默认为 wgs84 坐标系,可选 gcj02
success: function (res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
that.getarrd(res.longitude,res.latitude)
// 如果需要将经纬度转换为具体地址,可以使用逆地理编码
// 这里调用 uni.chooseLocation 或第三方地图服务(如高德、腾讯地图)
},
fail: function (err) {
console.log('获取位置失败:', err);
},
complete: function () {
console.log('获取位置完成');
}
});
// uni.chooseLocation({
// success: function (res) {
// console.log('位置名称:' + res.name);
// console.log('详细地址:' + res.address);
// console.log('经度:' + res.longitude);
// console.log('纬度:' + res.latitude);
// },
// fail: function (err) {
// console.log('选择位置失败:', err);
// }
// });
getErrorMessage(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
return "用户拒绝了地理位置权限";
case error.POSITION_UNAVAILABLE:
return "无法获取当前位置";
case error.TIMEOUT:
return "获取位置超时";
default:
return "未知错误";
}
},
// 跟进记录
followlistfn(){
+96 -51
View File
@@ -31,6 +31,7 @@ export default {
value: '',
// 模糊匹配数据
list: [],
center: { lat:'', lng:''},
cityInfo:{
lat: '',
lng: '',
@@ -44,7 +45,12 @@ export default {
}
}
},
onLoad() {
onLoad(e) {
if(e.lat&&e.lat!=''&&e.lat!=0){
this.center.lat = e.lat
this.center.lng = e.lng
}
console.log(e)
this.initMap()
},
methods:{
@@ -92,63 +98,102 @@ export default {
});
that.list =[]
},
getErrorMessage(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
return "用户拒绝了地理位置权限";
case error.POSITION_UNAVAILABLE:
return "无法获取当前位置";
case error.TIMEOUT:
return "获取位置超时";
default:
return "未知错误";
}
},
addmapmarkfn(lat,lng){
var that = this
that.map = new google.maps.Map(document.getElementById("map"),
{
center: { lat:lat, lng: lng},
zoom: 12,// 地图缩放参数
maxZoom: 18,// 最大缩放参数
minZoom: 4,// 最小缩放参数
disableDefaultUI: true// 禁用默认UI
}
)
var marker = new google.maps.Marker({
position: { lat:lat, lng: lng},
map: that.map,
draggable: true, // 允许拖动标记
icon: {
url: 'https://now.guua.com/attachs/default/location_shop.png',
scaledSize: new google.maps.Size(30, 30),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(0, 0)
}
});
// 监听标记拖动事件
marker.addListener('dragend', () => {
const position = marker.getPosition();
that.map.setCenter(position);
// 根据标记位置获取地址信息
const geocoder = new google.maps.Geocoder();
geocoder.geocode({ location: position }, (results, status) => {
if (status === 'OK' && results[0]) {
console.log(results)
console.log(position)
that.cityInfo.address = results[0].formatted_address;
that.cityInfo.lat = position.lat();
that.cityInfo.lng = position.lng();
that.value = results[0].formatted_address;
console.log(that.cityInfo)
} else {
alert('无法获取地址信息');
}
});
});
},
initMap() {
var that = this
loader
.load()
.then((google) => {
uni.getLocation({
type: 'wgs84', // 默认为 wgs84 坐标系,可选 gcj02
success: function (res) {
console.log(res)
that.map = new google.maps.Map(document.getElementById("map"),
{
center: { lat:res.latitude, lng: res.longitude},
zoom: 12,// 地图缩放参数
maxZoom: 18,// 最大缩放参数
minZoom: 4,// 最小缩放参数
disableDefaultUI: true// 禁用默认UI
}
)
var marker = new google.maps.Marker({
position: { lat:res.latitude, lng: res.longitude},
map: that.map,
draggable: true, // 允许拖动标记
icon: {
url: 'https://now.guua.com/attachs/default/location_shop.png',
scaledSize: new google.maps.Size(30, 30),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(0, 0)
if(this.center.lat!=''){
that.addmapmarkfn(parseFloat(this.center.lat),parseFloat(this.center.lng))
}else{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
console.log('当前位置的经度:' + position.coords.longitude);
console.log('当前位置的纬度:' + position.coords.latitude);
that.addmapmarkfn(position.coords.latitude,position.coords.longitude)
this.error = '';
console.log("获取位置成功:", position);
},
(error) => {
this.error = this.getErrorMessage(error);
uni.showToast({
title: this.error,
icon: 'none'
});
console.error("获取位置失败:", error);
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
}
);
} else {
this.error = "浏览器不支持 Geolocation API";
uni.showToast({
title: this.error,
icon: 'none'
});
// 监听标记拖动事件
marker.addListener('dragend', () => {
const position = marker.getPosition();
that.map.setCenter(position);
// 根据标记位置获取地址信息
const geocoder = new google.maps.Geocoder();
geocoder.geocode({ location: position }, (results, status) => {
if (status === 'OK' && results[0]) {
console.log(results)
console.log(position)
that.cityInfo.address = results[0].formatted_address;
that.cityInfo.lat = position.lat();
that.cityInfo.lng = position.lng();
that.value = results[0].formatted_address;
console.log(that.cityInfo)
} else {
alert('无法获取地址信息');
}
});
});
},
fail: function (err) {
console.log('获取位置失败:', err);
},
complete: function () {
console.log('获取位置完成');
}
})
console.error("浏览器不支持 Geolocation API");
}
}
})
.catch((e) => {