Просмотр исходного кода

需求变更:省市区切换ip定位

@dongkboy 7 месяцев назад
Родитель
Сommit
27cb91b925

+ 10 - 9
pages/adManagement/adlist.vue

@@ -137,26 +137,27 @@
 						name: "全屏广告",
 						value: "0",
 						content: "沉浸式覆盖",
-						image: "../static/ad/adtype1.png"
+						image: require("../../static/ad/adtype1.png")
 					},
 					{
 						name: "轮播广告",
 						value: "2",
 						content: "多内容循环展示",
-						image: "../../static/ad/adtype2.png"
-					}, {
+						image: require("../../static/ad/adtype2.png")
+					},
+					{
 						name: "页面嵌入广告",
 						value: "3",
 						content: "自然融入页面",
-						image: "../../static/ad/adtype3.png"
-					}, {
+						image: require("../../static/ad/adtype3.png")
+					},
+					{
 						name: "弹窗广告",
 						value: "1",
 						content: "强提醒触达",
-						image: "../../static/ad/adtype4.png"
+						image: require("../../static/ad/adtype4.png")
 					}
 				],
-
 				categoryFilter: [{
 					title: "广告类型",
 					filed: "type",
@@ -202,12 +203,12 @@
 						},
 						{
 							id: 2,
-							label: "审核驳回",
+							label: "审核通过",
 							value: "1",
 						},
 						{
 							id: 3,
-							label: "审核通过",
+							label: "审核驳回",
 							value: "2",
 						},
 						{

+ 32 - 28
pages/adManagement/createFullscreenAd.vue

@@ -18,9 +18,13 @@
 			</view>
 			<view class="module">
 				<text class="module-title ">投放区域</text>
-				<u-form-item label="省市区" prop="district" :label-width="100" required :border-bottom="false">
-					<u-input v-model="queryTreeValue" type="select" :select-open="queryTreeShow"
-						@click="queryTreeShow=true" :custom-style="{textAlign:'right'}" placeholder="请选择"></u-input>
+				<u-form-item label="门店地址" prop="address" required :border-bottom="false">
+					<u-input v-model="adForm.address" type="textarea" disabled
+						:custom-style="{textAlign:'right'}"></u-input>
+				</u-form-item>
+				<u-form-item label="投放范围" prop="coverageArea" required :border-bottom="false">
+					<u-input v-model="adForm.coverageArea" type="number" :custom-style="{textAlign:'right'}"></u-input>
+					<text class="ml-1">公里</text>
 				</u-form-item>
 			</view>
 			<view class="module">
@@ -207,9 +211,6 @@
 				提交审核
 			</view>
 		</view>
-		<!-- 省市区 -->
-		<u-select v-model="queryTreeShow" mode="mutil-column-auto" label-name="areaCname" value-name="areaCode"
-			child-name="children" :list="queryTreeList" @confirm="queryTreeConfirm"></u-select>
 		<!-- 广告位 -->
 		<u-select v-model="adSlotShow" mode="single-column" label-name="positionName" value-name="id" :list="adSlotList"
 			@confirm="adSlotConfirm"></u-select>
@@ -234,6 +235,10 @@
 		ACCESS_TOKEN,
 		USER_INFO
 	} from '@/common/util/constants.js'
+	import {
+		getCity,
+		findCityCodeByCname
+	} from './parseAddress.js' //地址解析函数
 	import configService from '@/common/service/config.service'
 	export default {
 		data() {
@@ -267,14 +272,7 @@
 					positionName: "", //广告位name
 					startDate: "", //投放开始时间
 					endDate: "", //投放结束时间
-					province: "", //省
-					provinceCode: "",
 					city: "", //市
-					cityCode: "",
-					district: "", //区
-					districtCode: "",
-					street: "", //街道
-					streetCode: "",
 					validPeriodType: "", //生效周期
 					validPeriodValue: "", //周期策略
 					validTimeRangeType: "", //生效时段类型
@@ -289,6 +287,10 @@
 					adBudget: "", //广告预算
 					merchantId: "", //商户id
 					merchantName: "", //商户name
+					address: "",
+					longitude: "", //经度
+					latitude: "", //维度
+					coverageArea: 0, //范围
 				},
 				timeSegmentStart: "", //生效时段开始
 				timeSegmentEnd: "", //生效时段结束
@@ -443,7 +445,7 @@
 			await this.queryAdSlot(); // 获取广告位数据
 			this.generateWeek();
 			this.generatemonth();
-
+			this.storeDetail();
 		},
 		onReady() {
 			this.$refs.uForm.setRules(this.adrules);
@@ -455,6 +457,20 @@
 			}
 		},
 		methods: {
+			// 门店
+			async storeDetail() {
+				let id = uni.getStorageSync(USER_INFO).merchantId;
+				let res = await this.$http.get("/merchant/localMerchantInfo/queryAppInfoById?id=" + id)
+				if (res.data.success) {
+					console.log(res);
+					this.adForm.address = res.data.result.address;
+					this.adForm.longitude = Number(res.data.result.longitude);
+					this.adForm.latitude = Number(res.data.result.latitude);
+					const addressResult = getCity(this.adForm.address); //截取城市
+					const cityCode = findCityCodeByCname(addressResult, this.queryTreeList) // 查找城市code
+					this.adForm.city = cityCode;
+				}
+			},
 			submit() {
 				if (this.adForm.validTimeRangeType == '1' && this.timeSegmentStart && this.timeSegmentEnd) {
 					this.adForm.validTimeRangeValue = this.timeSegmentStart + "," + this.timeSegmentEnd;
@@ -558,7 +574,7 @@
 				this.$http.get('/adPricingPrice/queryPageList', {
 					params: {
 						adPositionId: this.adForm.positionId,
-						city: this.adForm.cityCode,
+						city: this.adForm.city,
 						pageNo: 1,
 						pageSize: 1000,
 					}
@@ -628,19 +644,6 @@
 					}
 				})
 			},
-			//省市区选择事件
-			queryTreeConfirm(value) {
-				this.queryTreeValue = `${value[0].label}-${value[1].label}-${value[2].label}-${value[3].label}`
-				this.adForm.provinceCode = value[0].value;
-				this.adForm.cityCode = value[1].value;
-				this.adForm.districtCode = value[2].value;
-				this.adForm.streetCode = value[3].value;
-				this.adForm.province = value[0].label;
-				this.adForm.city = value[1].label;
-				this.adForm.district = value[2].label;
-				this.adForm.street = value[3].label;
-				this.getadBillingModel() //获取计费方式
-			},
 			//广告位选择后续操作
 			adSlotConfirm(value) {
 				let info = this.adSlotList.find(val => val.id == value[0].value).supportMaterial.split(','); //获取投放内容类型
@@ -658,6 +661,7 @@
 				this.adForm.imageType = info[0];
 				this.adForm.positionId = value[0].value;
 				this.adForm.positionName = value[0].label;
+				this.getadBillingModel() //获取计费方式
 			},
 			//日期选择
 			startDateChange(e) {

+ 1 - 2
pages/adManagement/fullscreenAdDetails.vue

@@ -29,8 +29,7 @@
 			</view>
 			<view class="module dis f-c ">
 				<text class="module-title ">投放区域</text>
-				<text
-					class="address">{{detailsInfo.province}}-{{detailsInfo.city}}-{{detailsInfo.district}}-{{detailsInfo.street}}</text>
+				<text class="address">{{detailsInfo.address}}</text>
 			</view>
 			<view class="module dis f-c ">
 				<text class="module-title ">投放时间</text>

+ 171 - 0
pages/adManagement/parseAddress.js

@@ -0,0 +1,171 @@
+/**
+ * 地址解析工具 - 使用关键词匹配方式解析省市区地址
+ * 思路:通过省市区关键词截取,去两边留中间
+ */
+
+/**
+ * 解析连续文本格式的地址
+ * @param {string} fullAddress 完整地址字符串,如:山西省太原市迎泽区庙前街道劲松北路9号院
+ * @returns {Object|null} 解析后的地址信息
+ */
+export const parseAddress = (fullAddress) => {
+	if (!fullAddress || typeof fullAddress !== 'string') {
+		console.warn('地址不能为空且必须为字符串');
+		return null;
+	}
+
+	// 定义省市区关键词
+	const provinceKeywords = /省|自治区|特别行政区/;
+	const cityKeywords = /市|自治州|地区|盟/;
+	const districtKeywords = /区|县|旗|自治县|自治旗|特区|林区/;
+
+	// 1. 解析省份
+	const provinceEndIndex = fullAddress.search(provinceKeywords);
+	if (provinceEndIndex === -1) {
+		// 处理直辖市情况
+		const cityStartIndex = fullAddress.search(cityKeywords);
+		if (cityStartIndex === -1) {
+			console.warn('无法识别省份或城市');
+			return null;
+		}
+		// 直辖市情况:如北京市海淀区
+		const province = fullAddress.substring(0, cityStartIndex + 1);
+		const city = province;
+
+		// 解析区县
+		const districtEndIndex = fullAddress.search(districtKeywords);
+		if (districtEndIndex === -1) {
+			console.warn('无法识别区县');
+			return null;
+		}
+		const district = fullAddress.substring(city.length, districtEndIndex + 1);
+		const street = fullAddress.substring(districtEndIndex + 1).trim();
+
+		return {
+			province,
+			city,
+			district,
+			street: street || undefined
+		};
+	}
+
+	// 2. 解析城市
+	const province = fullAddress.substring(0, provinceEndIndex + 1);
+	const remainingAfterProvince = fullAddress.substring(provinceEndIndex + 1);
+
+	const cityEndIndex = remainingAfterProvince.search(cityKeywords);
+	if (cityEndIndex === -1) {
+		console.warn('无法识别城市');
+		return null;
+	}
+	const city = remainingAfterProvince.substring(0, cityEndIndex + 1);
+	const remainingAfterCity = remainingAfterProvince.substring(cityEndIndex + 1);
+
+	// 3. 解析区县
+	const districtEndIndex = remainingAfterCity.search(districtKeywords);
+	if (districtEndIndex === -1) {
+		console.warn('无法识别区县');
+		return null;
+	}
+	const district = remainingAfterCity.substring(0, districtEndIndex + 1);
+	const street = remainingAfterCity.substring(districtEndIndex + 1).trim();
+
+	return {
+		province,
+		city,
+		district,
+		street: street || undefined
+	};
+};
+
+/**
+ * 仅获取省份名称
+ * @param {string} fullAddress 完整地址字符串
+ * @returns {string|null} 省份名称
+ */
+export const getProvince = (fullAddress) => {
+	const result = parseAddress(fullAddress);
+	return result?.province || null;
+};
+
+/**
+ * 仅获取城市名称
+ * @param {string} fullAddress 完整地址字符串
+ * @returns {string|null} 城市名称
+ */
+export const getCity = (fullAddress) => {
+	const result = parseAddress(fullAddress);
+	return result?.city || null;
+};
+
+/**
+ * 仅获取区县名称
+ * @param {string} fullAddress 完整地址字符串
+ * @returns {string|null} 区县名称
+ */
+export const getDistrict = (fullAddress) => {
+	const result = parseAddress(fullAddress);
+	return result?.district || null;
+};
+
+/**
+ * 获取解析后的省市区数组(用于回显)
+ * @param {string} fullAddress 完整地址字符串
+ * @returns {Array} 省市区数组
+ */
+export const getAddressTree = (fullAddress) => {
+	const result = parseAddress(fullAddress);
+	if (!result) return [];
+	return [result.province, result.city, result.district];
+};
+
+/**
+ * 递归查找城市名称对应的areaCode
+ * @param {string} cityName 城市名称
+ * @param {Array} areaTree 省市区联级列表数据
+ * @returns {string} 匹配到的areaCode,匹配不到返回空字符串
+ */
+export const findCityCodeByCname = (cityName, areaTree) => {
+	// 边界条件检查
+	if (!cityName || !areaTree || !Array.isArray(areaTree)) {
+		return '';
+	}
+	// 遍历当前层级
+	for (const area of areaTree) {
+		// 匹配到城市名称,返回areaCode
+		if (area.areaCname == cityName) {
+			return area.areaCode;
+		}
+
+		// 如果有子节点,递归查找
+		if (area.children && area.children.length > 0) {
+			const foundCode = findCityCodeByCname(cityName, area.children);
+			if (foundCode) {
+				return foundCode;
+			}
+		}
+	}
+
+	// 所有节点都遍历完,没有匹配到
+	return '';
+};
+
+// Vue 2 插件形式
+const AddressParserPlugin = {
+	install(Vue) {
+		Vue.prototype.$parseAddress = parseAddress;
+		Vue.prototype.$getProvince = getProvince;
+		Vue.prototype.$getCity = getCity;
+		Vue.prototype.$getDistrict = getDistrict;
+		Vue.prototype.$getAddressTree = getAddressTree;
+		Vue.prototype.$findCityCodeByCname = findCityCodeByCname;
+	}
+};
+
+// 如果是在浏览器环境下直接使用
+if (typeof window !== 'undefined' && window.Vue) {
+	window.Vue.use(AddressParserPlugin);
+}
+
+// 导出插件形式
+export default AddressParserPlugin;