// pages/edu/index.js const app = getApp(); const commonUtil = require("../../utils/commonUtil.js"); Page({ /** * 页面的初始数据 */ data: { date: '', array: commonUtil.educationArray(), index: -1, multiArray: commonUtil.getDateArrayOfScope(), multiIndex: [0, 0, 0,0,0], id: '', userEducationDetails: {}, }, bindPickerChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index: e.detail.value }) }, bindDateChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ date: e.detail.value }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; console.log(that.data.array); // options['id'] = 7; var date=new Date; var yearIndex = that.data.multiArray[0].length - 1; var monthIndex = date.getMonth(); that.data.multiIndex[0] = yearIndex; that.data.multiIndex[1] = monthIndex; that.data.multiIndex[3] = yearIndex; that.data.multiIndex[4] = monthIndex; if (app.isNotEmptyCheck(options.id)) { that.data.id = options.id; that.getUserEducationDetails(); } else { that.setData({ multiIndex: that.data.multiIndex }); } }, getUserEducationDetails: function() { var that = this; wx.request({ url: app.globalData.ip + '/user/education/getUserEducationDetails?id=' + that.data.id, data: {}, header: app.globalData.headers, method: "GET", success: function (res) { console.log(res); if (res.data.status == 200) { that.data.userEducationDetails = res.data.data; if (app.isNotEmptyCheck(that.data.userEducationDetails.startDate) && app.isNotEmptyCheck(that.data.userEducationDetails.endDate)) { var startDate = new Date(that.data.userEducationDetails.startDate); var yearIndex = startDate.getFullYear() - 1990; var monthIndex = startDate.getMonth(); that.data.multiIndex[0] = yearIndex; that.data.multiIndex[1] = monthIndex; var endDate = new Date(that.data.userEducationDetails.endDate); yearIndex = endDate.getFullYear() - 1990; monthIndex = endDate.getMonth(); that.data.multiIndex[3] = yearIndex; that.data.multiIndex[4] = monthIndex; } that.data.array.forEach((item, index) => { if (item.id == that.data.userEducationDetails.education) { that.data.index = index; } }); that.setData({ id: that.data.id, index: that.data.index, userEducationDetails: that.data.userEducationDetails, multiIndex: that.data.multiIndex, }); } else if (res.data.status == 9999) { // app.dialogNotLogin(); } else { app.showTips(that, res.data.msg); } } }) }, deleteRecord:function(e){ var that = this; wx.showModal({ title: '提示', content: '确定要删除该工作经历吗?', cancelColor:"#666666", confirmColor:"#027AFF", success (res) { if (res.confirm) { console.log('用户点击确定') that.deleteUserEducation(); } else if (res.cancel) { console.log('用户点击取消') } } }) }, deleteUserEducation: function() { var that = this; wx.request({ url: app.globalData.ip + '/user/education/deleteUserEducation?id=' + that.data.id, data: {}, header: app.globalData.headers, method: "GET", success: function (res) { console.log(res); if (res.data.status == 200) { wx.showToast({ title: '删除成功', icon: 'success', image: '', duration: 1500, mask: true, success: function(res) { wx.navigateBack({ delta: 1 }) }, fail: function(res) { wx.hideLoading(); }, complete: function(res) {}, }) } else if (res.data.status == 9999) { // app.dialogNotLogin(); } else { app.showTips(that, res.data.msg); } } }) }, onSubmit: function (e) { var that = this; var formData = e.detail.value; console.log(formData); formData['id'] = that.data.id; if (that.data.index >= 0) { formData['education'] = that.data.array[that.data.index].name; } var startDate = that.data.multiArray[0][that.data.multiIndex[0]].replace('年', '-') + that.data.multiArray[1][that.data.multiIndex[1]].replace('月', '-') + '01'; var endDate = that.data.multiArray[3][that.data.multiIndex[3]].replace('年', '-') + that.data.multiArray[4][that.data.multiIndex[4]].replace('月', '-') + '01'; formData['startDate'] = startDate; formData['endDate'] = endDate; console.log(formData); wx.request({ url: app.globalData.ip + '/user/education/addOrUpdateUserEducation', data: formData, header: app.globalData.headers, method: "POST", success: function (res) { console.log(res); if (res.data.status == 200) { wx.showToast({ title: '保存成功', icon: 'success', image: '', duration: 1500, mask: true, success: function(res) { wx.navigateBack({ delta: 1 }) }, fail: function(res) { wx.hideLoading(); }, complete: function(res) {}, }) } else if (res.data.status == 9999) { // app.dialogNotLogin(); } else { app.showTips(that, res.data.msg); } } }) }, bindMultiPickerChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ multiIndex: e.detail.value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })