// pages/cooperation/index.js const API = require('../../utils/api.js'); Page({ /** * 页面的初始数据 */ data: { // 招商图片URL cooperationImageUrl: '/images/招商图片.jpg', // 首页分享图片URL shareImageUrl: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 页面加载时的初始化操作 console.log('招商合作页面加载'); // 加载招商图片和分享图片 this.loadCoverData(); }, /** * 加载封面图片数据 */ loadCoverData: function () { API.getCovers().then(res => { if (res.success && res.covers) { // 查找招商图片(id为5) const cooperationCover = res.covers.find(cover => cover.id === 5); let cooperationImageUrl = '/images/招商图片.jpg'; // 默认图片 if (cooperationCover) { try { const urls = JSON.parse(cooperationCover.coverurl); if (Array.isArray(urls) && urls.length > 0) { cooperationImageUrl = urls[0].replace(/[`\s]/g, ''); } } catch (err) { console.error('解析招商图片URL失败:', err); } } // 查找首页分享图片(id为6) const shareCover = res.covers.find(cover => cover.id === 6); let shareImageUrl = ''; if (shareCover) { try { const urls = JSON.parse(shareCover.coverurl); if (Array.isArray(urls) && urls.length > 0) { shareImageUrl = urls[0].replace(/[`\s]/g, ''); } } catch (err) { console.error('解析分享图片URL失败:', err); } } this.setData({ cooperationImageUrl: cooperationImageUrl, shareImageUrl: shareImageUrl }); } }).catch(err => { console.error('加载封面图片数据失败:', err); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { // 页面初次渲染完成时的操作 }, /** * 生命周期函数--监听页面显示 */ onShow: function () { // 页面显示时的操作 }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { // 页面隐藏时的操作 }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { // 页面卸载时的操作 }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { // 下拉刷新时的操作 wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { // 上拉触底时的操作 }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { // 分享时的配置 return { title: '招商合作 - 又鸟蛋平台', path: '/pages/cooperation/index', imageUrl: this.data.shareImageUrl }; }, /** * 用户点击右上角分享到朋友圈 */ onShareTimeline: function () { return { title: '招商合作 - 又鸟蛋平台', query: '', imageUrl: this.data.shareImageUrl }; }, /** * 拨打电话 */ makePhoneCall: function () { wx.makePhoneCall({ phoneNumber: '19381602346', success: function () { console.log('拨打电话成功'); }, fail: function (error) { console.error('拨打电话失败:', error); wx.showToast({ title: '拨打电话失败,请稍后重试', icon: 'none' }); } }); }, /** * 跳转到立即合作页面 */ navigateToSettlement: function () { console.log('navigateToSettlement函数被调用'); wx.navigateTo({ url: '/pages/settlement/index', success: function() { console.log('跳转成功'); }, fail: function(error) { console.error('跳转失败:', error); wx.showToast({ title: '跳转失败,请稍后重试', icon: 'none' }); } }); } });