拜访区域和被访人增加联动

This commit is contained in:
chenglijuan
2026-04-28 15:30:05 +08:00
parent 533edb56bf
commit 1ba5ea1084
4 changed files with 81 additions and 8 deletions
+50 -2
View File
@@ -15,10 +15,15 @@ Page({
date: '', date: '',
time: '', time: '',
hostName: '', hostName: '',
hostId: '',
area: '' area: ''
}, },
areas: ['A区-生产车间', 'B区-办公楼', 'C区-仓储区', 'D区-研发中心', 'E区-综合区'], areas: ['A区-生产车间', 'B区-办公楼', 'C区-仓储区', 'D区-研发中心', 'E区-综合区'],
areaMap: { 'A区-生产车间': 'A', 'B区-办公楼': 'B', 'C区-仓储区': 'C', 'D区-研发中心': 'D', 'E区-综合区': 'E' },
areaIndex: -1, areaIndex: -1,
persons: [],
personNames: [],
personIndex: -1,
today: '', today: '',
submitting: false submitting: false
}, },
@@ -53,10 +58,53 @@ Page({
onAreaChange(e) { onAreaChange(e) {
const index = Number(e.detail.value) const index = Number(e.detail.value)
const areaName = this.data.areas[index]
const department = this.data.areaMap[areaName]
this.setData({ this.setData({
areaIndex: index, 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) { onDateChange(e) {
@@ -94,7 +142,7 @@ Page({
return false return false
} }
if (!hostName.trim()) { if (!hostName.trim()) {
wx.showToast({ title: '请输入被访人姓名', icon: 'none' }) wx.showToast({ title: '请选择被访人', icon: 'none' })
return false return false
} }
if (!area) { if (!area) {
+13 -4
View File
@@ -47,10 +47,6 @@
<!-- 被访人信息 --> <!-- 被访人信息 -->
<view class="section"> <view class="section">
<view class="section-title">被访人信息</view> <view class="section-title">被访人信息</view>
<view class="form-group">
<text class="form-label">被访人</text>
<input class="form-input" placeholder="请输入被访人姓名" value="{{form.hostName}}" bindinput="onHostNameInput" />
</view>
<view class="form-group"> <view class="form-group">
<text class="form-label">拜访区域</text> <text class="form-label">拜访区域</text>
<picker class="form-picker-wrap" range="{{areas}}" value="{{areaIndex}}" bindchange="onAreaChange"> <picker class="form-picker-wrap" range="{{areas}}" value="{{areaIndex}}" bindchange="onAreaChange">
@@ -60,6 +56,19 @@
</view> </view>
</picker> </picker>
</view> </view>
<view class="form-group">
<text class="form-label">被访人</text>
<picker wx:if="{{personNames.length > 0}}" class="form-picker-wrap" range="{{personNames}}" value="{{personIndex}}" bindchange="onPersonChange">
<view class="form-picker">
<text class="{{personIndex >= 0 ? 'picker-value' : 'picker-placeholder'}}">{{personIndex >= 0 ? personNames[personIndex] : '请选择被访人'}}</text>
<text class="picker-arrow"></text>
</view>
</picker>
<view wx:else class="form-picker">
<text class="picker-placeholder">请先选择拜访区域</text>
</view>
</view>
</view> </view>
<!-- 提交按钮 --> <!-- 提交按钮 -->
+14
View File
@@ -183,6 +183,20 @@ const appointmentDB = {
data: { id } data: { id }
}) })
return mapApiRecord(data) || null return mapApiRecord(data) || null
},
/**
* 获取被访人列表
* @param {string} department - 部门/区域编码
* @returns {Promise<Array>} 被访人列表
*/
async getPersonSelector(department) {
const data = await request({
url: BASE_URL + API.PERSON_SELECTOR,
method: 'GET',
data: { department }
})
return data || []
} }
} }
+4 -2
View File
@@ -6,7 +6,8 @@ const ENV_CONFIG = {
// release: 'https://xcx.yun.588580.xyz', // release: 'https://xcx.yun.588580.xyz',
trial: 'https://qywx.yun.588580.xyz', trial: 'https://qywx.yun.588580.xyz',
// 开发版 & 体验版 // 开发版 & 体验版
develop: 'http://172.16.60.235:8080' // develop: 'http://172.16.60.235:8080'
develop: 'http://10.50.13.191:8080'
} }
// 自动判断当前运行环境 // 自动判断当前运行环境
@@ -27,7 +28,8 @@ const API = {
APPOINTMENT_CREATE: '/api/wx-mini/appointment/create', APPOINTMENT_CREATE: '/api/wx-mini/appointment/create',
APPOINTMENT_CANCEL: '/api/wx-mini/appointment/cancel', APPOINTMENT_CANCEL: '/api/wx-mini/appointment/cancel',
APPOINTMENT_DETAIL: '/api/wx-mini/appointment/detail', APPOINTMENT_DETAIL: '/api/wx-mini/appointment/detail',
WXACODE: '/api/wx-mini/wxacode' WXACODE: '/api/wx-mini/wxacode',
PERSON_SELECTOR: '/api/wx-mini/appointment/person/selector'
} }
console.log('[config] 当前环境:', wx.getAccountInfoSync().miniProgram.envVersion, 'BASE_URL:', BASE_URL) console.log('[config] 当前环境:', wx.getAccountInfoSync().miniProgram.envVersion, 'BASE_URL:', BASE_URL)