小程序 收藏、分享功能
wxml:
<!-- 收藏&分享&购买工具栏 -->
<view class="tudo-goods-action">
<view class="icon" bindtap="handleCollect">
<image wx:if="{{isCollect}}" src="/images/basic/icon_collected.png"></image>
<image wx:else src="/images/basic/icon_collect.png"></image>
<label>收藏</label>
</view>
<view class="icon" bindtap="handleShare">
<image src="/images/course-detail/icon_share.png"></image>
<label>分享</label>
</view>
<form bindsubmit="handleBuyNow" report-submit="{{true}}">
<button formType="submit" plain class="buy-now">¥{{storyInfo.Price}}立即购买</button>
</form>
</view>
</view>
js:
Page({
data: {
showPopup: false,
storyInfo: null, //故事详情
isCollect: false, //收藏
},
/**
* 收藏|取消收藏该课程
*/
handleCollect: function () {
let _this = this
alert.request({
url: config.service.course_collection,
method: 'POST',
data: {
course_id: _this.data.courseId,
type_id: 2, // 1表示收藏课程
},
success: function (res) {
if (res.data.status === 100) {
let isCollect = res.data.data.collect
_this.setData({ isCollect: isCollect == 1 })
console.log('isCollect', _this.data.isCollect)
alert.showToast(isCollect == 1 ? '收藏成功' : '已取消收藏')
} else {
alert.showError(res.data.message)
}
},
fail: function (err) {
alert.showError(config.service.request_error)
},
complete: function () {}
})
},
/**
* 分享到朋友圈|邀请微信好友
*/
handleShare: function () {
this.setData({ showPopup: true })
},
/**
* 分享到朋友圈
*/
onChooseShare: function () {
alert.showToast('功能待开发。。。')
},
/**
* 邀请微信好友
*/
onChooseInvite: function () {
alert.showToast('功能待开发。。。')
},
/**
* 取消分享
*/
onChooseCancel: function () {
this.setData({ showPopup: false })
},
)}