地址路径修改
This commit is contained in:
@@ -10,7 +10,7 @@ Page({
|
||||
filteredWarehouses: [] as WarehouseInfo[],
|
||||
|
||||
// 页面状态
|
||||
currentTab: 'list', // list: 列表页, add: 添加页
|
||||
currentTab: 'list', // list: 列表页, add: 添加页, edit: 编辑页
|
||||
loading: false,
|
||||
|
||||
// 添加仓库表单数据
|
||||
@@ -25,6 +25,20 @@ Page({
|
||||
latitude: 24.880095
|
||||
},
|
||||
|
||||
// 编辑仓库表单数据
|
||||
editForm: {
|
||||
id: 0,
|
||||
name: '',
|
||||
address: '',
|
||||
contact: '',
|
||||
phone: '',
|
||||
description: '',
|
||||
capacity: 500,
|
||||
longitude: 102.833722,
|
||||
latitude: 24.880095,
|
||||
status: 'open' as 'open' | 'closed' | 'maintenance'
|
||||
},
|
||||
|
||||
// 错误信息
|
||||
errorMessage: '',
|
||||
successMessage: '',
|
||||
@@ -41,8 +55,10 @@ Page({
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 页面显示时刷新数据
|
||||
this.loadWarehouses();
|
||||
// 只在页面显示时检查是否需要刷新数据,避免频繁请求
|
||||
if (this.data.warehouses.length === 0) {
|
||||
this.loadWarehouses();
|
||||
}
|
||||
},
|
||||
|
||||
// 加载仓库列表
|
||||
@@ -145,6 +161,51 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
// 经度输入处理
|
||||
onLongitudeInput(e: any) {
|
||||
const value = parseFloat(e.detail.value) || 0;
|
||||
this.setData({
|
||||
'addForm.longitude': value
|
||||
});
|
||||
},
|
||||
|
||||
// 纬度输入处理
|
||||
onLatitudeInput(e: any) {
|
||||
const value = parseFloat(e.detail.value) || 0;
|
||||
this.setData({
|
||||
'addForm.latitude': value
|
||||
});
|
||||
},
|
||||
|
||||
// 地图选点功能
|
||||
pickLocationFromMap() {
|
||||
console.log('开始地图选点...');
|
||||
wx.chooseLocation({
|
||||
success: (res) => {
|
||||
console.log('地图选点成功:', res);
|
||||
if (res.longitude && res.latitude) {
|
||||
console.log('更新表单数据 - 经度:', res.longitude, '纬度:', res.latitude);
|
||||
this.setData({
|
||||
'addForm.longitude': res.longitude,
|
||||
'addForm.latitude': res.latitude
|
||||
});
|
||||
console.log('表单数据更新后:', this.data.addForm);
|
||||
wx.showToast({
|
||||
title: '位置已选择',
|
||||
icon: 'success'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('地图选点失败:', error);
|
||||
wx.showToast({
|
||||
title: '选点失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 验证表单
|
||||
validateForm(): boolean {
|
||||
const { name, address, contact, phone } = this.data.addForm;
|
||||
@@ -237,6 +298,168 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
// 取消编辑
|
||||
cancelEdit() {
|
||||
this.setData({
|
||||
currentTab: 'list',
|
||||
errorMessage: '',
|
||||
successMessage: ''
|
||||
});
|
||||
},
|
||||
|
||||
// 编辑表单输入处理
|
||||
onEditNameInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.name': e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
onEditAddressInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.address': e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
onEditContactInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.contact': e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
onEditPhoneInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.phone': e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
onEditDescriptionInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.description': e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
onEditCapacityInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.capacity': parseInt(e.detail.value) || 500
|
||||
});
|
||||
},
|
||||
|
||||
onEditLongitudeInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.longitude': parseFloat(e.detail.value) || 102.833722
|
||||
});
|
||||
},
|
||||
|
||||
onEditLatitudeInput(e: any) {
|
||||
this.setData({
|
||||
'editForm.latitude': parseFloat(e.detail.value) || 24.880095
|
||||
});
|
||||
},
|
||||
|
||||
onEditStatusChange(e: any) {
|
||||
this.setData({
|
||||
'editForm.status': e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
// 编辑仓库
|
||||
editWarehouse(e: any) {
|
||||
const warehouseId = e.currentTarget.dataset.id;
|
||||
const warehouse = this.data.warehouses.find(w => w.id === warehouseId);
|
||||
|
||||
if (warehouse) {
|
||||
this.setData({
|
||||
editForm: {
|
||||
id: warehouse.id || 0,
|
||||
name: warehouse.name || '',
|
||||
address: warehouse.address || '',
|
||||
contact: warehouse.contact || '',
|
||||
phone: warehouse.phone || '',
|
||||
description: warehouse.description || '',
|
||||
capacity: warehouse.capacity || 500,
|
||||
longitude: warehouse.longitude || 102.833722,
|
||||
latitude: warehouse.latitude || 24.880095,
|
||||
status: warehouse.status || 'open'
|
||||
},
|
||||
currentTab: 'edit'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 提交编辑仓库表单
|
||||
async submitEditForm() {
|
||||
this.setData({
|
||||
errorMessage: '',
|
||||
successMessage: ''
|
||||
});
|
||||
|
||||
if (!this.validateEditForm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loading: true
|
||||
});
|
||||
|
||||
try {
|
||||
// 使用updateWarehouse更新仓库信息
|
||||
await warehouseService.updateWarehouse(this.data.editForm.id, this.data.editForm);
|
||||
|
||||
this.setData({
|
||||
loading: false,
|
||||
successMessage: '仓库更新成功',
|
||||
currentTab: 'list'
|
||||
});
|
||||
|
||||
// 重新加载仓库列表
|
||||
this.loadWarehouses();
|
||||
|
||||
showToast('仓库更新成功');
|
||||
|
||||
} catch (error) {
|
||||
console.error('更新仓库失败:', error);
|
||||
this.setData({
|
||||
loading: false,
|
||||
errorMessage: '更新仓库失败,请重试'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 验证编辑表单
|
||||
validateEditForm(): boolean {
|
||||
const { name, address, contact, phone } = this.data.editForm;
|
||||
|
||||
if (!name.trim()) {
|
||||
this.setData({
|
||||
errorMessage: '请输入仓库名称'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!address.trim()) {
|
||||
this.setData({
|
||||
errorMessage: '请输入仓库地址'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!contact?.trim()) {
|
||||
this.setData({
|
||||
errorMessage: '请输入联系人'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!phone?.trim()) {
|
||||
this.setData({
|
||||
errorMessage: '请输入联系电话'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
// 删除仓库
|
||||
async deleteWarehouse(e: any) {
|
||||
const warehouseId = e.currentTarget.dataset.id;
|
||||
|
||||
Reference in New Issue
Block a user