php怎么实现收藏商品功能,商品收藏功能开发

6c601ca11af1088405c339a60c8930f9.png

完整代码

HUI

#product-img{width:100%;}

#product-img img{width:100%;}

#product-title{line-height:30px; padding:5px 10px; font-size:16px;}

#product-price{height:30px; line-height:30px; padding:5px 10px; font-size:26px; color:#F0302F;}

#product-desc{line-height:1.8em;}

#product-desc img{width:100%;}

#addToCard{width:40%; height:56px; line-height:56px; background:#F0302F; color:#FFFFFF; text-align:center; position:fixed; right:0px; bottom:0px; z-index:22;}

.red{color:#C61523 !important;}

加载中

商品描述

var _self;

hui.plusReady(function(){

_self = plus.webview.currentWebview();

//获取商品详情

hui.loading();

hui.postJSON(

'http://shop.hcoder.net/myApi.php',

{act:"goodsInfo", id : _self.pid},

function(res){

hui.closeLoading();

//替换标题

hui('.hui-header').eq(0).find('h1').html(res.msg.goods_name);

hui('#product-title').html(res.msg.goods_name);

//替换图片

hui('#product-img').html(''+res.msg.original_img+'');

//价格

hui('#product-price').html('¥'+res.msg.market_price);

//描述

hui('#product-desc').html(res.msg.goods_desc);

}

);

//检查收藏状态

checkLike();

});

function checkLike(){

var res = isLogin();

if(!res){return false;}

var SUID = hui.getItem('SUID');

var SRAND = hui.getItem('SRAND');

hui.postJSON(

'http://shop.hcoder.net/myApi.php',

{act:"checkLike", id : _self.pid, suid : SUID, srand : SRAND},

function(res){

if(res.msg == 'yes'){

hui('#nav-like').find('div').addClass('red');

}else if(res.msg == 'no'){

hui('#nav-like').find('div').removeClass('red');

}

}

);

}

function like(){

var res = isLogin();

if(!res){

hui.open('login.html');

return false;

}

var SUID = hui.getItem('SUID');

var SRAND = hui.getItem('SRAND');

hui.postJSON(

'http://shop.hcoder.net/myApi.php',

{act:"like", id : _self.pid, suid : SUID, srand : SRAND},

function(res){

if(res.msg == 'yes'){

hui('#nav-like').find('div').addClass('red');

hui.toast('收藏成功');

}else if(res.msg == 'no'){

hui('#nav-like').find('div').removeClass('red');

hui.toast('取消收藏');

}

}

);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值