Files
kuaiying_wx/pages/video_list/video_list.js

220 lines
5.1 KiB
JavaScript
Raw Normal View History

2025-03-04 15:25:38 +08:00
const app = getApp();
Page({
data: {
2025-08-15 10:49:43 +08:00
requirementTypes: [
{ value: 'new_feature', label: '新功能需求' },
{ value: 'cooperation', label: '合作需求' },
{ value: 'advertising', label: '广告投放' },
{ value: 'miniapp_dev', label: '小程序开发' },
{ value: 'software_custom', label: '软件定制' },
{ value: 'other', label: '其他需求' }
],
selectedType: '', // 选中的需求类型
title: '', // 需求标题
description: '', // 功能描述
contactInfo: '', // 联系方式(微信号)
submitButtonDisabled: false, // 提交按钮是否禁用
showTypeSelector: false // 是否显示类型选择器
2025-03-04 15:25:38 +08:00
},
onLoad: function(e) {
},
onShow: function() {
var t = this;
2025-08-15 10:49:43 +08:00
t.resetData();
2025-03-04 15:25:38 +08:00
app.getCurrentTabbar(2, this);
app.checkUpdateVersion();
app.getUserInfo().then(() => {
console.log('获取用户信息完成');
}).catch(error => {
console.error('获取用户信息失败:', error);
}).finally(() => {
console.log('getUserInfo调用完成');
});
},
2025-08-15 10:49:43 +08:00
2025-03-04 15:25:38 +08:00
resetData: function() {
// 重置页面数据为默认值
this.setData({
2025-08-15 10:49:43 +08:00
selectedType: '',
title: '',
description: '',
contactInfo: '',
submitButtonDisabled: false,
showTypeSelector: false
2025-03-04 15:25:38 +08:00
});
},
2025-08-15 10:49:43 +08:00
// 显示需求类型选择器
showTypeSelector() {
2025-03-04 15:25:38 +08:00
this.setData({
2025-08-15 10:49:43 +08:00
showTypeSelector: true
2025-03-04 15:25:38 +08:00
});
2025-08-15 10:49:43 +08:00
},
2025-03-04 15:25:38 +08:00
2025-08-15 10:49:43 +08:00
// 隐藏需求类型选择器
hideTypeSelector() {
this.setData({
showTypeSelector: false
});
},
// 选择需求类型
selectType(e) {
const type = e.currentTarget.dataset.type;
const label = e.currentTarget.dataset.label;
this.setData({
selectedType: type,
selectedTypeLabel: label,
showTypeSelector: false
});
},
// 处理标题输入
onTitleInput(e) {
this.setData({
title: e.detail.value
});
},
// 处理描述输入
onDescriptionInput(e) {
this.setData({
description: e.detail.value
});
},
// 处理联系方式输入
onContactInput(e) {
this.setData({
contactInfo: e.detail.value
});
},
// 验证表单
validateForm() {
const { selectedType, description, contactInfo } = this.data;
if (!selectedType) {
2025-03-04 15:25:38 +08:00
wx.showToast({
2025-08-15 10:49:43 +08:00
title: '请选择需求类型',
2025-03-04 15:25:38 +08:00
icon: 'none'
});
2025-08-15 10:49:43 +08:00
return false;
2025-03-04 15:25:38 +08:00
}
2025-08-15 10:49:43 +08:00
if (!description.trim()) {
2025-03-04 15:25:38 +08:00
wx.showToast({
2025-08-15 10:49:43 +08:00
title: '请填写功能描述',
2025-03-04 15:25:38 +08:00
icon: 'none'
});
2025-08-15 10:49:43 +08:00
return false;
2025-03-04 15:25:38 +08:00
}
2025-08-15 10:49:43 +08:00
if (!contactInfo.trim()) {
2025-03-04 15:25:38 +08:00
wx.showToast({
2025-08-15 10:49:43 +08:00
title: '请填写微信号',
2025-03-04 15:25:38 +08:00
icon: 'none'
});
2025-08-15 10:49:43 +08:00
return false;
}
return true;
},
// 提交需求
submitRequirement() {
if (!this.validateForm()) {
2025-03-04 15:25:38 +08:00
return;
}
2025-08-15 10:49:43 +08:00
// 禁用提交按钮
this.setData({ submitButtonDisabled: true });
2025-03-04 15:25:38 +08:00
wx.showLoading({
2025-08-15 10:49:43 +08:00
title: '正在提交...',
2025-03-04 15:25:38 +08:00
});
2025-08-15 10:49:43 +08:00
const { selectedType, title, description, contactInfo } = this.data;
// 调用后端需求提交接口
2025-03-04 15:25:38 +08:00
app.apiRequest({
2025-08-15 10:49:43 +08:00
url: '/myapp/submit_requirement/',
2025-03-04 15:25:38 +08:00
method: 'POST',
data: {
openid: wx.getStorageSync('openid'),
2025-08-15 10:49:43 +08:00
nickname: wx.getStorageSync('uuid'),
requirement_type: selectedType,
title: title,
description: description,
contact_info: contactInfo,
wechat_id: contactInfo // 使用同一个值作为微信号
2025-03-04 15:25:38 +08:00
},
success: (res) => {
wx.hideLoading();
2025-08-15 10:49:43 +08:00
this.setData({ submitButtonDisabled: false });
if (res.data.success) {
2025-03-04 15:25:38 +08:00
wx.showModal({
2025-08-15 10:49:43 +08:00
title: "提交成功",
content: res.data.message || "需求提交成功,我们会尽快处理您的需求",
showCancel: false,
confirmText: "确定",
success: () => {
// 重置表单
this.resetData();
2025-03-04 15:25:38 +08:00
}
});
} else {
wx.showToast({
2025-08-15 10:49:43 +08:00
title: res.data.error || '提交失败,请稍后重试',
2025-03-04 15:25:38 +08:00
icon: 'none'
});
}
},
fail: (err) => {
wx.hideLoading();
2025-08-15 10:49:43 +08:00
this.setData({ submitButtonDisabled: false });
2025-03-04 15:25:38 +08:00
console.error('请求失败:', err);
2025-08-15 10:49:43 +08:00
// 处理常见错误
if (err.statusCode === 400) {
2025-03-04 15:25:38 +08:00
wx.showToast({
2025-08-15 10:49:43 +08:00
title: '请检查填写信息',
2025-03-04 15:25:38 +08:00
icon: 'none'
});
2025-08-15 10:49:43 +08:00
} else if (err.statusCode === 404) {
2025-03-04 15:25:38 +08:00
wx.showToast({
2025-08-15 10:49:43 +08:00
title: '用户信息异常,请重新登录',
icon: 'none'
2025-03-04 15:25:38 +08:00
});
} else {
wx.showToast({
2025-08-15 10:49:43 +08:00
title: '网络异常,请稍后重试',
2025-03-04 15:25:38 +08:00
icon: 'none'
});
}
}
});
},
2025-08-15 10:49:43 +08:00
// 清空表单
clearForm() {
wx.showModal({
title: "提示",
content: "确定要清空所有内容吗?",
2025-03-04 15:25:38 +08:00
success: (res) => {
2025-08-15 10:49:43 +08:00
if (res.confirm) {
this.resetData();
wx.showToast({
title: '已清空内容',
icon: 'none'
});
}
2025-03-04 15:25:38 +08:00
}
});
}
});