// pages/myAgentInfo/index.js let app = getApp(); Page({ /** * 页面的初始数据 */ data: { checkboxItems: [ { name: '同业', value:2,checked:false}, { name: '异业', value:0,checked:false }, { name: '门店', value:3,checked:false } ], msg: false, checkValue: 1, check: false, agencyId:'', checkedValue:2, addressRecord:{address:'',lat:'',lng:''}, record:{}, isFirstIn:true }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options.agencyId); this.setData({ agencyId: options.agencyId }) }, checkboxChange(e){ var that = this; console.log('checkbox发生change事件,携带value值为:', e.detail.value) that.setData({ checkedValue:e.detail.value }) }, chooseLocation(){ var that = this; wx.chooseLocation({ success: res => { that.setData({ isFirstIn:false, addressRecord:res, ['record.address']:res.address, ['record.lat']:res.latitude, ['record.lng']:res.longitude, }) console.log(that.data.record) }, fail: res => { console.log('打开地图选择位置取消', res) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { if(this.data.isFirstIn){ this.getDetail(); } }, getDetail() { var that = this; wx.request({ url: app.globalData.ip + "/agency/getDetailById?id=" + that.data.agencyId, header: app.globalData.header, method: "GET", success: function (res) { console.log(res.data); // console.log(that.convertHtmlToText(res.data.data.articleContent)); that.data.checkboxItems.forEach((item,index)=>{ // console.log(item.value); // console.log(res.data.data.channelItemType); if(item.value - res.data.data.channelItemType == 0){ item.checked = true } }) that.setData({ record: res.data.data, checkboxItems:that.data.checkboxItems, checkedValue:res.data.data.channelItemType, }); // debugger; }, fail: function (res) { console.log(res); }, }); wx.hideLoading({ success: (res) => {}, }) }, formSubmit(e) { console.log('form发生了submit事件,携带数据为:', e.detail.value) var that = this; if(e.detail.value.agencyName == ""){ wx.showToast({ title: '名称不能为空', icon: 'error', duration: 1000 }) }else{ let currData = {}; currData["id"] = that.data.agencyId; currData["agencyName"] = e.detail.value.agencyName; currData["channelItemType"] = that.data.checkedValue; console.log(that.data.addressRecord); if(that.data.addressRecord.address == ''){ currData["address"] = that.data.record.address; currData["lat"] = that.data.record.lat; currData["lng"] = that.data.record.lng }else{ currData["address"] = that.data.addressRecord.address; currData["lat"] = that.data.addressRecord.latitude; currData["lng"] = that.data.addressRecord.longitude } wx.request({ url: app.globalData.ip + "/agency/updateBase", 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) // console.log(that.convertHtmlToText(res.data.data.articleContent)); // that.setData({ // agencyStatistics: res.data.data.record, // }); }, fail: function (res) { console.log(res); }, }); } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })