igi_orion_cignacmb
Version:
Censors words out of text
1,348 lines (1,306 loc) • 61.2 kB
JavaScript
var interfaces = require('../config/interfaces');
var checkValid = require('./CheckValid');
var validateService = require('./ValidateService');
var config = require('../config/config');
var inputFilter = require('../lib/inputFilter');
var validate = require('../lib/util/3-validate');
var base64 = require('./base64');
var calculateDate = require('./CalculateDate');
var interfaceService = require('./interfaceService')
var centralService = {
interfaces: interfaces,
localStorage: window.localStorage,
checkValid: checkValid,
config: config,
inputFilter: inputFilter,
validate: validate,
validateService: validateService,
calculateDate: calculateDate,
base64: base64,
require: function (url) {
try {
return require(url);
} catch (e) {
}
},
calTimeStamp: function () {
var accesstime = (new Date()).Format("yyyy-MM-dd hh:mm:ss");
avalon.log("calTimeStamp:", accesstime);
accesstime = accesstime.replace(/-/g, '/');
return accesstime;
},
getProductColor: function (params, products) {
var color = 'blue';
for (var i = 0; i < products.length; i++) {
var productItem = products[i];
if ((productItem.productNo == params.productNo) && (productItem.product == params.product)) {
if (productItem.frontPageConfig.color) {
color = productItem.frontPageConfig.color.replace("#", "")
}
}
}
return color
},
viewDetail: function (product, params) {
var that = this;
// var params = {};
params.productNo = product.productNo;
params.organizationId = product.companyConfig.organizationId;
params.product = product.product;
params.color = product.frontPageConfig.color;
console.log('params_params', params);
var url = that.combineUrlWithParams('orion-detail.html', params);
window.location.href = url;
},
setCurrentProducts: function (products, urlParams) {
var that = this;
var result = {
productUndershelfUrl: that.combineUrlWithParams('productUndershelf.html', urlParams),
productInvalidUrl: that.combineUrlWithParams('productInvalid.html', urlParams),
indexUrl: 'index.html?organizationId=' + urlParams.organizationId,
index: 0,// 1--进入detail页面 2--进入下架页面 3--进入当前页面 4--停留下架页面 5--下架页面轮询进入产品列表页 6--停留失效页 7--进入失效页
detail: 0,
};
if (products.length > 0) {
var isCurrentProductLength = {
num: 0,
index: '',
};
for (var i = 0; i < products.length; i++) {
var datum = products[i];
if (datum.companyConfig.offShelves) {
isCurrentProductLength.num++
} else {
isCurrentProductLength.index = i;
result.detail = i
}
}
console.log("isCurrentProductLength", isCurrentProductLength, products)
if (location.href.indexOf("/productUndershelf.html") != -1) {
if (isCurrentProductLength.num == products.length - 1) {
result.index = 1;
console.log("进入单独的detail页面")
} else if (isCurrentProductLength.num == products.length) {
result.index = 4;
console.log("停留下架页面")
} else {
result.index = 5;
console.log("进入页面01")
}
} else if (location.href.indexOf("/productInvalid.html") != -1) {
if (isCurrentProductLength.num == products.length - 1) {
result.index = 1;
console.log("进入单独的detail页面")
} else if (isCurrentProductLength.num == products.length) {
result.index = 2;
console.log("进入下架页面01")
} else {
result.index = 5;
console.log("进入页面01")
}
} else if (location.href.indexOf("/index.html") != -1) {
if (isCurrentProductLength.num == products.length - 1) {
result.index = 1;
console.log("进入单独的detail页面")
} else if (isCurrentProductLength.num == products.length) {
result.index = 2;
console.log("进入下架页面01")
} else {
result.index = 3;
console.log("进入页面02")
}
} else if (location.href.indexOf("/myOrder.html") != -1) {
if (isCurrentProductLength.num == products.length) {
result.index = 2;
console.log("进入下架页面02")
} else {
result.index = 3;
console.log("进入页面02")
}
} else {
var currentProduct = 0;
for (var i = 0; i < products.length; i++) {
var product = products[i];
if ((urlParams.productNo == product.productNo) && product.companyConfig.offShelves) {
result.index = 2;
console.log("进入下架页面03")
} else {
currentProduct++
}
}
if (currentProduct == products.length) {
result.index = 3;
console.log("进入页面03")
}
}
} else {
if (location.href.indexOf("/productInvalid.html") != -1) {
result.index = 6;
} else {
result.index = 7;
}
}
return result
},
getAge: function (startDate, birthday) {
try {
console.log('1234', startDate, birthday)
var r = birthday.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if (r == null) return false;
var birth = new Date(r[1], r[3] - 1, r[4]);
if (birth.getFullYear() == r[1] && (birth.getMonth() + 1) == r[3] && birth.getDate() == r[4]) {
var today = new Date(startDate);
var age = today.getFullYear() - r[1];
if (today.getMonth() > birth.getMonth()) {
return age;
}
if (today.getMonth() == birth.getMonth()) {
if (today.getDate() >= birth.getDate()) {
return age;
} else {
return age - 1;
}
}
if (today.getMonth() < birth.getMonth()) {
return age - 1;
}
}
} catch (e) {
avalon.log(e)
return ("输入的日期格式错误!");
}
},
//获取默认值
getDefaultDataService: function (urlParams) { //获取默认值设置的服务
var that = this;
var deferred = Deferred();
var data = {
statusCode: 1,
msg: "",
data: {
singleProduct: false,//是否单产品项目
candidateArrays: that.getDefaultCandidateArrayService(urlParams),
auxProperties: {myOrderAge: 21, isLogin: false},
urlParams: urlParams,
productInfo: {},
userInfo: {},
order: {
organizationId: urlParams.organizationId,
relationship: '',
type: urlParams.productNo
},
appntInfo: that.getDefaultappntInfoService(urlParams),
insuredInfos: that.getDefaultInsuredInfosService(urlParams),
schemaInfo: that.getDefaultschemaInfoService(urlParams),
LCInsureImparts: that.getDefaultLCInsureImpartsService(urlParams),
crsInfos: that.getDefaultcrsService(urlParams),
},
}
;
deferred.resolve(data);
return deferred.promise;
},
getDefaultCandidateArrayService: function (urlParams) {
var candidates = require('../lib/dic/index')
return candidates;
},
getDefaultappntInfoService: function (urlParams) {
// return { //投保人信息
// appntName: '测试',
// rankCode: '',
// rankName: '',
// appntidType: 'A',
// appntidNo: '23234113123123',
// idExpDate: '2019-01-02',
// idIsLongValid: '0',
// appntSex: '0',
// appntBirthday: '1990-01-01',
// marriage: '',
// nativePlace: 'CHN',
// personalIncome: '10',
// premSource: '测试',
// occupationCode: '',
// workDepartment: '测试单位',
// companyOrSchool: '测试单位',
// mobilePhoneNumber: '13988555858',
// email: '2342' + parseInt(Math.random() * 10000) + '34@234234.com',
// contactProvince: '44',
// contactCity: '4401',
// contactDistrict: '440101',
// contactDetailedAddress: '在在在在在',
// taxIdentity: 1,
// serviceNo: "123456798"
// }
return { //投保人信息
name: '',
idType: 'I',
idNum: '',
idExpDate: '',
idIsLongValid: '-1',
sex: '-1',
birthday: '1990-01-01',
marriage: '',
nationality: 'CHN',
personalIncome: '',
premSource: '',
companyOrSchool: '',
mobile: '',
email: '',
industry: "",
industryContent: "",
industryCategory: "",
industryCategoryContent: "",
occupationCode: "",
occupationContent: "",
contactAddress: {
province: '',
city: '',
district: '',
detailedAddress: '',
},
taxIdentity: 1,
serviceNo: ""
}
},
getDefaultInsuredInfosService: function (urlParams) {
var result = [{ //被保人信息
seqNo: '1',
relationToApplicant: '-1',
name: "",
idType: "I",
idNum: "",
idExpDate: "",
industry: "",
industryContent: "",
industryCategory: "",
industryCategoryContent: "",
idIsLongValid: "",
sex: "-1",
birthday: "1990-01-01",
marriage: "",
nationality: "CHN",
personalIncome: "",
occupationCode: "",
occupationContent: "",
companyOrSchool: "",
mobile: "",
contactAddress: {
province: '',
city: '',
district: '',
detailedAddress: '',
},
email: "",
taxIdentity: "1",
}];
return result
},
//根据后台返回的productInfo,正确处理默认值
processDefaultDataByProductConfigList: function (defaultData, products) {
var deferred = Deferred();
var that = this;
deferred.resolve(defaultData);
return deferred.promise;
},
getDefaultschemaInfoService: function (urlParams) {
var that = this;
var result = [{ //保险方案信息
seqNo: '1',
organizationId: urlParams.organizationId, //组织id
type: urlParams.productNo,//类型
relationship: '-1',//与投保人的关系
birthday: '1990-01-01', //被保人生日
sex: '-1', //被保人性别
insureYear: '1', //保险期间
payEndYear: '-1',//交费期间
payInterval: '-1',//交费方式
getInterval: '-1',//年金领取方式
payEndYearFlag: 'Y',//缴费标识
riskCode: 'PMLP001',
insuYearFlag: 'A',
amnt: '',//保额
prem: '',//保费
mult: '1',
}];
// if (result.productNo == '701') {
// result[0].relationship = '-1'
// } else {
// result[0].relationship = '00'
// }
//根据orderType选取riskCode
var riskCode = "PNSD002"; //
var products = that.getDefaultCandidateArrayService(urlParams).products.products;
for (var i = 0; i < products.length; i++) {
var product = products[i];
if (product.productNo == urlParams.productNo) {
riskCode = product.riskCode
}
}
result[0].riskCode = riskCode;
return result;
},
getDefaultLCInsureImpartsService: function (urlParams) {
var pension801 = [
{ //健康告知信息
impartCode: 'IGI_801_1',
impartParammodle: '/',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_2',
impartParammodle: '///',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_3',
impartParammodle: '////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_4',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_5',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_6',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_7',
impartParammodle: '/////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_8',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_9',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_10',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_11',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_12',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_13',
impartParammodle: '/',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_801_14',
impartParammodle: '/',
impartResult: '0',
},
];
var pension605 = [
{ //健康告知信息
impartCode: 'IGI_605_1',
impartParammodle: '/',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_2',
impartParammodle: '///',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_3',
impartParammodle: '////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_4',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_5',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_6',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_7',
impartParammodle: '/////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_8',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_9',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_10',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_11',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_12',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_13',
impartParammodle: '/',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_605_14',
impartParammodle: '/',
impartResult: '0',
},
];
var pension603 = [
{ //健康告知信息
impartCode: 'IGI_603_1',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_603_2',
impartParammodle: '/',
impartResult: '0',
},
];
var pension701 = [
{ //健康告知信息
impartCode: 'IGI_701_1',
impartParammodle: '/',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_2',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_3',
impartParammodle: '/////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_4',
impartParammodle: '/////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_5',
impartParammodle: '/////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_6',
impartParammodle: '',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_7',
impartParammodle: '/////',
impartResult: '0',
},
{ //健康告知信息
impartCode: 'IGI_701_8',
impartParammodle: '/////',
impartResult: '0',
},
];
if (urlParams.productNo == 801) {
return pension801;
} else if (urlParams.productNo == 603) {
return pension603;
} else if (urlParams.productNo == 605) {
return pension605;
} else if (urlParams.productNo == 701) {
return pension701;
}
},
getDefaultcrsService: function (urlParams) {
return {
"residencePlace": {
"province": '',
"city": '',
"district": '',
"detailedAddress": ''
},
"residencePlaceNationality": 'CHN',
"birthPlace": {
"province": '',
"city": '',
"district": '',
"detailedAddress": ''
},
"birthPlaceNationality": '-1',
"taxResidents": [
{
"sn": '1',
"nation": "-1",
"taxPayerIdNumber": "",
"noTaxpayerIdNumberFlag": "",
"detailReason": ""
},
],
}
},
//组件
setUpWidgetService: function (form, widgetConfig) {
var deferred = Deferred();
var that = this;
//将配置自动化复制进组件
for (var x in widgetConfig) {
//取得组件实例 (创建一个独立的新对象)
var widget = $.extend({}, require('../widget/index')[widgetConfig[x].type]);
//将配置放进组件实例
for (var y in widgetConfig[x]) {
widget[y] = widgetConfig[x][y];
}
avalon.log("setUpWidgetService", x, form[x])
var value = form[x];
widget.setValue(value); //设置值的时候,组件会进行单位转换、拆解等操作
form[x] = widget
}
deferred.resolve(form);
// deferred.reject();
return deferred.promise;
},
getQueryString: function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
},
setOrderStatusForOrderList: function (orderList) {
console.log("setOrderStatusForOrderList()");
var result = true;
for (var i = 0; i < orderList.length; i++) {
var orderList_item = orderList[i];
if (orderList_item.orderStatus == '1') {
result = false;
break;
} else {
result = true;
}
}
return result;
},
//缓存接口
setOrderToCache: function (urlParams, order) {
var deferred = Deferred();
var that = this;
var prefix = that.getCacheNamePrefix(urlParams);
avalon.log('prefixprefix', prefix)
var cacheName = prefix + 'order';
var result = JSON.stringify(order);
window.newStorage.setItem(cacheName, result);
deferred.resolve(result);
return deferred.promise;
},
getOrderCache: function (urlParams) {
var that = this;
try {
var prefix = that.getCacheNamePrefix(urlParams);
var cacheName = prefix + 'order';
var result = window.newStorage.getItem(cacheName);
if (result) {
result = JSON.parse(result)
}
} catch (e) {
avalon.log(e)
}
return result;
},
deleteOrderCache: function (urlParams) {
var deferred = Deferred();
var that = this;
//删除缓存
try {
var form_order_widget = require('../widget/order_form');
form_order_widget.urlParams = urlParams;
form_order_widget.removeCache();//删除缓存
} catch (e) {
}
deferred.resolve();
return deferred.promise;
},
//服务
getCacheNamePrefix: function (urlParams) {
return urlParams.organizationId + '-' + urlParams.productNo + '-'
},
gethtmlUrl: function () {
var htmlUrl = window.location.href;
var splitedUrl = htmlUrl.indexOf("?");
splitedUrl = htmlUrl.substring(0, splitedUrl);
htmlUrl = splitedUrl.split('/');
htmlUrl = htmlUrl[htmlUrl.length - 1];
console.log(htmlUrl);
return htmlUrl;
},
extractUrlParams: function (url) {
var splitedUrl = url.indexOf("?");
var object = {};
splitedUrl = url.substring(splitedUrl + 1, url.length);
if (splitedUrl) {
var splitedParams = splitedUrl.split("&");
avalon.log("splitedUrl", splitedUrl);
for (var i = 0; i < splitedParams.length; i++) {
var param = splitedParams[i].split("=");
if (param[0]) {
param[1] = param[1].replace('#AgainForbidBack', '');
param[1] = param[1].replace('#ForbidBack', '');
object[param[0]] = param[1];
}
}
}
return object;
},
combineUrlWithParams: function (baseUrl, urlParams) {
var params = '';
var i = 0;
var length = Object.keys(urlParams).length;
for (var x in urlParams) {
i++;
if (i == length) {
params = params + x + "=" + urlParams[x];
} else {
params = params + x + "=" + urlParams[x] + "&";
}
avalon.log("key:" + x, urlParams[x]);
}
var url = baseUrl + "?" + params;
url = url.replace('#AgainForbidBack', '');
url = url.replace('#ForbidBack', '');
return url;
},
//日志
logToLocal: function () {
},
logToRemote: function () {
},
// 初始化
initwithLoginService: function () {
var deferred = Deferred();
var that = this;
var result = {
data: {}
};
//解释参数
var urlParams = that.extractUrlParams(window.location.href)
result.data.urlParams = urlParams;
that.getDefaultDataService(urlParams)
.then(function (data) {
for (var x in data.data) {
result.data[x] = data.data[x];
}
avalon.log('result', result);
return that.getProductConfigList(urlParams)
})
.then(function (products) {
result.data.products = products;
return that.processDefaultDataByProductConfigList(result.data, products)
})
.then(function (defaultData) {
result.data = defaultData;
return that.getUser(urlParams)
})
.then(function (data) {
if (data.code == 20000) { //未登录
throw new Exception(data.message);
} else {
result.data.userInfo = data.data;
result.data.auxProperties.isLogin = true;
deferred.resolve(result);
}
})
.otherwise(function (err) {
deferred.reject(err)
});
return deferred.promise;
},
initWithoutLoginService: function (url) {
var deferred = Deferred();
var that = this;
var result = {
data: {}
};
//解释参数
var urlParams = that.extractUrlParams(window.location.href)
result.data.urlParams = urlParams;
that.getDefaultDataService(urlParams)
.then(function (data) {
for (var x in data.data) {
result.data[x] = data.data[x];
}
avalon.log('result', result);
return that.getProductConfigList(urlParams)
})
.then(function (products) {
result.data.products = products;
result.data.productInfo = products[0];
avalon.log('121212', result.data.productInfo)
return that.processDefaultDataByProductConfigList(result.data, products)
})
.then(function (defaultData) {
result.data = defaultData;
return that.getUser(urlParams)
})
.then(function (data) {
if (data.code == 20000) { //未登录
result.data.auxProperties.isLogin = false;
} else {
result.data.userInfo = data.data;
result.data.auxProperties.isLogin = true;
}
deferred.resolve(result);
})
.otherwise(function (err) {
deferred.resolve(result)
});
return deferred.promise;
},
myBrowserType: function () {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIe11 = (/Trident\/7\.|Trident\/5\./).test(navigator.userAgent);
var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
if (isIE || isIe11) {
return true
} else {
return false
}
},
copyOrderIfExistCache: function (urlParams, result) {//获取接口缓存数据
var deferred = Deferred();
var that = this;
var cachePreFix = that.getCacheNamePrefix(urlParams);
var cacheName = cachePreFix + 'order';
var myBrowserType = that.myBrowserType();
var interfaceOrder = false;
if(myBrowserType){
that.getOpCache(urlParams,cacheName)
.then(function(order){
if(order){
interfaceOrder = JSON.parse(order);
}
deferred.resolve(interfaceOrder);
})
}else{
deferred.resolve(interfaceOrder);
}
return deferred.promise;
},
getcache: function (urlParams) {
var deferred = Deferred();
var that = this;
var myBrowserType = that.myBrowserType();
var cachePreFix = that.getCacheNamePrefix(urlParams);
var cacheName = cachePreFix + 'order';
var interfaceOrder = false;
if (myBrowserType) {
var orionLoginState = window.newStorage.getItem('orionLoginState');
if(orionLoginState != 1){
cacheName = 'orion-order';
var all_order = window.newStorage.getItem(cacheName + '-' + 'names');
if(!all_order){
all_order = '["applicant","insureds","risks","currentPremium","insuredAmount"]'
}
all_order = JSON.parse(all_order)
var order = {};
for (var i = 0; i < all_order.length; i++) {
order[all_order[i]] = window.newStorage.getItem(cacheName + '-' + all_order[i]);
if(order[all_order[i]]){
order[all_order[i]] = JSON.parse(order[all_order[i]]);
}
}
deferred.resolve(order);
}else{
that.getOpCache(urlParams,cacheName)
.then(function(order){
if(order){
interfaceOrder = JSON.parse(order);
}
deferred.resolve(interfaceOrder);
})
}
} else {
var all_order = window.newStorage.getItem(cacheName + '-' + 'names');
if(!all_order){
all_order = '["applicant","insureds","risks","currentPremium","insuredAmount"]'
}
all_order = JSON.parse(all_order)
var order = {};
for (var i = 0; i < all_order.length; i++) {
order[all_order[i]] = window.newStorage.getItem(cacheName + '-' + all_order[i]);
if(order[all_order[i]]){
order[all_order[i]] = JSON.parse(order[all_order[i]]);
}
}
deferred.resolve(order);
}
return deferred.promise;
},
setRelationshipConfig: function (result) {
avalon.log('setRelationshipConfig', result)
var relationshipAgeRangeArrays = result.ageRangeConfigs;
avalon.log("setRelationshipConfig()", relationshipAgeRangeArrays, typeof relationshipAgeRangeArrays)
var resultJson = {};
if (relationshipAgeRangeArrays) {
for (var i = 0; i < relationshipAgeRangeArrays.length; i++) {
var relationshipItem = relationshipAgeRangeArrays[i];
avalon.log('relationshipAgeRangeArrays[i]', relationshipItem.relationship, relationshipItem)
resultJson[relationshipItem.relationship] = {
start: {type: relationshipItem.endFlag, value: relationshipItem.endAge},
end: {type: relationshipItem.startFlag, value: relationshipItem.startAge},
};
}
avalon.log("resultJson", resultJson)
}
return resultJson
},
getLastPayDay: function (birthday, updateDate, endDate) {
//这个过滤器是比较订单的当前十五天内、开放期内和生日的日期,决定用户在什么时间内支付完成的
//如果用户的订单开放期和生日都在当前十五天内,开放期少于生日,以开放期为准/开放期大于于生日,以生日为准
//如果用户的订单开放期和生日都不在当前十五天内,以十五天为准
var lastPayDay;
var now = new Date();//定义now等于当前的日期
// updateDate = now.getTime();
var fifteenDaysMilliseconds = 15 * 86400000;//计算15天的总共的毫秒数
var nowMMilliseconds = now.getTime();
endDate = endDate.replace(/\-/g, '/');//将字符串形式的日期转换成日期对象
endDate = new Date(endDate);//转成真正能拿到毫秒数的格式(实例化一个日期)
birthday = new Date(birthday);//被保人的出生日期 //字符串日期格式
birthday = new Date(now.getFullYear() + '/' + (birthday.getMonth() + 1) + '/' + birthday.getDate());//转换成对象拿到当前的用户的生日;
var updateDateDay = new Date(updateDate);//最后操作订单的时间
updateDateDay = new Date(updateDateDay.getFullYear() + '/' + (updateDateDay.getMonth() + 1) + '/' + updateDateDay.getDate());//转化成对象格式
var birthdayMilliseconds = birthday.getTime();//将生日日期转成毫秒数
var endDateMilliseconds = endDate.getTime();//将结束日日期转成毫秒数
var updateDateMilliseconds = updateDateDay.getTime();//开发日期
var updateDateAdd15DayMilliseconds = updateDate + fifteenDaysMilliseconds;//开放日期加上15天的毫秒数
var birthday_ = false;
var endDate_ = false;
if (birthdayMilliseconds >= updateDateMilliseconds && birthdayMilliseconds <= updateDateAdd15DayMilliseconds) {//如果出生日期毫秒数大于等于开放日期并且出生日期毫秒数小于等于开放日期加上15天的毫秒数则birthday_为true
birthday_ = true;
}
if (endDateMilliseconds >= updateDateMilliseconds && endDateMilliseconds <= updateDateAdd15DayMilliseconds) {//如果结束日期大于开放日期毫秒数并且结束日期小于等于开放日期加上15天的毫秒数则endData_为true
endDate_ = true;
}
if (birthday_) {//如果存在birthday_
if (endDate_) {
if (birthdayMilliseconds > endDateMilliseconds) {
console.log('结束期为准');
endDateMilliseconds = endDateMilliseconds + 86400000;
lastPayDay = new Date(endDateMilliseconds)
} else {
console.log('生日为准');
birthdayMilliseconds = birthdayMilliseconds - 86400000;
lastPayDay = new Date(birthdayMilliseconds)
}
} else {
console.log('生日为准01');
birthdayMilliseconds = birthdayMilliseconds - 86400000;
lastPayDay = new Date(birthdayMilliseconds)
}
} else if (endDate_) {//如果存在endData_
console.log('结束期为准01');
endDateMilliseconds = endDateMilliseconds + 86400000;
lastPayDay = new Date(endDateMilliseconds)
} else {
console.log('十五天内为准');
lastPayDay = new Date(updateDateAdd15DayMilliseconds)
}
var display = lastPayDay.getFullYear() + '年' + (lastPayDay.getMonth() + 1) + '月' + lastPayDay.getDate() + '日';
console.log('++++++++++++++++++++++++ payday', display);
return display
},
getDayAddOne: function (date) {
var now = new Date(date);
var nowTime = now.getTime();
nowTime += 86400000;
var lastPayDay = new Date(nowTime);
var display = lastPayDay.getFullYear() + '年' + (lastPayDay.getMonth() + 1) + '月' + lastPayDay.getDate() + '日';
return display
},
setWindowPeriod: function (product) {
var num = 0; // 1-窗口期 2-已过窗口期/缓存期 3-已过缓存期
if (product.companyConfig.openPeriod) {
num = 1
} else {
if (product.companyConfig.bufferPeriod) {
num = 2
} else {
num = 3
}
}
return num
},
setWindowHistoryPushState_2: function () {//处理某些浏览器回退按钮不重新刷新页面
(function () {
var isPageHide = false;
window.addEventListener('pageshow', function () {
if (isPageHide) {
window.location.reload();
}
});
window.addEventListener('pagehide', function () {
isPageHide = true;
});
})();
},
distinguishGroup: function (orderType) {//用于区分是否接口名是否需要添加 group
var result = false;
for (var i = 0; i < config.distinguishGroups.length; i++) {
var item = config.distinguishGroups[i];
if (item == orderType) {
result = true
}
}
return result
},
distinguishHasHealthPage: function (orderType) {
var result = true;
for (var i = 0; i < config.distinguishHasHealthPage.length; i++) {
var item = config.distinguishHasHealthPage[i];
if (item == orderType) {
result = false
}
}
return result
},
childAgeRangeArrays: function (data) {
var deferred = Deferred();
var childAgeRangeArrayType = 0;
if (data.relationshipAgeRangeArrays) {
for (var item in data.relationshipAgeRangeArrays) {
if (item == '03') {
var child = data.relationshipAgeRangeArrays[item];
var child_json = JSON.parse(child);
if (parseInt(child_json.end) >= 8) {
childAgeRangeArrayType = 2
} else {
childAgeRangeArrayType = 1
}
}
}
}
deferred.resolve(childAgeRangeArrayType);
return deferred.promise;
},
setLoginMethodToLogin: function (loginMethod, isAuthImage) {
var displayList = {
employeeIdtype: ['7'],//证件类型
employeeIdno: ['7', '8', '9'],//证件号
employee_number: ['1', '4', '5'],//工号
employee_name: ['1', '4', '5', '6', '8', '9'],//姓名
mobile_phone: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],//姓名手机号码
verification_code: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],//短信验证码
authImage_Code: [],//图形验证码
};
if (isAuthImage == '1') {
displayList.authImage_Code.push(loginMethod)
}
return displayList
},
bubbleSort: function (birthdaysInMills) {
var that = this;
var len = birthdaysInMills.length, j;
var temp;
while (len > 1) {
for (j = 0; j < len - 1; j++) {
if (birthdaysInMills[j] > birthdaysInMills[j + 1]) {
temp = birthdaysInMills[j];
birthdaysInMills[j] = birthdaysInMills[j + 1];
birthdaysInMills[j + 1] = temp;
}
}
len--;
}
return birthdaysInMills;
},
getCamparedLastPayDay: function (birthdaysInMills) {
var that = this;
var lastPayDayInMills = new Date(that.bubbleSort(birthdaysInMills)[0])
return lastPayDayInMills.getFullYear() + '年' + (lastPayDayInMills.getMonth() + 1) + '月' + lastPayDayInMills.getDate() + '日'
},
setIsSelectAdditionalFlag: function (order_to_premiul_trial_form_widget) {
var isSelectAdditionalFlag = 0;
try {
isSelectAdditionalFlag = ((order_to_premiul_trial_form_widget.form[2].selected == 1)) ? 1 : 0;
} catch (error) {
}
return isSelectAdditionalFlag
},
setIsSelectExemptionFlag: function (order_to_premiul_trial_form_widget) {//设置新加的豁免险的是否勾选的逻辑
var isSelectExemptionFlag = 0;
try {
isSelectExemptionFlag = ((order_to_premiul_trial_form_widget.form[1].selected == 1)) ? 1 : 0;
} catch (error) {
}
return isSelectExemptionFlag
},
setCommonParams: function (params, orderListHolder) {
params.color = orderListHolder.color;
params.product = orderListHolder.product;
params.productNo = orderListHolder.productNo;
return params;
},
setSpecialOrganizationId: function (urlParams, config, relationships) {
if (urlParams.organizationId == config.specialOrganizationId && relationships == '00') {
return false
} else {
return true
}
},
copyAppntInfoFromHistoryService: function (urlParams) {
var deferred = Deferred();
var that = this;
var newParams = JSON.parse(JSON.stringify(urlParams));
delete newParams['productNo'];//需要获取所有的订单
var result = {
appntInfo: '',
oldappntInfo: '',
};
that.getOrderList(newParams)
.then(function (data) {
var orderList = data.data;
for (var i = 0; i < orderList.length; i++) {
if (orderList[i].orderStatus != 0) {
result.appntInfo = orderList[i].appntNew;
result.oldappntInfo = orderList[i].appntNew
}
}
deferred.resolve(result)
})
.otherwise(function (msg) {
deferred.reject(msg)
});
return deferred.promise;
},
getPDFList: function (specialType, isShowTouBao) {
/**
* 特约类型
* 1.核心加费特约
* 2.核心除外特约
* 3.核心加费+除外特约
* 4.天秤加费特约
* 5.天秤除外特约
* 6.天秤加费+除外特约
* private Integer specialType;
*/
var result = [
{
item: {name: '责任免除约定书', id: 'qrcw', key: 'qrcw', hasClicked: false},
bool: (specialType == '5' || specialType == '6') ? true : false,
fileType: '16',
},
{
item: {name: '保费调价约定书', id: 'jfyds', key: 'jfyds', hasClicked: false},
bool: (specialType == '4' || specialType == '6') ? true : false,
fileType: '18',
},
{
item: {name: '保费调价约定书', id: 'bftjyds', key: 'bftjyds', hasClicked: false},
bool: (specialType == '1' || specialType == '3') ? true : false,
fileType: '18',
},
{
item: {name: '责任免除约定书', id: 'cwyds', key: 'cwyds', hasClicked: false},
bool: (specialType == '2' || specialType == '3') ? true : false,
fileType: '16',
},
{
item: {name: '投保单', id: 'tbd', key: 'tbd', hasClicked: false},
bool: isShowTouBao,
fileType: '11',
},
];
return result
},
getPreviewAndConfirmOrderItemList: function (specialType, fileList, isShowTouBao) {
var that = this;
var arr = [];
var isShowTouBao = isShowTouBao || false;
var result = that.getPDFList(specialType, isShowTouBao);
function getFile(fileList, fileType) {
var file = '';
if (fileList.pdf) {
for (var j = 0; j < fileList.pdf.length; j++) {
var item = fileList.pdf[j]
if (item.type == fileType) {
file = item.file;
break;
}
}
}
return file;
};
for (var i = 0; i < result.length; i++) {
var element = result[i]
if (element.bool) {
element.item.file = getFile(fileList, element.fileType);
that.downloadFilePdf(window.urlParams, element);
arr.push(element.item)
}
}
return arr
},
getPreviewAndConfirmOrderItemId: function (specialType, fileList) {
var that = this;
var arr = [];
var result = that.getPDFList(specialType);
for (var i = 0; i < result.length; i++) {
arr.push(result[i].item.key);
}
return arr
},
getPdfUrlCache: function (id) {
var that = this;
var url = localStorage.getItem('orion_' + id);
return url
},
setExceptionStatus: function (result, urlParams) {
var that = this
if (result.data.order.insureds[0].specialType == 1 || result.data.order.insureds[0].specialType == 2 || result.data.order.insureds[0].specialType == 3) {
result.data.auxProperties.coreConfirmException = true
} else {
result.data.auxProperties.coreConfirmException = false;
//是否需要确认除外(同电子签名)
if (result.data.order.insureds[0].specialType == 4 || result.data.order.insureds[0].specialType == 5 || result.data.order.insureds[0].specialType == 6) {
if (result.data.order.insureds[0].agreeSpecial == 0 || result.data.order.insureds[0].agreeSpecial == 1) {
result.data.auxProperties.needToConfirmException = true;
} else {
result.data.auxProperties.needToConfirmException = false;
}
} else {
result.data.auxProperties.needToConfirmException = false;
}
}
},
needSignCheck: function (result) {//判断是否是需要签名按钮显示的和头部顶栏的显示的
var item = {
coreConfirmException: false,
needToConfirmException: false,
}
if (result.data.order.insureds[0].specialType == 1 ||
result.data.order.insureds[0].specialType == 2 ||
result.data.order.insureds[0].specialType == 3) {
item.coreConfirmException = true
} else {
item.coreConfirmException = false;
//是否需要确认除外(同电子签名)
if (result.data.order.insureds[0].specialType == 4 ||
result.data.order.insureds[0].specialType == 5 ||
result.data.order.insureds[0].specialType == 6) {
if (result.data.order.insureds[0].agreeSpecial === 0 ||
result.data.order.insureds[0].agreeSpecial === 1) {
item.needToConfirmException = true;
} else {
item.needToConfirmException = false;
}
} else {
item.needToConfirmException = false;
}
}
return item
},
getProducts_product: function (productNo) {
var data = [
{product: 'akg', name: '安康团险', productNo: 702, group: true},//添加了快钱签约 添加了线上照会功能
{product: 'aki', name: '安康个险', productNo: 701, group: false},//添加了快钱签约 添加了线上照会功能
];
for (var i = 0; i < data.length; i++) {
var product = data[i]
if (product.productNo == productNo) {
return product.product
}
}
},
resolveUploadType: function (order) {
/**
* 解析订单uploads数据
*/
var data = {
uploadBodyCheck: '1',//体检文件
uploadIdcard: '2',//被保人身份证件文件
uploadIdcardRelationProve: '3',//关系证明文件
uploadHandIdcard: '4',//手持证件照
uploadOcrFront: '5',//ocr身份证正面
uploadOcrBack: '6',//ocr身份证反面
uploadMedicalRecord: '7',//病历的文件类型
}
for (var x in data) {
if (order.applicant) {
order.applicant[x] = -1;
if (order.applicant.uploads) {
for (var i = 0; i < order.applicant.uploads.length; i++) {
var applicant_upload = order.applicant.uploads[i]
if (applicant_upload.uploadType == data[x]) {
order.applicant[x] = 0
}
}
}
}
if (order.insureds) {
for (var i = 0; i < order.insureds.length; i++) {
var insured = order.insureds[i]
insured[x] = -1
if (insured.uploads) {
for (var j = 0; j < insured.uploads.length; j++) {
var insured_upload = insured.uploads[j]
if (insured_upload.uploadType == data[x]) {
insured[x] = 0
}
}
}
}
}
}
console.log('order_order', order)
return order;
},
getNextPageByCode: function (code, params, redirectUrl) {
var that = this
//前端根据 nextStep 中的code去判断下一步做什么操作
// nextStep code 解释:
// 001 去订单页
// 002 去天秤页(目前是后台进行跳转) (暂时不用处理)
// 003 TSA一个提示按钮的提示
// 004 TSA两个提示按钮的提示
// 005 一个确认按钮的提示
// 006 提示预留1
// 007 提示预留2
// 008 去普通健康告知页
// 009 去支付签约页
// 010 去税收居民页(投保人)
// 011 去税收居民页(被保人)