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 @@