From ac7764617f7fd95fad5dc314dcc0d5f1ad23b8c7 Mon Sep 17 00:00:00 2001
From: aaron <>
Date: Fri, 10 Jan 2025 17:41:08 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=95=86=E5=AE=B6=E5=92=8C?=
=?UTF-8?q?=E9=A9=BF=E7=AB=99=E7=9A=84=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/station.js | 9 ++
src/views/merchant/List.vue | 252 +++++++++++++++++++++++++++++-
src/views/station/StationList.vue | 112 ++++++++++++-
3 files changed, 369 insertions(+), 4 deletions(-)
diff --git a/src/api/station.js b/src/api/station.js
index 1f4b8f2..ea11e2f 100644
--- a/src/api/station.js
+++ b/src/api/station.js
@@ -16,4 +16,13 @@ export function createStation(data) {
method: 'post',
data
})
+}
+
+// 修改驿站
+export function updateStation(id, data) {
+ return request({
+ url: `/api/station/${id}`,
+ method: 'put',
+ data
+ })
}
\ No newline at end of file
diff --git a/src/views/merchant/List.vue b/src/views/merchant/List.vue
index 654e14d..931af40 100644
--- a/src/views/merchant/List.vue
+++ b/src/views/merchant/List.vue
@@ -22,7 +22,10 @@
{{ formatDateTime(record.create_time) }}
- 管理图片
+
+ 管理图片
+ 修改
+
@@ -167,6 +170,98 @@
>
+
+
+
+
+
+ 取消
+
+ 保存
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -678,6 +773,150 @@ export default defineComponent({
resetImageManager() // 使用重置函数
}
+ // 修改商家相关
+ const editModalVisible = ref(false)
+ const editLoading = ref(false)
+ const editFormRef = ref(null)
+ const editFormState = ref({
+ name: '',
+ category_id: undefined,
+ business_hours: '',
+ address: '',
+ longitude: null,
+ latitude: null,
+ phone: ''
+ })
+ const editSearchAddress = ref('')
+ const editMap = ref(null)
+ const editMarker = ref(null)
+ const currentEditId = ref(null)
+
+ // 显示修改模态框
+ const handleEdit = async (record) => {
+ currentEditId.value = record.id
+ editFormState.value = {
+ name: record.name,
+ category_id: record.category_id,
+ business_hours: record.business_hours,
+ address: record.address,
+ longitude: record.longitude,
+ latitude: record.latitude,
+ phone: record.phone
+ }
+
+ // 获取分类数据
+ if (categories.value.length === 0) {
+ await fetchCategories()
+ }
+
+ editModalVisible.value = true
+ await nextTick()
+ initEditMap(record.longitude, record.latitude)
+ }
+
+ // 初始化编辑地图
+ const initEditMap = async (lng, lat) => {
+ try {
+ await loadAMap()
+
+ if (!editMap.value) {
+ editMap.value = createMap('edit-map-container', {
+ zoom: 13,
+ viewMode: '2D'
+ })
+
+ editMap.value.on('click', async (e) => {
+ const { lng, lat } = e.lnglat
+ updateEditMarkerPosition(lng, lat)
+
+ const geocoder = createGeocoder()
+ geocoder.getAddress([lng, lat], (status, result) => {
+ if (status === 'complete' && result.info === 'OK') {
+ const address = result.regeocode
+ editFormState.value.address = address.formattedAddress
+ editFormState.value.longitude = lng
+ editFormState.value.latitude = lat
+ } else {
+ message.error('获取地址信息失败')
+ }
+ })
+ })
+ }
+
+ // 设置中心点和标记
+ editMap.value.setCenter([lng, lat])
+ updateEditMarkerPosition(lng, lat)
+ } catch (error) {
+ console.error('初始化地图失败:', error)
+ message.error('初始化地图失败')
+ }
+ }
+
+ // 更新编辑标记位置
+ const updateEditMarkerPosition = (lng, lat) => {
+ if (editMarker.value) {
+ editMarker.value.setPosition([lng, lat])
+ } else {
+ editMarker.value = new window.AMap.Marker({
+ position: [lng, lat],
+ map: editMap.value
+ })
+ }
+ }
+
+ // 处理地址选择
+ const handleEditSelect = (value, option) => {
+ const selected = searchOptions.value.find(opt => opt.value === value)
+ if (selected && selected.location) {
+ const { lng, lat } = selected.location
+ updateEditMarkerPosition(lng, lat)
+ editMap.value.setCenter([lng, lat])
+
+ const geocoder = createGeocoder()
+ geocoder.getAddress([lng, lat], (status, result) => {
+ if (status === 'complete' && result.info === 'OK') {
+ const address = result.regeocode
+ editFormState.value.address = address.formattedAddress
+ editFormState.value.longitude = lng
+ editFormState.value.latitude = lat
+ } else {
+ editFormState.value.address = value
+ editFormState.value.longitude = lng
+ editFormState.value.latitude = lat
+ }
+ })
+ }
+ }
+
+ // 提交修改
+ const handleEditSubmit = () => {
+ editFormRef.value.validate().then(async () => {
+ try {
+ editLoading.value = true
+ await request.put(`/api/merchant/${currentEditId.value}`, editFormState.value)
+ message.success('修改成功')
+ editModalVisible.value = false
+ fetchData()
+ } catch (error) {
+ console.error('修改商家失败:', error)
+ message.error('修改失败')
+ } finally {
+ editLoading.value = false
+ }
+ })
+ }
+
+ // 取消修改
+ const handleEditCancel = () => {
+ editFormRef.value?.resetFields()
+ editSearchAddress.value = ''
+ if (editMarker.value) {
+ editMarker.value.setMap(null)
+ editMarker.value = null
+ }
+ editModalVisible.value = false
+ }
+
onMounted(() => {
fetchData()
})
@@ -718,7 +957,16 @@ export default defineComponent({
handleRemove,
handleSaveImages,
handleCancelImages,
- categories
+ categories,
+ editModalVisible,
+ editLoading,
+ editFormRef,
+ editFormState,
+ editSearchAddress,
+ handleEdit,
+ handleEditSubmit,
+ handleEditCancel,
+ handleEditSelect
}
}
})
diff --git a/src/views/station/StationList.vue b/src/views/station/StationList.vue
index ad49400..3261b23 100644
--- a/src/views/station/StationList.vue
+++ b/src/views/station/StationList.vue
@@ -38,6 +38,13 @@
@change="handleTableChange"
row-key="id"
>
+
+
+
+ 修改
+
+
+
@@ -79,6 +86,46 @@
+
+
+
+
+
+ 取消
+
+ 保存
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -86,7 +133,7 @@