拜访区域支持多选,被访人改为输入框,取消拜访区域和被访人的联动
This commit is contained in:
@@ -15,17 +15,13 @@ Page({
|
||||
date: '',
|
||||
time: '',
|
||||
hostName: '',
|
||||
hostId: '',
|
||||
personId: '',
|
||||
area: '',
|
||||
plateNumber: ''
|
||||
},
|
||||
areas: [],
|
||||
departments: [],
|
||||
areaIndex: -1,
|
||||
persons: [],
|
||||
personNames: [],
|
||||
personIndex: -1,
|
||||
areaOptions: [],
|
||||
selectedAreas: {},
|
||||
selectedAreasDisplay: '',
|
||||
showAreaDropdown: false,
|
||||
today: '',
|
||||
timeStart: '',
|
||||
timeEnd: '',
|
||||
@@ -47,23 +43,16 @@ Page({
|
||||
},
|
||||
|
||||
initPage() {
|
||||
// 使用本地时区获取当天日期,用于 picker 最小日期限制
|
||||
const today = formatDate(new Date())
|
||||
this.setData({ today })
|
||||
this.loadDepartments()
|
||||
this.loadAreaOptions()
|
||||
},
|
||||
|
||||
async loadDepartments() {
|
||||
async loadAreaOptions() {
|
||||
try {
|
||||
const list = await appointmentDB.getDepartmentSelector()
|
||||
const departments = list.map(item => ({
|
||||
departmentCode: item.departmentCode,
|
||||
departmentName: item.departmentName
|
||||
}))
|
||||
this.setData({
|
||||
departments,
|
||||
areas: departments.map(d => d.departmentName)
|
||||
})
|
||||
const areaOptions = list.map(item => item.departmentName)
|
||||
this.setData({ areaOptions })
|
||||
} catch (err) {
|
||||
console.error('获取拜访区域列表失败', err)
|
||||
wx.showToast({ title: '获取拜访区域失败', icon: 'none' })
|
||||
@@ -131,58 +120,21 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
onAreaChange(e) {
|
||||
const index = Number(e.detail.value)
|
||||
const department = this.data.departments[index]
|
||||
const departmentCode = department ? department.departmentCode : ''
|
||||
toggleAreaDropdown() {
|
||||
this.setData({ showAreaDropdown: !this.data.showAreaDropdown })
|
||||
},
|
||||
|
||||
toggleArea(e) {
|
||||
const value = e.currentTarget.dataset.value
|
||||
const selectedAreas = { ...this.data.selectedAreas }
|
||||
selectedAreas[value] = !selectedAreas[value]
|
||||
const display = Object.keys(selectedAreas).filter(k => selectedAreas[k]).join('、')
|
||||
this.setData({
|
||||
areaIndex: index,
|
||||
'form.area': department ? department.departmentName : '',
|
||||
'form.hostId': '',
|
||||
'form.hostName': '',
|
||||
'form.personId': '',
|
||||
persons: [],
|
||||
personNames: [],
|
||||
personIndex: -1
|
||||
selectedAreas,
|
||||
selectedAreasDisplay: display,
|
||||
'form.area': display
|
||||
})
|
||||
if (departmentCode) {
|
||||
this.loadPersons(departmentCode)
|
||||
}
|
||||
},
|
||||
|
||||
async loadPersons(department) {
|
||||
wx.showLoading({ title: '加载被访人中...' })
|
||||
try {
|
||||
const list = await appointmentDB.getPersonSelector(department)
|
||||
const persons = list.map(item => ({
|
||||
personId: item.personId,
|
||||
personName: item.personName,
|
||||
personId: item.personId
|
||||
}))
|
||||
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 && person.personId) {
|
||||
this.setData({
|
||||
personIndex: index,
|
||||
'form.hostId': person.personId,
|
||||
'form.hostName': person.personName,
|
||||
'form.personId': person.personId
|
||||
})
|
||||
}
|
||||
this._clearFieldError('area')
|
||||
},
|
||||
|
||||
onDateChange(e) {
|
||||
@@ -212,7 +164,7 @@ Page({
|
||||
},
|
||||
|
||||
validateForm() {
|
||||
const { name, phone, company, reason, date, time, hostName, area } = this.data.form
|
||||
const { name, phone, company, reason, date, time, area } = this.data.form
|
||||
if (!name.trim()) {
|
||||
wx.showToast({ title: '请输入访客姓名', icon: 'none' })
|
||||
return false
|
||||
@@ -237,10 +189,6 @@ Page({
|
||||
wx.showToast({ title: '请选择来访时间', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!hostName.trim()) {
|
||||
wx.showToast({ title: '请选择被访人', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (!area) {
|
||||
wx.showToast({ title: '请选择拜访区域', icon: 'none' })
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user