// packageDomain/pages/publickBookForm/index.js const app = getApp(); import tool from "../../../assets/js/toolClass.js"; import { loginInfo } from '../../../assets/js/login'; Page({ /** * 页面的初始数据 */ data: { teacherInfo: { topicName: '', //选题名称 declarer: '', //申报人 declarationUnit: '', //"申报单位" disciplineMajor: '', //学科专业 authorBasicInformation: '', //"作者基本情况 phone: '', //联系电话 email: '', //联系邮箱 targetReaders: '', //读者对象 topicFeatures: '', //选题特色 topicImpactAndExpected: '', //选题学术影响与预期社会效益 topicProgress: '', //选题的进度安排 marketAnalysis: '', //市场分析 marketingAndPromotionPlan: '', //营销与宣传推广计划 digitalResourceDevelopmentPlan: '', //配套数字资源开发方案 otherExistingIssues: '' //存在的其他问题 }, worksInfo: [], keyboardHeight: 0, autosize: { maxHeight: 120, minHeight: 80, }, phoneError: false, emailError: false, loading: false, isKeyboard: false }, /** * 生命周期函数--监听页面加载 */ onLoad() { const token = wx.getStorageSync(app.config.tokenKey) if (!token) { loginInfo(app, (data) => { if (data) {} }) } else {} this.getType() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, scroll() { // 监听视图滚动,手动收起键盘 if (this.data.isKeyboard) { wx.hideKeyboard() } }, // 监听键盘弹起和收起 bindkeyboardheightchange(e) { // 键盘高度 const height = e.detail.height; this.setData({ isKeyboard: height ? true : false }) }, //获取字段 getType() { app.MG.resource.getCmsTypeByRefCode({ refCodes: ['jsek_publicationApplication'] }).then((res) => { this.setData({ worksInfo: res[0].cmsTypeLinks[0].children, }) }) }, onTopicNameInput(e) { this.setData({ "teacherInfo.topicName": e.detail.value, }); }, onDeclarerInput(e) { this.setData({ "teacherInfo.declarer": e.detail.value, }); }, ondeclarationUnitInput(e) { this.setData({ "teacherInfo.declarationUnit": e.detail.value, }); }, onDisciplineMajorInput(e) { this.setData({ "teacherInfo.disciplineMajor": e.detail.value, }); }, onAuthorBasicInfoInput(e) { this.setData({ "teacherInfo.authorBasicInformation": e.detail.value, }); }, //输入手机号 onPhoneInput(e) { const { phoneError } = this.data; if (e.detail.value) { const isPhoneNumber = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(e.detail.value); if (phoneError === isPhoneNumber) { this.setData({ phoneError: !isPhoneNumber, "teacherInfo.phone": e.detail.value, }); } } else { this.setData({ phoneError: false, }); } }, onEmailInput(e) { const { emailError } = this.data; if (e.detail.value) { const isPhoneNumber = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(e.detail.value); if (emailError === isPhoneNumber) { this.setData({ emailError: !isPhoneNumber, "teacherInfo.email": e.detail.value, }); } } else { this.setData({ emailError: false, }); } }, onTargetReadersInput(e) { this.setData({ "teacherInfo.targetReaders": e.detail.value, }); }, onTopicFeaturesInput(e) { this.setData({ "teacherInfo.topicFeatures": e.detail.value, }); }, onTopicImpactAndExpectedInput(e) { this.setData({ "teacherInfo.topicImpactAndExpected": e.detail.value, }); }, onTopicProgressInput(e) { this.setData({ "teacherInfo.topicProgress": e.detail.value, }); }, onMarketAnalysisInput(e) { this.setData({ "teacherInfo.marketAnalysis": e.detail.value, }); }, onMarketingAndPromotionPlanInput(e) { this.setData({ "teacherInfo.marketingAndPromotionPlan": e.detail.value, }); }, ondigitalResourceInput(e) { this.setData({ "teacherInfo.digitalResourceDevelopmentPlan": e.detail.value, }); }, onOtherExistingIssuesInput(e) { this.setData({ "teacherInfo.otherExistingIssues": e.detail.value, }); }, submit() { let that = this; if (!that.data.teacherInfo.topicName) { wx.showToast({ title: "请填写选题名称!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.declarer) { wx.showToast({ title: "请填写申报人姓名!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.declarationUnit) { wx.showToast({ title: "请填写申报单位!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.disciplineMajor) { wx.showToast({ title: "请填写学科专业!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.authorBasicInformation) { wx.showToast({ title: "请填写作者基本情况!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.phone) { wx.showToast({ title: "请填写联系电话!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.email) { wx.showToast({ title: "请填写联系邮箱!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.targetReaders) { wx.showToast({ title: "请填写读者对象!", icon: 'none', duration: 1000, }) return } if (!that.data.teacherInfo.topicFeatures) { wx.showToast({ title: "请填写选题特色!", icon: 'none', duration: 1000, }) return } that.setData({ loading: true, }); const data = { topicIdOrRefCode: 'bookApplication', name: that.data.teacherInfo.topicName, content: '', state: 'WaitAudit', type: 'bookApplication', cmsTypeRefCode: 'jsek_publicationApplication', newDataListRequest: tool.worksDataBytool(that.data.worksInfo, that.data.teacherInfo) } let basicInfo = JSON.parse(JSON.stringify(that.data.teacherInfo)) delete basicInfo.worksInfo delete basicInfo.state app.MG.ugc.newTopicMessage(data).then((res) => { console.log(res) if (res) { wx.showToast({ title: "提交成功!请等待联系...", icon: 'none', duration: 1000, }) that.setData({ loading: false, "teacherInfo.topicName": '', "teacherInfo.declarer": '', "teacherInfo.declarationUnit": '', "teacherInfo.disciplineMajor": '', "teacherInfo.authorBasicInformation": '', "teacherInfo.phone": '', "teacherInfo.email": '', "teacherInfo.targetReaders": '', "teacherInfo.topicImpactAndExpected": '', "teacherInfo.topicProgress": '', "teacherInfo.topicFeatures": '', "teacherInfo.marketAnalysis": '', "teacherInfo.marketingAndPromotionPlan": '', "teacherInfo.digitalResourceDevelopmentPlan": '', "teacherInfo.otherExistingIssues": '', }); } }) } })