// pages/developer/join/index.js Page({ /** * 页面的初始数据 */ data: { languageLabels: [], frontLabels: [], backendLabels: [], otherLabels: [], languageSelected: [], frontSelected: [], backendSelected: [], otherSelected: [], languageSelectedMap: {}, frontSelectedMap: {}, backendSelectedMap: {}, otherSelectedMap: {}, desc: '', job: '', workYears: 0, contact: '', }, /** * 获取基础配置 */ getConfig() { wx.$util.request(wx.$api.CommonGetMiniConfig, {}, 'GET').then(res => { if (res.code === 1) { this.setData({ languageLabels: res.data.languageLabels || [], frontLabels: res.data.frontLabels || [], backendLabels: res.data.backendLabels || [], otherLabels: res.data.otherLabels || [], }); } }); }, onChipTap(e) { const { field, value } = e.currentTarget.dataset; const key = field + 'Selected'; const mapKey = field + 'SelectedMap'; const selected = this.data[key].slice(); const map = Object.assign({}, this.data[mapKey]); const idx = selected.indexOf(value); if (idx > -1) { selected.splice(idx, 1); delete map[value]; } else { selected.push(value); map[value] = true; } this.setData({ [key]: selected, [mapKey]: map }); }, onInputChange(e) { console.log(e) const value = e.detail.value; const { field } = e.currentTarget.dataset; // 获取 data-field 的值 console.log(value) console.log(field) this.setData({ [field]: value // 使用动态属性名设置值 }); }, onSubmit() { const { backendSelected, frontSelected, languageSelected, otherSelected, contact, job, workYears, desc } = this.data; const validations = [ { condition: !backendSelected.length && !frontSelected.length && !languageSelected.length && !otherSelected.length, message: '技能不能为空' }, { condition: !job.trim(), message: '职称不能为空' }, { condition: workYears == 0, message: '年限不能为空' }, { condition: !contact.trim(), message: '请填写联系方式' }, { condition: !desc.trim(), message: '简介不能为空' } ]; for (const validation of validations) { if (validation.condition) { wx.showToast({ title: validation.message, icon: 'error', duration: 2000 }); return; } } wx.requestSubscribeMessage({ tmplIds: ['0LRwQET1LgJohEok6EbcfMTnikuICe6-NZ7pc0WSbOY'], complete: (re) => { wx.$util.request(wx.$api.DeveloperSubmit, { backendSelected: backendSelected, frontSelected: frontSelected, languageSelected: languageSelected, otherSelected: otherSelected, job: job, contact: contact, work_years: workYears, desc: desc, }, 'POST').then(res => { if (res.code === 1) { wx.showModal({ title: '提示', showCancel: false, content: res.msg || '提交成功', success: (res2) => { if (res2.confirm) { wx.navigateBack({ delta: 1 }); } } }); } else { wx.showToast({ title: res.msg || '提交失败', icon: 'none', duration: 2000 }); } }); } }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getConfig(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })