// pages/form/rightsProtection/rightsProtection.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:{ tortStoreAdinSite:'美国站', tortType:'发明专利', tortClassify:'产品侵权', ifHaveRightProof:true, problemDescription:'商品详细页上使用了未经授权的图片' }, labelWidth:200, //站点 countrys:[ { text: '美国站', value: '美国站' }, { text: '日本站', value: '日本站' }, { text: '德国站', value: '德国站' }, { text: '英国站', value: '英国站' }, ], //侵权类型 typeOptions:[ { text: '发明专利', value: '发明专利' }, { text: '外观设计', value: '外观设计' }, { text: '实用新型', value: '实用新型' }, { text: '商标', value: '商标' }, { text: '版权', value: '版权' }, ], //侵权分类 typeOptions2:[ { text: '产品侵权', value: '产品侵权' }, { text: '图片侵权', value: '图片侵权' }, { text: '背景侵权', value: '背景侵权' }, { text: '文字侵权', value: '文字侵权' }, ], //问题描述 problemDescriptions:[ { text: '商品详情页上使用了未经授权的图片', value: '商品详情页上使用了未经授权的图片' }, { text: '实际商品或其包装包含非盗版的未授权的内容', value: '实际商品或其包装包含非盗版的未授权的内容' }, { text: '商品详情页面上使用了未经授权的文本', value: '商品详情页面上使用了未经授权的文本' }, { text: '商品或其包装为盗版(全盘复制受版权保护的商品)', value: '商品或其包装为盗版(全盘复制受版权保护的商品)' }, ], proofGuids:[], }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { this.setData( { proofGuids:[], form:{ tortStoreAdinSite:'美国站', tortType:'发明专利', tortClassify:'产品侵权', ifHaveRightProof:true, problemDescription:'商品详情页上使用了未经授权的图片' }, } ) }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 页面方法集合 */ //表单栏位值发生变化时 onValuesChange(e) { const { changedValues, allValues } = e.detail // this.setValues(changedValues) Object.keys(changedValues).forEach((field) => { this.setData({ ['form.'+field]: changedValues[field], }) }) }, //手机号校验 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 that = this var tempFilePaths = e.detail.tempFiles tempFilePaths.forEach(item=>{ let tempFilePath = item.tempFilePath // this.setData({ imageUrl:e.detail.tempFiles[0].tempFilePath }) upload.upload(tempFilePath).then(res=>{ if(res.code == 200){ // var arr = [] // arr.push(res.data[0]) var guid = res.data[0] var arr = that.data.proofGuids arr.push( { url:tempFilePath, guid:guid, status:"done" } ) that.setData( { // ["form.fileGuids"]:arr proofGuids:arr } ) } }) }) } }, //移除 onRemove(e){ const { file, fileList } = e.detail wx.showModal({ content: '确定删除?', success: (res) => { if (res.confirm) { this.setData({ proofGuids: this.data.proofGuids.filter((n) => n.guid !== file.guid), }) } }, }) }, //输入备注 changRemark(e){ this.setData( { ["form.description"]:e.detail.value } ) }, //修改是否拥有专利号 onChange(e){ this.setData( { ["form.ifHaveRightProof"]:e.detail } ) }, //修改哪一项最能描述您的问题? onChange1(e){ this.setData( { ["form.problemDescription"]: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() console.log(this.data.form) validateFields((err, values) => { console.log(err) if (!err) { if(this.data.proofGuids && this.data.proofGuids.length>0){ this.data.form.proofGuids = this.data.proofGuids.map(item=>item.guid) } var params = { ticketType:2, contactPerson:this.data.form.contactPerson, contactPhone:this.data.form.contactPhone, contactMail:this.data.form.contactMail, fileGuids:this.data.form.fileGuids, protectionAddDTO:this.data.form } wx.showLoading({ title: '加载中', }) api.addTicket(params).then(res=>{ if(res.code == 200){ wx.navigateTo({ url: '/pages/successReminder/successReminder?id=2', }) } }) }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() { } })