vipcommon.js
4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function GetDateStr(date,type,beishu) {
var dd = new Date(date); //1 年卡 2半年卡 3季卡 4月卡 5日卡
var cyy = dd.getFullYear();
var cmm = dd.getMonth()+1;
var cdd = dd.getDate();
var ddddd = '';
if(type==1){cmm = cmm+12*beishu;}
else if(type==2){cmm = cmm+6*beishu;}
else if(type==3){cmm = cmm+3*beishu;}
else if(type==4){cmm = cmm+1*beishu;}
console.log(cmm);
if(cmm>12){
var ny = parseInt( cmm/12);
if(ny <0){ny=0;}
cyy = cyy+ny;
console.log(cyy);
if(cmm%12!=0){
cmm = cmm%12;
}else{
cyy = cyy-1
cmm = 12;
}
}
if(cmm==4||cmm==6||cmm==9||cmm==11){
if(cdd>30){cdd=30;}
}else if(cmm==2){
if(cyy%4==0||cyy%400==0){
if(cdd>29){cdd = 29;}
}else{
if(cdd>29){cdd = 28;}
}
}
cdd = cdd - 1;
if(cdd==0){
cmm = cmm -1;
if(cmm==0){
cyy = cyy-1;
cmm = 12;
}
if(cmm==1||cmm==3||cmm==5||cmm==7||cmm==8||cmm==10||cmm==12){cdd=31;}
else if(cmm==4||cmm==6||cmm==9||cmm==11){cdd=30;}
else if(cmm==2){
if(cyy%4==0||cyy%400==0){
cdd = 29;
}else{cdd = 28;}
}
}
var mm=dd='';
if(parseInt(cmm)<=9){
mm='0'+cmm.toString();
}else{
mm=cmm;
}
if(parseInt(cdd)<=9){
dd='0'+cdd.toString();
}else{
dd = cdd;
}
var ds = cyy+'-'+mm+'-'+dd;
return ds;
}
//根据数量,开始时间计算 结束时间,总价
function handelEndDateAndPrice(num, startDate) {
console.log('初始化截止时间');
if (typeof num == 'string') {
num = parseInt(num);
}
if (typeof startDate == 'string') {
startDate = new Date(startDate);
}
var endDate = new Date(startDate.format('yyyy-MM-dd'));
//设置数量
$("#numder").val(num);
var shixd = null;
var car5 = '';
if(func.cardType==1){
//年卡日历
shixd = GetDateStr(startDate,1,num);
endDate = new Date(shixd);
shixd = endDate.format('yyyy-MM-dd')+car5;
}else if(func.cardType==2){
shixd = GetDateStr(startDate,2,num);
endDate = new Date(shixd);
shixd = endDate.format('yyyy-MM-dd')+car5;
//半年卡
}else if(func.cardType==3){
shixd = GetDateStr(startDate,3,num);
endDate = new Date(shixd);
shixd = endDate.format('yyyy-MM-dd')+car5;
//季卡
}else if(func.cardType==4){
shixd = GetDateStr(startDate,4,num);
endDate = new Date(shixd);
shixd = endDate.format('yyyy-MM-dd')+car5;
}else if(func.cardType==5){
//日卡
var days = 0;
var temp = startDate.getMonth();
var myDate = new Date();
var hours = myDate.getHours();
var minute = myDate.getMinutes();
//转化成分钟后再转化成小时最后转化成天数,剩下的看能转化
var allminutes = (hours*60)+minute + 24*60*num ;
var mt = allminutes%60 ;//是剩下的分钟数
var h = parseInt(allminutes/60);
var ho = h%24;//剩下的小时数
var day = parseInt(h/24);//天数
endDate.setDate(endDate.getDate() + day);
car5 = " "+ho+" : "+mt;
shixd = endDate.format('yyyy-MM-dd');//+car5;
}
console.log('截止时间 '+shixd);
//设置失效日期
$('#date1').val(shixd);
//设置总价
var price = $("#cardAmount").val();
var mnum = num * price;
$('#totalm').val(mnum);
var jz = jsajax.fenToYuan(mnum);
$("#totle_money").html(jz);
//设置优惠金额
//console.log(a.replace(",",""));
var olp = parseFloat(func.actprice.replace(",",""));//优惠前金额
olp = (olp*100)*num;//优惠前总金额
console.log('优惠前的单价 '+func.actprice+" "+olp);
var dissp = olp-parseFloat(mnum);
var dicp = jsajax.fenToYuan(dissp);
console.log('优惠金额为'+olp+"减去"+parseFloat(mnum)+" ---- "+dicp);
$("#disPrice").text('-¥'+dicp);
//func.discount
}