var qs = parseQueryString(window.location.href),user_id,contractList;
var request = '';
$().ready(function(){
if(qs.user_id){
user_id = qs.user_id;
}
if(!getCookie('user_id') || getCookie('user_id') != user_id){
window.location.href="index.html"
}
contract();//合同列表
})
function contract () {
//合同列表
$(".loading").show();
$.ajax({
type: 'post',
url: request + '/api/contract/index',
data:{
'user_id':user_id
},
success: function (res) {
$(".loading").hide();
console.log(res)
if(res.status == 200){
contractList = res.data;
var contractListHtml = '',user_info = '';
user_info = res.user_info;
$(".userImg").attr('src',user_info.user_header_url)
contractList.forEach(function(item,index){
var signStatus = '',signStatusColor = '',contractType = '';
if(item.sign_status == 1){signStatus = '待签约';signStatusColor = 'color:red'}
if(item.sign_status == 2){signStatus = '正在签约';signStatusColor = 'color:green'}
if(item.sign_status == 3){signStatus = '签约成功'}
if(item.sign_status == 4){signStatus = '签约失败';signStatusColor = 'color:red'}
if(item.platform_name != 'null' && item.platform_name){contractType = item.platform_name}
var goSigningData = {'sign_status':item.sign_status,'tpl_id':item.tpl_id,'sign_id':item.sign_id,'contract_url':encodeURIComponent(item.contract_url)};
goSigningData = JSON.stringify(goSigningData)
contractListHtml+= "
订单编号:"+ item.sign_id + '
' + user_info.name + '' + user_info.mobile + ' 身份证号:' + user_info.id_card_num + '
状态:' + signStatus + '合同类型:' + contractType + '
';
})
$(".contractList").html(contractListHtml)
}else{
showMsg(res.msg)
}
},
fail: function () {
showMsg('网络错误,请稍后再试~')
$(".loading").hide();
}
})
}
function goSigning (data) {
//去签约页面
console.log(data)
if(data.sign_status == 1 || data.sign_status == 4){
//未签约 签约失败
window.location.href='signing.html?user_id=' + user_id + '&tpl_id=' + data.tpl_id
}
if(data.sign_status == 2){
//正在签约
showMsg('签约中,请稍后查看')
}
if(data.sign_status == 3){
//签约成功
window.location.href = decodeURIComponent(data.contract_url)
// window.location.href="lookPdf.html?contract_url=" + data.contract_url + '&user_id=' + user_id
// contract_view(data.sign_id);//查看合同
}
}
// function contract_view (order_id) {
// $(".loading").show();
// $.ajax({
// type: 'get',
// url: request + '/contract/view',
// data:{
// 'order_id':order_id
// },
// success: function (res) {
// $(".loading").hide();
// console.log(res)
// if(res.status == 200){
// var iframeUrl = decodeURIComponent(res.data);
// window.location.href=iframeUrl;
// }else{
// showMsg(res.msg)
// }
// },
// fail: function () {
// showMsg('网络错误,请稍后再试~')
// $(".loading").hide();
// }
// })
// }
//获取地址栏参数
function parseQueryString(url) {
var urlObj = {};
var reg = /([^?=&]+)=([^?=&]+)/g;
url.replace(reg, function($0, $1, $2) {
urlObj[$1] = decodeURIComponent($2);
})
return urlObj;
}
// 展示错误提示信息
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 goPerfectInfo(){
window.location.href="personalInfo.html?user_id=" + user_id;
}
//取Cookie的值
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg)){
return arr[2];
}else{
return false
}
}
//写入到Cookie
//name:cookie名称 value:cookie值
function setCookie(name,value){
var exp = new Date();
exp.setTime(exp.getTime() + 12 * 60 * 60000);//过期时间 12小时
// exp.setTime(exp.getTime() + 60 * 10000);//过期时间 10分钟
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}