// pages/Crew/Crew.js Page({ data: { name:'Crew', selectedTime: '--时--分', selectedDate: '--年--月--日', selectedIndex1: 0, selectedIndex2: 0, selectedIndex5: 0, selectedIndex9: 0, inputValue1: '', inputValue2: '', inputValue3: '', inputValue4: '', inputValue5: '', inputValue9: '', inputValue10: '', inputValue11: '', inputValue12: '', inputValue13: '', inputValue14: '', inputValue20: '', inputValue21: '', inputValue22: '', inputValue23: '', timezones: ['请选择','UTC-12:00', 'UTC-11:00', 'UTC-10:00', 'UTC-9:00', 'UTC-8:00', 'UTC-7:00', 'UTC-6:00', 'UTC-5:00', 'UTC-4:00', 'UTC-3:00', 'UTC-2:00', 'UTC-1:00', 'UTC+0:00', 'UTC+1:00', 'UTC+2:00', 'UTC+3:00', 'UTC+4:00', 'UTC+5:00', 'UTC+6:00', 'UTC+7:00', 'UTC+8:00', 'UTC+9:00', 'UTC+10:00', 'UTC+11:00', 'UTC+12:00'], position:['请选择','乘务员','主任乘务长','乘务教员','乘务检查员','保安员','其他'], ACFT:['请选择','飞机','直升机','滑翔机','其它'], phase:['请选择','地面/滑行','起飞','爬升','巡航/作业','下降','进近','复飞','着陆','其它'], }, //时间选择 onTimeChange: function (event) { this.setData({ selectedTime: event.detail.value }); }, onTimezoneChange: function (event) { this.setData({ selectedIndex1: event.detail.value }); }, onDateChange: function(e) { this.setData({ selectedDate: e.detail.value }); }, //工作时间选择 onInput1: function(event) { this.setData({ inputValue1: event.detail.value }); }, onInput2: function(event) { this.setData({ inputValue2: event.detail.value }); }, onInput3: function(event) { this.setData({ inputValue3: event.detail.value }); }, //岗位选择 onposition: function (event) { this.setData({ selectedIndex2: event.detail.value }); }, //飞行经历 onInput4: function(event) { this.setData({ inputValue4: event.detail.value }); }, onInput5: function(event) { this.setData({ inputValue5: event.detail.value }); }, //飞行区间 onInput9: function(event) { this.setData({ inputValue9: event.detail.value }); }, onInput10: function(event) { this.setData({ inputValue10: event.detail.value }); }, //航空器种类 onACFT: function(event) { this.setData({ selectedIndex5: event.detail.value }); }, //人员情况 onInput11: function(event) { this.setData({ inputValue11: event.detail.value }); }, onInput12: function(event) { this.setData({ inputValue12: event.detail.value }); }, onInput13: function(event) { this.setData({ inputValue13: event.detail.value }); }, onInput14: function(event) { this.setData({ inputValue14: event.detail.value }); }, //飞行阶段 onphase: function(event) { this.setData({ selectedIndex9: event.detail.value }); }, //事件经过 onInput20: function(event) { this.setData({ inputValue20: event.detail.value }); }, //个人信息//姓名电话邮箱 onInput21: function(event) { this.setData({ inputValue21: event.detail.value }); }, onInput22: function(event) { this.setData({ inputValue22: event.detail.value }); }, onInput23: function(event) { this.setData({ inputValue23: event.detail.value }); }, //提交与重写 onReset() { this.setData({ selectedTime: '--时--分', selectedDate: '--年--月--日', selectedIndex1: 0, selectedIndex2: 0, selectedIndex5: 0, selectedIndex9: 0, inputValue1: '', inputValue2: '', inputValue3: '', inputValue4: '', inputValue5: '', inputValue9: '', inputValue10: '', inputValue11: '', inputValue12: '', inputValue13: '', inputValue14: '', inputValue20: '', inputValue21: '', inputValue22: '', inputValue23: '', },() => { console.log('Form has been reset'); }) }, // 提交数据 onSubmit: function () { // 获取存储中的 token const token = wx.getStorageSync('token'); if (!token) { console.log('Token 不存在,请先登录'); wx.showToast({ title: '请先登录', icon: 'none' }); return; // 终止提交 } const data = this.data; // 获取各选择项的实际文本值 const timezoneText = data.timezones[data.selectedIndex1]; // 获取时区的实际文本 const workPositionText = data.position[data.selectedIndex2]; // 获取岗位的实际文本 const acftText = data.ACFT[data.selectedIndex5]; // 获取航空器类型的实际文本 const phaseText = data.phase[data.selectedIndex9]; // 获取飞行阶段的实际文本 // 提交数据到后端 wx.request({ url: 'http://192.168.137.1:8080/report/add', method: 'POST', header: { 'Authorization': `${token}`, 'content-type': 'application/json' }, data: { selectedTime: data.selectedTime, selectedDate: data.selectedDate, timezone: timezoneText, // 提交时区的实际文本 workPosition: workPositionText,// 提交岗位的实际文本 acftType: acftText, // 提交航空器类型的实际文本 phase: phaseText, // 提交飞行阶段的实际文本 inputValue1: data.inputValue1, inputValue2: data.inputValue2, inputValue3: data.inputValue3, inputValue4: data.inputValue4, inputValue5: data.inputValue5, inputValue9: data.inputValue9, inputValue10: data.inputValue10, inputValue11: data.inputValue11, inputValue12: data.inputValue12, inputValue13: data.inputValue13, inputValue14: data.inputValue14, inputValue20: data.inputValue20, inputValue21: data.inputValue21, inputValue22: data.inputValue22, inputValue23: data.inputValue23, name: data.name, }, success: function(res) { console.log('Data submitted successfully:', res); }, fail: function(err) { console.error('Error submitting data:', err); } }); // 使用腾讯混元智能体的 API 调用 wx.request({ url: 'https://yuanqi.tencent.com/openapi/v1/agent/chat/completions', method: 'POST', header: { 'X-Source': 'openapi', 'Content-Type': 'application/json', 'Authorization': 'Bearer jSNTZONSnnzJ2uuQT7IEgXlPzfE4lX5f' // 替换为你的实际 Bearer Token }, data: { assistant_id: 'ty1W9unZM9IY', // 替换为实际的 assistant_id user_id: '123456', // 替换为实际的用户ID stream: false, messages: [ { role: 'user', content: [ { type: 'text', text: JSON.stringify(data) // 将用户填写的数据转换为字符串 } ] } ] }, success: function (res) { console.log('API 调用成功: ', res); // 打印完整的 API 响应 console.log('API 返回的 choices:', res.data.choices); // 检查数据结构 // 检查选择项并从中提取智能体回复 if (res.data && res.data.choices && res.data.choices.length > 0) { // 确保 message 字段的内容可以被访问 const messageContent = res.data.choices[0].message?.content; let agentReply; // 如果 messageContent 存在并且是一个数组,则提取内容 if (Array.isArray(messageContent) && messageContent.length > 0) { agentReply = messageContent[0].text; // 假设内容在数组的第一个元素中 } else { agentReply = messageContent || '无法获取智能体的回复'; } // 跳转到详情页面并传递数据和智能体的回复 wx.navigateTo({ url: '/pages/FlightCrewDetails/FlightCrewDetails', success: function (navRes) { navRes.eventChannel.emit('sendData', { details: data, // 用户输入的数据 agentReply: agentReply // 智能体的回复 }); } }); } else { console.log('API 响应中没有 choices'); } }, fail: function (err) { console.log('智能体调用失败', err); } }); }, onLoad(options) { }, onReady() { }, onShow() { }, onHide() { }, onUnload() { }, onPullDownRefresh() { }, onReachBottom() { }, onShareAppMessage() { } })