123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- var qs = parseQueryString(window.location.href);
- $().ready(function(){
- init(qs.id?qs.id:'')
- })
- function init(id) {
- $(".loading").show();
- $.ajax({
- url:'/api/v2/adv/talentArticle',
- type:'get',
- dataType:'json',
- data:{
- id:id
- },
- success:function (res){
- $(".loading").hide();
- if(res.errno==0) {
- var data = res.rst.data
- var content = data.article;
- var goodsInfo = data.items;
- $("#app_image").attr("src",data.app_image)
- var news_info_con = '<h3 class="title">' + data.name + '</h3><div class="drs_info"><div class="left"><img src="' + data.head_img + '" class="head_img"/><span class="talent_name">'+ data.talent_name +'</span></div><div class="right"><img class="readtimes_icon" src="./yanjing.png"/><span class="readtimes">' + data.readtimes + '</span></div></div>'
- $(".news_info").html(news_info_con)
- $("#container").html(decodeHtml(content))
- document.title = data.shorttitle;
- $(".commodity-tkmoney").remove();
- $(".commodity-tkrates").remove();
- $(".single-tkmoney").remove();
- $(".single-tkrates").remove();
- //删除goodsInfo中没有的商品
- var goods_id = '';
- Array.prototype.slice.call($(".js_tobuy")).forEach(function (item,index){
- goods_id = $(item).attr('id').split('itemid')[1];
- if(JSON.stringify(goodsInfo).indexOf(goods_id)==-1){
- $(item).remove()
- }
- })
- $(".js_tobuy").click(function () {
- console.log($(this).attr('id'))
- var itemid = $(this).attr('id').split('itemid')[1];
- var param = '';
- console.log(itemid)
- goodsInfo.forEach(function (item, index) {
- if(item.goods_id == itemid){
- param = {
- goods_id: item.goods_id,
- is_coupon: item.is_coupon,
- coupon_price: item.coupon_price,
- price: item.price,
- discount_price: item.discount_price,
- commission_rate: item.commission_rate,
- coupon_start_time: item.coupon_start_time,
- coupon_end_time: item.coupon_end_time
- }
- param = JSON.stringify(param)
- goGoodsDetail(param)//跳详情
- }
- })
-
- })
- }else {
- showMsg(res.err)
- }
- },
- error:function () {
- $(".loading").hide();
- showMsg('网络异常,请稍后再试')
- }
- })
- }
- // 展示错误提示信息
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.getElementsByTagName("p")[0].innerHTML=msg;
- msgBox.style.display="block";
- setTimeout(function() {
- msgBox.style.display="none";
- }, 2000);
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, function($0, $1, $2) {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- //打开商品详情
- function goGoodsDetail (param) {
- console.log(param)
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_open_goodDetail.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_open_goodDetail(param);
- }
- }catch(e){
- //TODO handle the exception
- console.log("兼容")
- }
-
- }
- //文章解析
- function decodeHtml(s) {
- var HTML_DECODE = {
- "<": "<",
- ">": ">",
- "&": "&",
- " ": " ",
- """: "\"",
- "©": ""
- // Add more
- };
- var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
- var REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;
- var REGX_TRIM = /(^\s*)|(\s*$)/g;
- s = (s != undefined) ? s : "";
- return (typeof s != "string") ? s :
- s.replace(REGX_HTML_DECODE,
- function ($0, $1) {
- var c = HTML_DECODE[$0];
- if (c == undefined) {
- // Maybe is Entity Number
- if (!isNaN($1)) {
- c = String.fromCharCode(($1 == 160) ? 32 : $1);
- } else {
- c = $0;
- }
- }
- return c;
- });
- };
|