const util = require("../../../utils/util.js"); const Http = require("../../../utils/HttpBasics"); const config = require("../../../config/config"); Page({ /** * 页面的初始数据 */ data: { date: '1988-03-12', flag: 1, answerflag: "", flagsex: 0, items: [{ name: 1, value: '男', checked: false }, { name: 2, value: '女', checked: false }, ], username: "", array: ['上班族', '学生', '企业高管', '个体户', '自由职业', '其他'], array1: ['附近住户', '距离2km', '距离3km', '更远'], index: 0, index1: 0, showPage: false }, /** * 获得生日 */ bindDateChange: function(e) { this.setData({ date: e.detail.value, flag: 2 }) }, /** * 职业 */ bindPickerChange: function(e) { this.setData({ index: e.detail.value }) }, /** * 生活半径 */ bindPickerChange1: function(e) { this.setData({ index1: e.detail.value }) }, address: function() { let that = this; wx.chooseLocation({ success: function(res) { that.setData({ address: res.name + '(' + res.address + ')', addressStr: JSON.stringify(res) }) }, fail: function(error) { console.log(error) }, complete: function(data) {} }) }, change(value){ console.log(value) }, formSubmit: function(e) { let that = this; console.log(e) /** * sex * 0 保密 * 1 男 * 2 女 */ if (that.data.flagsex == 0) { var sex = 0; } else { var sex = that.data.sex; } if (that.data.addressStr) { var address = that.data.addressStr; } else { var address = null; } if (e.detail.value.username) { var username = e.detail.value.username; } else if (that.data.username) { var username = that.data.username; } else { var username = null; } if (that.data.flag == 2 && that.data.date) { var birthday = new Date(that.data.date).getTime(); } else { var birthday = null; } //获得答案 delete e.detail.value.username; let obj = e.detail.value; if (that.data&&that.data.question&&that.data.question.length>0){ let valArr22; valArr22 = Object.keys(obj).map(function (item,index) { if (!obj[item]){ wx.showToast({ title: '问卷调查回答不完整,请补充', duration:2000, icon:"none" }) that.setData({ answerflag:"noanswer" }) }else{ that.setData({ answerflag: "answer" }) return { ques: that.data.question[index].ques, answer: obj[item] } } }); this.setData({ answer:valArr22 }); } if (username == null || address == null || sex == 0 || birthday == null) { wx.showToast({ title: '请输入完整的用户信息', icon: "none" }) } else { console.log(that.data.answer) if (this.data.answerflag == 'noanswer'){ }else{ Http.post({ url: config.api.activityJoin, data: { sex: sex, address: address, name: username, birthday: birthday, answer: JSON.stringify(that.data.answer), activityId: that.data.activityId } }) .then(res => { wx.redirectTo({ url: '/pages/radetail/success/index', }) }) .catch(err => { wx.showToast({ title: err.message, icon: 'none', duration: 2000, mask: false }) }) } } }, radioChange: function(e) { this.setData({ sex: e.detail.value, flagsex: 1 }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { let that = this; if (options && options.activityId) { that.setData({ activityId: options.activityId }) that.getDetail(options.activityId); } }, getDetail(activityId) { let that = this; Http.get({ url: config.api.acfindById, data: { id: activityId } }).then(res => { if (res && res.data && res.data.activity) { if (res.data && res.data.activity && res.data.activity.question) { that.setData({ question: JSON.parse(res.data.activity.question) }) } } }).catch(err => { wx.showToast({ title: err.errMsg, icon: 'none', duration: 2000, mask: false }) }) } })