var id = ''; //详情id
var qs = parseQueryString(window.location.href);
$().ready(function () {
if(qs.id) {id = qs.id;}
detailEvent();//详情页接口
})
function detailEvent () {
//详情页接口数据
$.ajax({
type:'post',
url:'/user/product/detail',
dataType:'json',
data:{
id:id
},
success:function(res){
console.log(res)
if(res && res.errno == 0){
var product_con_html = '',requirements_html = '';//申请条件
var document_html = '';//所需资料
var explain_html = '';//产品特色
var periods = res.rst.loan_period[0].k;//贷款期限
var money = res.rst.upper_amount;//贷款金额下线
var star = '';//星星
for(var i = 0; i < res.rst.star; i++){
star += ''
}
for(var j = res.rst.star; j<5; j++){
star += ''
}
var details_info_html = `
${res.rst.name}
${res.rst.description}
通过率${star}
额度 (元)
${res.rst.chinese_amount}
${res.rst.show_day}
${res.rst.day_rate}%
`
if(res.rst.requirements){
requirements_html=`申请条件
${res.rst.requirements}
`
}
if(res.rst.document){
document_html=`所需资料
${res.rst.document}
`
}
if(res.rst.explain){
explain_html=`产品特色
${res.rst.explain}
`
}
product_con_html=`${explain_html}${requirements_html}${document_html}`;
var applyHtml = `立即申请
`
if(res.rst.applicants_ch){
applyHtml = `立即申请(${res.rst.applicants_ch}人申请)
`
}
$("#apply").html(applyHtml)
$('.product_con').html(product_con_html)
$(".details_info").html(details_info_html);
$('.apply').click(function () {
addapplyEvent(periods,money)
})
}
}
})
}
//获取地址栏参数
function parseQueryString(url) {
var urlObj = {};
var reg = /([^?=&]+)=([^?=&]+)/g;
url.replace(reg, ($0, $1, $2) => {
urlObj[$1] = decodeURIComponent($2);
})
return urlObj;
}
//提示信息
function showMsg(msg) {
var msg = msg;
var msgBox = $('.alert-info');
msgBox.children('p').text(msg);
msgBox.show();
setTimeout(function() {
msgBox.hide();
}, 2000);
}
//立即申请
function addapplyEvent (periods,money) {
$.ajax({
type:"post",
url:"/user/user/addapply",
dataType:'json',
data:{
product_id:id,
periods:periods,
money:money
},
success: function(res){
console.log(res)
if(res && res.errno == 0){
window.location.href=res.rst.url;
}
}
});
}