// pages/form/appeal/appeal.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:{ complainAdinSite:'美国站', complainedAdinSite:'美国站', isOriginal:true, complainedType:'商标', ifTalked:true }, labelWidth:350, imageUrl:'', //站点 countrys:[ { text: '美国站', value: '美国站' }, { text: '日本站', value: '日本站' }, { text: '德国站', value: '德国站' }, { text: '英国站', value: '英国站' }, ], //被投诉类型 complainedTypes:[ { 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() }, //上传文件 beforeUpload(e){ if(e.detail.errMsg=="chooseMedia:ok"){ // var data = [{ // status: 'done', // url: e.detail.tempFiles[0].tempFilePath, // }] var that = this this.setData({ imageUrl:e.detail.tempFiles[0].tempFilePath }) upload.upload(tempFilePaths).then(res=>{ if(res.code == 200){ var arr = [] arr.push(res.data[0]) that.setData( { ["form.fileGuids"]:arr } ) } }) } }, //输入备注 changRemark(e){ this.setData( { ["form.description"]:e.detail.value } ) }, //修改商品是否原创 onChange(e){ this.setData( { ["form.isOriginal"]:e.detail } ) }, //修改被投诉类型 onChange1(e){ this.setData( { ["form.complainedType"]:e.detail } ) }, //修改是否协商过 onChange3(e){ this.setData( { ["form.ifTalked"]:e.detail } ) }, //修改下拉菜单值 changeVanDropdownnValue(e){ var label = e.currentTarget.dataset.label if(label){ var detail = e.detail this.setData( { ["form."+label]:detail } ) } }, //提交工单 submit(){ var key = api.isLogin() if(!key){ return false } const { validateFields } = $wuxForm() validateFields((err, values) => { console.log(err) if (!err) { var params = { ticketType:3, contactPerson:this.data.form.contactPerson, contactPhone:this.data.form.contactPhone, contactMail:this.data.form.contactMail, fileGuids:this.data.form.fileGuids, respondingAddDTO:this.data.form } wx.showLoading({ title: '加载中', }) api.addTicket(params).then(res=>{ if(res.code == 200){ wx.navigateTo({ url: '/pages/successReminder/successReminder?id=3', }) } }) }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() { } })