main481.js
4 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
require('YH_PaymentViewModel','YH_InvoiceModel','YH_Global')
defineClass('YH_PaymentViewModel',{
invoiceCellSubtitle : function(){
var invoicesTypeString = "";
var model = self.invoiceModel();
var type = model.invoiceType();
var isOpen = require('YH_Global').sharedInstance().isOpenElectronicInvoice();
if (isOpen && type == 2) {
invoicesTypeString = "电子";
}else{
self.invoiceModel().setInvoiceType(1);
invoicesTypeString = "纸质";
}
return require('NSString').stringWithFormat('%@(%@)',self.invoiceModel().invoiceTypeName(),invoicesTypeString);
}
})
defineClass('YH_InvoiceModel',{
analysisDicWithDictionary :function(dic){
if (!dic) {
return;
}
self.setInvoiceContentList(dic.yh__arrayForKey('invoiceContentList'));
self.setInvoicesTypeList(dic.yh__arrayForKey('invoices_type_list'));
//与后台沟通 默认数组第一个 invoice信息
if (self.invoiceContentList().count() > 0) {
var tempDic = self.invoiceContentList().objectAtIndex(0);
self.setInvoicesTypeId(tempDic.yh__integerForKey('invoices_type_id'));
self.setInvoiceTypeName(tempDic.yh__stringForKey('invoices_type_name'));
}
var isOpen = require('YH_Global').sharedInstance().isOpenElectronicInvoice();
self.setInvoiceType(isOpen ? 2 : 1);
self.setIsCompanyInvoice(false);
self.setInvoiceTitle("个人");
self.setCompanyName("");
self.setPhoneNumber("");
}
})
defineClass('YH_Global',{
isOpenElectronicInvoice : function (){
var isOpenElectronicInvoice = require('NSUserDefaults').standardUserDefaults().objectForKey('kUserConfigSei');
var isOpen = self.isOpenSei(isOpenElectronicInvoice);
return isOpen;
},
isOpenSei : function(sei){
if (sei.isKindOfClass(require('NSString').class())) {
if (sei.isEqualToString('1')) {
return true;
}
return false;
}else{
return true;
}
}
})
require('NSURLProtocol,NSHTTPURLResponse,NSURL,NSURLResponse');
defineClass('YH_H5URLProtocol', {
connection_didReceiveResponse: function(connection, response) {
var originalUrl = connection.currentRequest().valueForHTTPHeaderField("originalUrl");
if (!originalUrl) {
originalUrl = response.URL().absoluteString();
}
if (response.isKindOfClass(NSHTTPURLResponse.class())) {
var httpResponse = response;
var mutableAllHeaderFields = httpResponse.allHeaderFields().mutableCopy();
mutableAllHeaderFields.setObject_forKey("*", "Access-Control-Allow-Origin");
var retResponse = NSHTTPURLResponse.alloc().initWithURL_statusCode_HTTPVersion_headerFields(NSURL.URLWithString(originalUrl), httpResponse.statusCode(), "HTTP/1.1", mutableAllHeaderFields);
self.client().URLProtocol_didReceiveResponse_cacheStoragePolicy(self, retResponse, 2);
} else {
var retResponse = NSURLResponse.alloc().initWithURL_MIMEType_expectedContentLength_textEncodingName(NSURL.URLWithString(originalUrl), response.MIMEType(), response.expectedContentLength(), response.textEncodingName());
self.client().URLProtocol_didReceiveResponse_cacheStoragePolicy(self, retResponse, 2);
}
}
}, {
canInitWithRequest: function(request) {
if (NSURLProtocol.propertyForKey_inRequest("URLProtocolHandledKey", request)) {
return NO;
}
var requestURL = request.URL();
if (!self.supportedSchemes().containsObject(requestURL.scheme())) {
return NO;
}
if (requestURL.host().isEqualToString("m.yohobuy.com")) {
return YES;
}
var webViewType = request.valueForHTTPHeaderField("X-YH-Request-DNS-H5");
if (webViewType.hasSuffix("iOS")) {
return YES;
}
return NO;
}
});