// pages/form/riskAssessment/riskAssessment.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:{ unableExport:true }, labelWidth:350, }, /** * 生命周期函数--监听页面加载 */ 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) { // 返回选定文件的本地文件路径列表,tempFilePath可以作为文件上传的标识 const tempFilePaths = res.tempFilePaths[0]; upload(tempFilePaths).then(res=>{ console.log(res) }) } }); }, //输入备注 changRemark(e){ this.setData( { ["form.description"]:e.detail.value } ) }, //修改专利无法导出? onChange(e){ this.setData( { ["form.patentExport"]:e.detail } ) }, //提交工单 submit(){ var key = api.isLogin() if(!key){ return false } const { validateFields } = $wuxForm() validateFields((err, values) => { console.log(err) if (!err) { var params = { ticketType:1, contactPerson:this.data.form.contactPerson, contactPhone:this.data.form.contactPhone, contactMail:this.data.form.contactMail, fileGuids:this.data.form.fileGuids, ticketFillInAddDTO:this.data.form } api.addTicket(params).then(res=>{ if(res.code == 200){ wx.navigateTo({ url: '/pages/successReminder/successReminder?id=1', }) } }) }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() { } })