// pages/myAgentNew/myCreatMember/edit/index.js let app = getApp(); const commonUtil = require("../../../../utils/commonUtil.js"); Page({ /** * 页面的初始数据 */ data: { checkboxItems: [ { name: '管理员', value:2}, { name: '成员', value:3 }, ], msg: false, checkedValue: 3, check: false, agencyId:'', record:{}, id:'', }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options.userId); console.log(options.userName); console.log(options.agencyRole); console.log(options.tel); this.setData({ ["record.userId"] : options.userId, ["record.userName"] : options.userName, ["record.agencyRole"] : options.agencyRole, ["record.tel"] : options.tel, // record:options.record, // checkValue:options.record.agencyRole }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { // this.getDetail(); var that = this; that.data.checkboxItems.forEach((item,index)=>{ // console.log(item.value); // console.log(res.data.data.channelItemType); if(item.value - that.data.record.agencyRole == 0){ item.checked = true } }) that.setData({ checkedValue:that.data.record.agencyRole, checkboxItems:that.data.checkboxItems, }); // console.log(commonUtil.getAgencyPermissionsByRole(1)); }, checkboxChange(e){ var that = this; console.log('checkbox发生change事件,携带value值为:', e.detail.value) that.setData({ checkedValue:e.detail.value }) }, formSubmit(e) { console.log('form发生了submit事件,携带数据为:', e.detail.value) var that = this; if(e.detail.value.userName == ""){ wx.showToast({ title: '姓名不能为空', icon:'error', duration:1000 }) return } if(e.detail.value.tel == ""){ wx.showToast({ title: '电话不能为空', icon:'error', duration:1000 }) return } let currData = {}; currData["userId"] = that.data.record.userId; currData["userName"] = e.detail.value.userName; currData["tel"] = e.detail.value.tel; currData["agencyRole"] = that.data.checkedValue; currData["agencyPermissions"] = commonUtil.getAgencyPermissionsByRole(that.data.checkedValue) wx.request({ url: app.globalData.ip + "/agency/updateMember", header: app.globalData.header, data:currData, method: "post", success: function (res) { console.log(res.data); wx.showToast({ title: '修改成功', icon:'success', duration:1000 }) setTimeout(function(){ wx.navigateBack({ delta: 1, }) },1000) }, fail: function (res) { console.log(res); }, }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })