// pages/form/application/application.js const upload = require("../../../utils/upload") const api = require('../../../api/index') import { $wuxForm} from '../../../miniprogram_npm/wux-weapp/index' Page({ /** * 页面的初始数据 */ data: { validateMessages: { required: '%s 字段为必填', }, form:{ appType:'发明专利', appAbroad:true, appApostille:true, }, labelWidth:350, typeOptions:[ { text: '发明专利', value: '发明专利' }, { text: '外观设计', value: '外观设计' }, { text: '实用新型', value: '实用新型' }, { text: '商标', value: '商标' }, { text: '版权', value: '版权' }, ] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 页面方法集合 */ //表单栏位值发生变化时 onValuesChange(e) { console.log(e) const { changedValues, allValues } = e.detail // this.setValues(changedValues) Object.keys(changedValues).forEach((field) => { this.setData({ ['form.'+field]: changedValues[field], }) }) console.log('onValuesChange \n', changedValues, allValues) }, //手机号校验 checkPhone(rule, value){ if(!value){ return Promise.reject(new Error('手机号不能为空!')) } const isTel = (value) => /^1[34578]\d{9}$/.test(value) if(!isTel(value)){ return Promise.reject(new Error('手机号输入错误!')) } return Promise.resolve() }, //上传文件 uploadFile(){ const that = this; wx.chooseMessageFile({ count: 1, // 默认9,表示一次最多可以选择的文件个数 type: 'file', // 可以指定是文件 success(res) { console.log(res) // 返回选定文件的本地文件路径列表,tempFilePath可以作为文件上传的标识 const tempFilePaths = res.tempFiles[0].path; upload.upload(tempFilePaths).then(res=>{ if(res.code == 200){ var arr = this.data.form.fileGuids if(!arr){ arr = [] } arr.push(res.data[0]) this.setData( { ["form.fileGuids"]:arr } ) } }) } }); }, //输入备注 changRemark(e){ this.setData( { ["form.description"]:e.detail.value } ) }, //修改是否海外申请 onChange(e){ this.setData( { ["form.appAbroad"]:e.detail } ) }, //修改一同申请海牙认证 onChange1(e){ this.setData( { ["form.appApostille"]:e.detail } ) }, //修改下拉菜单值 changeVanDropdownnValue(e){ var label = e.currentTarget.dataset.label if(label){ var detail = e.detail this.setData( { ["form."+label]:detail } ) } }, //提交工单 submit(){ const { validateFields } = $wuxForm() var key = api.isLogin() if(!key){ return false } validateFields((err, values) => { console.log(err) if (!err) { var params = { ticketType:4, contactPerson:this.data.form.contactPerson, contactPhone:this.data.form.contactPhone, contactMail:this.data.form.contactMail, fileGuids:this.data.form.fileGuids, ticketPatentApplyAddDTO:this.data.form } api.addTicket(params).then(res=>{ if(res.code == 200){ wx.navigateTo({ url: '/pages/successReminder/successReminder?id=4', }) } }) }else{ var error = Object.keys(err) var key = error[0] var len = err[key].errors.length var message = err[key].errors[len-1].message wx.showModal({ title: '提示', content: message, complete: (res) => { if (res.cancel) { } if (res.confirm) { } } }) } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })