const API = require('../../utils/api.js') Page({ data: { service: { id: null, title: '', subtitle: '', price: '0.00', image: '', tag: '', description: '', flow: [], notices: [] }, totalPrice: '0.00', showOrderPopup: false, patientName: '', patientPhone: '', province: '', provinceIndex: 0, provinces: ['北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省', '河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市', '四川省', '贵州省', '云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区', '台湾省', '香港特别行政区', '澳门特别行政区'], hospital: '', appointmentDate: '', appointmentTime: '', remark: '', today: '', gender: '不限', genderIndex: 0, genderOptions: ['不限', '男', '女'], department: '', departments: ['内科', '外科', '妇产科', '儿科', '骨科', '神经科', '心血管内科', '消化内科', '呼吸内科', '内分泌科', '皮肤科', '眼科', '耳鼻喉科', '口腔科', '急诊科', '肿瘤科', '康复医学科', '老年病科', '中医科', '针灸推拿科'], hospitals: [] }, onLoad(options) { const today = new Date() const year = today.getFullYear() const month = String(today.getMonth() + 1).padStart(2, '0') const day = String(today.getDate()).padStart(2, '0') const todayStr = `${year}-${month}-${day}` this.setData({ today: todayStr }) const serviceId = parseInt(options.id) || 1 this.loadServiceDetail(serviceId) }, loadServiceDetail(id) { const app = getApp() let service = null for (const item of app.globalData.services) { if (item.id === id) { service = item break } } if (!service) { return } const totalPrice = this.calculateTotal(service.price, 1) this.setData({ service: service, totalPrice: totalPrice }) }, calculateTotal(price) { return price }, openOrderPopup() { const app = getApp() if (!app.globalData.user) { wx.showToast({ title: '请先登录', icon: 'none' }) return } const user = app.globalData.user this.setData({ patientName: user.profile?.name || '', patientPhone: user.profile?.mobile || '', showOrderPopup: true }) }, closeOrderPopup() { this.setData({ showOrderPopup: false }) }, onPatientNameChange(e) { this.setData({ patientName: e.detail.value }) }, onPatientPhoneChange(e) { this.setData({ patientPhone: e.detail.value }) }, onProvinceChange(e) { const index = e.detail.value const province = this.data.provinces[index] this.setData({ provinceIndex: index, province: province }) }, onHospitalChange(e) { this.setData({ hospital: e.detail.value }) }, onDepartmentChange(e) { this.setData({ department: e.detail.value }) }, onDateChange(e) { this.setData({ appointmentDate: e.detail.value }) }, onTimeChange(e) { this.setData({ appointmentTime: e.detail.value }) }, onGenderChange(e) { const index = e.detail.value const gender = this.data.genderOptions[index] this.setData({ genderIndex: index, gender: gender }) }, onRemarkChange(e) { this.setData({ remark: e.detail.value }) }, submitOrder() { const { service, patientName, patientPhone, province, hospital, department, appointmentDate, appointmentTime, gender, remark } = this.data if (!patientName.trim()) { wx.showToast({ title: '请输入就诊人姓名', icon: 'none' }) return } if (!patientPhone.trim()) { wx.showToast({ title: '请输入联系电话', icon: 'none' }) return } if (!hospital.trim()) { wx.showToast({ title: '请输入就诊医院', icon: 'none' }) return } if (!department.trim()) { wx.showToast({ title: '请输入就诊科室', icon: 'none' }) return } if (!appointmentDate) { wx.showToast({ title: '请选择预约日期', icon: 'none' }) return } if (!appointmentTime) { wx.showToast({ title: '请选择预约时间', icon: 'none' }) return } const phoneRegex = /^1[3-9]\d{9}$/ if (!phoneRegex.test(patientPhone.trim())) { wx.showToast({ title: '请输入正确的手机号', icon: 'none' }) return } const app = getApp() const user = app.globalData.user let sex = "none" if (gender == '男') sex = 'male' else if (gender == '女') sex = 'female' const orderData = { userId: user._id, patient: { name: patientName.trim(), mobile: patientPhone.trim(), }, escort: { serviceId: service.id, serviceName: service.title, sexRequirement: sex }, hospital: { province: province, name: hospital.trim(), department: department.trim(), }, schedule: { date: appointmentDate, startTime: appointmentTime }, payment: { totalFee: service.price }, notes: { patientNote: remark.trim() } } wx.showLoading({ title: '提交中...' }) API.escort.createRecord(orderData) .then((data) => { wx.hideLoading() if (data.code === 0) { wx.showToast({ title: '下单成功', icon: 'success' }) this.setData({ showOrderPopup: false }) this.resetForm() wx.navigateTo({url: '/pages/escort/recordlist?tab=pending'}) } else { wx.showToast({ title: data.msg || '下单失败', icon: 'none' }) } }) .catch((err) => { wx.hideLoading() wx.showToast({ title: '网络请求失败', icon: 'none' }) console.log('下单失败', err) }) }, resetForm() { this.setData({ patientName: '', patientPhone: '', province: '', provinceIndex: 0, hospital: '', department: '', appointmentDate: '', appointmentTime: '', gender: '', genderIndex: 0, remark: '' }) const totalPrice = this.calculateTotal(this.data.service.price) this.setData({ totalPrice: totalPrice }) }, onShareAppMessage() { const { service } = this.data return { title: `${service.title} - 专业陪诊服务`, path: `/pages/escort/itemdetail?id=${service.id}` } } })