拜访区域和被访人增加联动
This commit is contained in:
@@ -15,10 +15,15 @@ Page({
|
||||
date: '',
|
||||
time: '',
|
||||
hostName: '',
|
||||
hostId: '',
|
||||
area: ''
|
||||
},
|
||||
areas: ['A区-生产车间', 'B区-办公楼', 'C区-仓储区', 'D区-研发中心', 'E区-综合区'],
|
||||
areaMap: { 'A区-生产车间': 'A', 'B区-办公楼': 'B', 'C区-仓储区': 'C', 'D区-研发中心': 'D', 'E区-综合区': 'E' },
|
||||
areaIndex: -1,
|
||||
persons: [],
|
||||
personNames: [],
|
||||
personIndex: -1,
|
||||
today: '',
|
||||
submitting: false
|
||||
},
|
||||
@@ -53,10 +58,53 @@ Page({
|
||||
|
||||
onAreaChange(e) {
|
||||
const index = Number(e.detail.value)
|
||||
const areaName = this.data.areas[index]
|
||||
const department = this.data.areaMap[areaName]
|
||||
this.setData({
|
||||
areaIndex: index,
|
||||
'form.area': this.data.areas[index]
|
||||
'form.area': areaName,
|
||||
'form.hostId': '',
|
||||
'form.hostName': '',
|
||||
persons: [],
|
||||
personNames: [],
|
||||
personIndex: -1
|
||||
})
|
||||
if (department) {
|
||||
this.loadPersons(department)
|
||||
}
|
||||
},
|
||||
|
||||
async loadPersons(department) {
|
||||
wx.showLoading({ title: '加载被访人中...' })
|
||||
try {
|
||||
const list = await appointmentDB.getPersonSelector(department)
|
||||
const persons = list.map(item => ({
|
||||
personId: item.personId,
|
||||
personName: item.personName
|
||||
}))
|
||||
this.setData({
|
||||
persons,
|
||||
personNames: persons.map(p => p.personName),
|
||||
personIndex: -1
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('获取被访人列表失败', err)
|
||||
wx.showToast({ title: '获取被访人列表失败', icon: 'none' })
|
||||
} finally {
|
||||
wx.hideLoading()
|
||||
}
|
||||
},
|
||||
|
||||
onPersonChange(e) {
|
||||
const index = Number(e.detail.value)
|
||||
const person = this.data.persons[index]
|
||||
if (person) {
|
||||
this.setData({
|
||||
personIndex: index,
|
||||
'form.hostId': person.personId,
|
||||
'form.hostName': person.personName
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
onDateChange(e) {
|
||||
@@ -94,7 +142,7 @@ Page({
|
||||
return false
|
||||
}
|
||||
if (!hostName.trim()) {
|
||||
wx.showToast({ title: '请输入被访人姓名', icon: 'none' })
|
||||
wx.showToast({ title: '请选择被访人', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!area) {
|
||||
|
||||
Reference in New Issue
Block a user