igi_orion_cignacmb
Version:
Censors words out of text
1,200 lines (1,161 loc) • 62.4 kB
JavaScript
var service = require('../service/CentralService');
var config = require('../config/config');
var ClipboardJS = require('../../bower_components/clipboard/clipboardDemo/dist/clipboard.min');//复制包
var md5 = require('../lib/util/md5')
//TODO 检测调用服务没有 try catch
//TODO 检测调用 promise 服务没有 otherwise
var centralController = {
$id: 'vm',
config: config,
$listeners: [],
service: service,
md5: md5,
singleProduct: '', //是否单产品项目
urlParams: '',
imgs: {},
candidateArrays: '',
auxProperties: {isLogin: false},
productInfo: '',
products: '',
userInfo: '',
order: '',
appntInfo: '',
insuredInfos: '',
schemaInfo: '',
LCInsureImparts: '',
judgementCase: '',//用于判断产品详情页案例显示
mobile: '',
terminalType: '',
isSpecialOrganizationId: true,
trialReturnData: {
needHealthCheck: false,//是否需要体检
healthCheckItem: '',//体检项目
maximumHealthCheckAmount: 0,//最高免体检额
},
getNewData: function (dateTemp, days) {
var dateTemp = dateTemp.split("-");
var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式
var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
var rDate = new Date(millSeconds);
var year = rDate.getFullYear();
var month = rDate.getMonth() + 1;
if (month < 10) month = "0" + month;
var date = rDate.getDate();
if (date < 10) date = "0" + date;
return (year + "-" + month + "-" + date);
},
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) {
return ("输入的日期格式错误!");
}
},
submitQuestionForm: function (orderToPost) {
var that = this;
$('body').append('<form id="questionnaire" method="post" action="' + that.config.questionnaireUrl + '"></form>');
$('#questionnaire').append('<input type="hidden" name="orderId" value="' + orderToPost.orderId + '">');
$('#questionnaire').append('<input type="hidden" name="insuredseqNo" value="' + orderToPost.insuredseqNo + '">');
$('#questionnaire').append('<input type="hidden" name="insuredIdno" value="' + orderToPost.insuredIdno + '">');
$('#questionnaire').append('<input type="hidden" name="insuredIdtype" value="' + orderToPost.insuredIdtype + '">');
$('#questionnaire').submit();
},
goToThirdPartyQuestionnaire: function () { //跳转第三方问卷平台
try {
} catch (e) {
alert(e)
}
},
//导航
setParmsUrl: function (urlParams) {
var that = this;
if (that.products) {
if (that.products instanceof Array) {
products = that.products
} else {
products.push(that.products)
}
if (urlParams.productNo && urlParams.organizationId) {
if (!urlParams.product) {
urlParams.product = that.products[0].companyConfig.product;
}
} else {
// urlParams.source = that.products[0].source;//companyId替换为organizationId
urlParams.organizationId = that.products[0].companyConfig.organizationId;
urlParams.productNo = that.products[0].companyConfig.productNo;
urlParams.product = that.products[0].companyConfig.product;
}
}
return urlParams;
},
goToIndex: function () {
try {
var that = this;
var urlParams = that.urlParams.$model;
if (!urlParams) {
urlParams = that.service.extractUrlParams(window.location.href)
}
urlParams = that.setParmsUrl(urlParams);
// var url = that.service.combineUrlWithParams('index.html', urlParams)
var url = that.service.combineUrlWithParams('index.html', urlParams);
window.location.href = url
} catch (e) {
alert(e)
}
},
goToDetail: function () {
try {
var that = this;
// var urlParams = that.urlParams.$model;
// if (!urlParams) {
// urlParams = that.service.extractUrlParams(window.location.href)
// }
var urlParams = that.service.extractUrlParams(window.location.href)
delete urlParams['next'];
delete urlParams['resident_flag'];
delete urlParams['uploadType'];
delete urlParams['id'];
delete urlParams['orderId'];
if (urlParams.configId) {
}
// var url = that.service.combineUrlWithParams(urlParams.source + '-' + 'detail.html',
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams('orion' + '-' + 'detail.html', urlParams);
window.location.href = url
} catch (e) {
alert(e)
}
},
goToMyOrder: function () {
try {
var that = this;
var urlParams = that.urlParams.$model;
if (!urlParams) {
urlParams = that.service.extractUrlParams(window.location.href)
}
if (urlParams.token) {
urlParams.igiToken = urlParams.token
}
that.showLoading();
that.service.getUser()
.then(function (data) {
if (data.code == 200) {
delete urlParams['resident_flag'];
delete urlParams['uploadType'];
delete urlParams['id'];
delete urlParams['orderId'];
delete urlParams['token'];
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams('myOrder.html', urlParams);
window.location.href = url;
} else if (data.code == 20000) {
modal.open({
text: '您尚未登录,点击确定为您跳转至登录页',
buttons: [
{
text: '确定',
callback: function () {
urlParams = that.setParmsUrl(urlParams);
urlParams.next = 'myOrder.html';
var url = that.service.combineUrlWithParams('login.html', urlParams);
window.location.href = url;
// if (callback) {
// callback()
// } else {
// if (that.isGoToLogin(errs)) {//products[0].companyConfig.loginMethod11-信诺登录平台登录方式,
// that.goToLogin()
// }
// }
}
}
]
})
} else {
that.handleTips(data.message);
}
that.showLoading();
})
.otherwise(function (msg) {
that.showLoading();
that.handleTips(msg);
})
} catch (e) {
alert(e)
}
},
getLoginMethod: function () {
var that = this;
var loginMethod = '';
console.log('123', window.products)
if (window.products instanceof Array) {
loginMethod = window.products[0].companyConfig.loginMethod
} else {
loginMethod = window.products.companyConfig.loginMethod
}
return loginMethod
},
logOut: function () {
try {
var deferred = Deferred();
var that = this;
var urlParams = that.service.extractUrlParams(window.location.href);
that.service.logOut(urlParams)
.then(function (data) {
var loginMethod = that.getLoginMethod();
if (loginMethod != 11) {//products[0].companyConfig.loginMethod11-信诺登录平台登录方式,
that.handleTips([
{
type: 'modal',
msg: '您已成功退出登录',
code: 1,
callback: function () {
delete urlParams['next'];
delete urlParams['resident_flag'];
delete urlParams['uploadType'];
delete urlParams['id'];
delete urlParams['orderId'];
delete urlParams['igiToken'];
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams(
'login.html',
urlParams
);
window.location.href = url
}
}
])
} else {//products[0].companyConfig.loginMethod非11-客户端平台登录方式(第三方登录平台)
that.handleTips([
{
type: 'modal',
msg: '您已成功退出登录',
code: 1,
callback: function () {
}
}
]);
}
})
.otherwise(function (errs) {
that.handleTips(errs)
});
deferred.resolve();
// deferred.reject();
return deferred.promise
} catch (e) {
alert(e)
}
},
takeOut: function (productNo, extraParams) {
try {
var that = this;
if (extraParams) that.urlParams = $.extend({}, that.urlParams, extraParams);
that.service.getUser(that.urlParams)
.then(function (data) {
if (data.code == 20000) {
var urlParams = that.urlParams;
delete urlParams['id'];
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams('orion' + '-2.html', urlParams);
window.location.href = url
} else {
that.service.getList()
.then(function (data) {
var urlParams = that.urlParams;
if (data.code == 200) {
var orders = data.data;
if (orders.length > 0) {
//存在订单
//判断是否草稿单
var isDraft_edit = false;
var isDraft_uncertain = false;
var isHasNotFinish = false;
for (var x in orders) {
console.log('123', urlParams)
if (orders[x].productNo != urlParams.productNo) {
continue;
}
if (orders[x].orderStatus == '000' || orders[x].orderStatus == '001' || orders[x].orderStatus == '002') {
isDraft_edit = true;
break
} else if (orders[x].orderStatus == 100) {//待处理
isDraft_uncertain = true;
break
} else {
if (orders[x].orderStatus != 1000) {//已完成
isHasNotFinish = true
}
}
}
if (isDraft_edit) {
//判断是否有草稿单
modal.open({
text: '您已有草稿订单,将跳转到订单列表页',
buttons: [
{
text: '确定',
callback: function () {
var baseUrl = 'myOrder.html';
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams(
baseUrl,
urlParams
);
window.location.href = url
}
}
]
})
} else if (isDraft_uncertain) {
//判断是否有草稿单
modal.open({
text: '您有待处理订单,请更新订单状态后再继续投保',
buttons: [
{
text: '确定',
callback: function () {
var baseUrl = 'myOrder.html';
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams(
baseUrl,
urlParams
);
window.location.href = url
}
}
]
})
} else {
//无草稿单
if (isHasNotFinish) {
//判断是否有未完成的订单
modal.open({
text: '您有未完成订单,是否跳转到订单列表页完成投保',
buttons: [
{
text: '以后再说',
callback: function () {
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
delete urlParams['id'];
urlParams = that.setParmsUrl(urlParams);
// var url = that.service.combineUrlWithParams(urlParams.source + '-2.html', urlParams)
var url = that.service.combineUrlWithParams('orion' + '-2.html', urlParams);
window.location.href = url
}
},
{
text: '现在跳转',
callback: function () {
var baseUrl = 'myOrder.html';
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams(
baseUrl,
urlParams
);
window.location.href = url
}
}
]
})
} else {
//没有
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
delete urlParams['id'];
urlParams = that.setParmsUrl(urlParams);
// var url = that.service.combineUrlWithParams(urlParams.source + '-2.html', urlParams)
var url = that.service.combineUrlWithParams('orion' + '-2.html', urlParams)
window.location.href = url
}
}
} else {
//无订单
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
delete urlParams['id'];
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams('orion' + '-2.html', urlParams);
window.location.href = url
}
} else {
that.handleTips(data.message)
}
})
.otherwise(function (err) {
that.handleTips(err)
})
}
})
.otherwise(function (err) {
if (err.code == 20000) {
var urlParams = that.urlParams.$model;
urlParams.productNo = productNo;
// var url = that.service.combineUrlWithParams(urlParams.source + '-2.html', urlParams)
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams('orion' + '-2.html', urlParams);
window.location.href = url
} else {
that.handleTips(err)
}
})
} catch (e) {
alert(e)
}
},
goToLogin: function (createOrder, isSelectAdditionalFlag, isSelectExemptionFlag) {
try {
var that = this;
var urlParams = that.urlParams.$model;
if (!urlParams) {
urlParams = that.service.extractUrlParams(window.location.href)
}
if (createOrder == '1') {
urlParams['createOrder'] = 1;
}
var htmlUrl = ['orion-2.html', 'orion-detail.html']
var next = that.service.gethtmlUrl();
if (htmlUrl.indexOf(next) != -1) {
urlParams['next'] = next;
}
if (isSelectAdditionalFlag != undefined) {
urlParams['isSelectAdditionalFlag'] = isSelectAdditionalFlag;
}
if (isSelectExemptionFlag != undefined) {
urlParams['isSelectExemptionFlag'] = isSelectExemptionFlag;
}
try {
// 删除无用的参数
delete urlParams['resident_flag'];
delete urlParams['uploadType'];
delete urlParams['id'];
delete urlParams['orderId']
} catch (e) {
}
urlParams = that.setParmsUrl(urlParams);
var url = that.service.combineUrlWithParams('login.html', urlParams)
window.location.href = url
} catch (e) {
alert(e)
}
},
//监听
bindListeners: function () {
},
unBindListeners: function () {
//解绑所有控制器
try {
var that = this;
$('.watch').off('change');
$('.watch').off('blur');
for (var i = 0; i < that.$listeners.length; i++) {
try {
var $listener = that.$listeners[i];
$listener()
} catch (e) {
}
}
} catch (e) {
alert(e)
}
},
checkBrowser: function () {
//检测浏览器版本
try {
var that = this;
var deferred = Deferred();
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isOpera = userAgent.indexOf('Opera') > -1; //判断是否Opera浏览器
var isIE =
userAgent.indexOf('compatible') > -1 &&
userAgent.indexOf('MSIE') > -1 &&
!isOpera //判断是否IE浏览器
if (isIE) {
var IE55 = false;
var IE6 = false;
var IE7 = false;
var IE8 = false;
var IE9 = false;
var reIE = new RegExp('MSIE (\\d+\\.\\d+);');
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp['$1']);
IE9 = fIEVersion == 9.0;
if (IE55) {
that.auxProperties.isIEType = true;
}
if (IE6) {
that.auxProperties.isIEType = true;
}
if (IE7) {
that.auxProperties.isIEType = true;
}
if (IE8) {
that.auxProperties.isIEType = true;
}
if (IE9) {
that.auxProperties.isIEType = true;
}
}
deferred.resolve();
return deferred.promise
} catch (e) {
alert(e)
}
},
//组件
widgetValidate: function (object) {
//统一对组件进行验证
try {
var errs = [];
for (var x in object) {
if (object[x] && typeof object[x] == 'object' && object[x].validate) {
var validateResult = object[x].validate();
if (validateResult) {
errs = errs.concat(validateResult);
}
}
}
return errs.length > 0 ? errs : null;
} catch (e) {
alert(e)
}
},
widgetFix: function (object) {
//统一对组件进行自修复
try {
var that = this;
var deferred = Deferred();
for (var x in object) {
if (object[x] && typeof object[x] == 'object' && object[x].fix) {
object[x].fix();
}
}
return deferred.promise
} catch (e) {
// alert(e)
}
},
converWidgetToData: function (object) {
//统一对组件进行数据转换
try {
var data = {};
for (var x in object) {
if (object[x] && typeof object[x] == 'object' && object[x].getValue) {
object[x] = data[x] = object[x].getValue()
} else {
data[x] = object[x]
}
}
return data
} catch (e) {
alert(e)
}
},
//提示
handleSingleTipsByType: function (err) {
var that = this;
try {
if (err.type == 'alert') {
alert(err.msg)
} else if (err.type == 'tooltip') {
if (err.id) {
$('#' + err.id).attr('title', err.msg);
$('#' + err.id).attr('data-original-title', err.msg);
$('#' + err.id).tooltip();
$('#' + err.id).tooltip('show', {title: err.msg});
setTimeout(function () {
$('#' + err.id).tooltip('destroy');
}, 5000)
}
// if (that.mobile) {
// $('.konwfooter').tooltip('show');
// setTimeout(function () {
// $('.konwfooter').tooltip('destroy');
// }, 5000)
// }
} else if (err.type == 'popover') {
avalon.log('124423424', err)
avalon.log('err.id', err.id)
avalon.log('err.msg', err.msg)
$('#' + err.id)
.addClass('errorClass')
.attr('data-toggle', 'popover')
.attr('data-placement', 'top')
.attr('data-content', err.msg)
.popover('show')
$('html,body').animate({
scrollTop: $('#' + err.id).offset().top - 300
}, '400')
var timer = setTimeout(function () {//2020-02-17发现
$('#' + err.id).popover('destroy')
.removeClass('errorClass')
clearTimeout(timer)
}, 3000)
} else if (err.type == 'popover_and_red') {
$('#' + err.id)
.addClass('error_red')
.attr('data-toggle', 'popover')
.attr('data-placement', 'top')
.attr('data-content', err.msg)
.popover('show')
$('html,body').animate({
scrollTop: $('#' + err.id).offset().top - 300
}, '400')
var timer = setTimeout(function () {//2020-02-17发现
$('#' + err.id).popover('destroy')
.removeClass('error_red')
clearTimeout(timer)
}, 3000)
} else if (err.type == 'modal') {
if (err.callback) {
modal.open({
text: err.msg,
buttons: [
{
text: '确定',
callback: err.callback
}
]
})
// alertModal.open(err.msg, err.callback)
} else {
modal.open({
text: err.msg,
buttons: [
{
text: '确定'
}
]
})
// alertModal.open(err.msg)
}
} else if (err.type == 'toast') {
if (err.msg) {
toast.open(err.msg, err.callback)
} else {
toast.open(err.msg)
}
} else if (err.type == 'jump') {
window.location.href = err.data;
}
} catch (e) {
alert(e)
}
},
isGoToLogin: function (errs) {
var that = this;
var result = false;
var loginMethod = that.getLoginMethod();
if (loginMethod != 11) {//products[0].companyConfig.loginMethod11-信诺登录平台登录方式,
if (errs.indexOf('登录已失效') > -1 || errs.indexOf('您尚未登录') > -1) {
result = true
} else {//products[0].companyConfig.loginMethod非11-客户端平台登录方式(第三方登录平台)
}
}
return result
},
handleTips: function (errs, callback) {//处理不同类型的错误提示
try {
var that = this;
var typeOfError = typeof errs;
avalon.log('typeOfErrortypeOfError', typeOfError)
that.testMobileOrPc();
if (typeOfError == 'object') {
if (errs instanceof Array) {
for (var i = 0; i < errs.length; i++) {
var err = errs[i];
avalon.log('errereerr', err)
if (err.code && err.code == -401) {
that.handleTips(err.msg)
} else {
that.handleSingleTipsByType(errs[0])
}
}
} else {
// alert(0)
that.handleSingleTipsByType(errs)
}
} else if (typeOfError == 'string') {
modal.open({
text: errs,
buttons: [
{
text: '确定',
callback: function () {
if (callback) {
callback()
} else {
if (that.isGoToLogin(errs)) {//products[0].companyConfig.loginMethod11-信诺登录平台登录方式,
that.goToLogin()
}
}
}
}
]
})
}
} catch (e) {
alert(e)
}
},
noLoginModel: function (callback) {
modal.open({
text: '您尚未登录,点击确定为您跳转至登录页',
buttons: [
{
text: '确定',
callback: function () {
if (callback) {
callback()
}
}
}
]
})
},
initView: function () {//初始化
try {
var that = this
that.testMobileOrPc()
} catch (e) {
alert(e)
}
},
init: function () {
try {
var that = this
var url = window.location.href
var urlParams = that.service.extractUrlParams(url)
that.urlParams = urlParams
that.service
.initWithoutLoginService(url)
.then(function (data) {
for (var x in data.data) {
that[x] = data.data[x]
}
setTimeout(function () {
that.bindListeners()
that.initView()
}, 500)
})
.otherwise(function (errs) {
that.handleTips(errs)
})
} catch (e) {
alert(e)
}
},
testMobileOrPc: function () {
try {
var that = this;
var width = 0;
if (document.body.clientWidth > window.screen.availWidth) {
width = window.screen.availWidth
} else {
width = document.body.clientWidth
}
if (width < 768) {
that.mobile = true
that.terminalType = "mobile";
} else {
that.mobile = false
that.terminalType = "pc";
}
$(window).resize(function () {
// document.body.clientWidth
var width = 0;
if (document.body.clientWidth > window.screen.availWidth) {
width = window.screen.availWidth
} else {
width = document.body.clientWidth
}
if (width < 768) {
that.mobile = true
that.terminalType = "mobile";
} else {
that.mobile = false
that.terminalType = "pc";
}
})
} catch (e) {
alert(e)
}
},
myBrowserType: function myBrowserType() {
try {
var userAgent = navigator.userAgent //取得浏览器的userAgent字符串
var isOpera = userAgent.indexOf('Opera') > -1 //判断是否Opera浏览器
var isIE =
userAgent.indexOf('compatible') > -1 &&
userAgent.indexOf('MSIE') > -1 &&
!isOpera //判断是否IE浏览器
if (isIE) {
return true
} else {
return false
}
} catch (e) {
alert(e)
}
},
// 转为unicode 编码
encodeUnicode: function (str) {
var res = [];
for (var i = 0; i < str.length; i++) {
res[i] = ("00" + str.charCodeAt(i).toString(16)).slice(-4);
}
return "\\u" + res.join("\\u");
},
// 解码
decodeUnicode: function (str) {
str = str.replace(/\\/g, "%");
return unescape(str);
},
showLoading: function () {
if (window.loading) {
window.loading.open();
}
},
hideLoading: function () {
if (window.loading) {
window.loading.close();
}
},
clipboardText: function (clipBoardText, success) {//复制粘贴板逻辑
var clipboard = new ClipboardJS('.clipboard', {
text: function () {
return clipBoardText;
}
});
clipboard.on('success', function (e) {
if (success) {
success();
}
});
clipboard.on('error', function (e) {
});
},
setSelectHtmlForId: function (isId, htmlId, allSelects, defaultSelectsHtml, defaultSelectsValue, chooseSelectsValue, keyValue) {
var result = {
isId: isId ? isId : false,
htmlId: htmlId ? htmlId : '',//需要设置的id
allSelects: allSelects ? allSelects : '',//全部可选内容
defaultSelectsHtml: defaultSelectsHtml ? defaultSelectsHtml : '',//默认未选中的情况
defaultSelectsValue: defaultSelectsValue ? defaultSelectsValue : '',//默认未选中的情况
chooseSelectsValue: chooseSelectsValue ? chooseSelectsValue : '',//选中的内容
needAddHtml: '',//需要设置的html内容
};
if (defaultSelectsHtml) {
result.needAddHtml = '<option value=' + result.defaultSelectsValue + '>' + result.defaultSelectsHtml + '</option>';
}
for (var i = 0; i < result.allSelects.length; i++) {
var item = result.allSelects[i];
if (item[keyValue.key] == result.chooseSelectsValue) {
result.needAddHtml += '<option value="' + item[keyValue.key] + '" selected>' + item[keyValue.value] + '</option>'
} else {
result.needAddHtml += '<option value="' + item[keyValue.key] + '">' + item[keyValue.value] + '</option>'
}
}
if (result.isId) {
$("#" + result.htmlId).html(result.needAddHtml)
} else {
$("." + result.htmlId).html(result.needAddHtml)
}
},
SectionToChinese: function (section) {//数字转换中文形式数子
var number = section;
var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
var chnUnitSection = ["", "万", "亿", "万亿", "亿亿"];
var chnUnitChar = ["", "十", "百", "千"];
var strIns = '', chnStr = '';
var unitPos = 0;
var zero = true;
while (section > 0) {
var v = section % 10;
if (v === 0) {
if (!zero) {
zero = true;
chnStr = chnNumChar[v] + chnStr;
}
} else {
zero = false;
strIns = chnNumChar[v];
strIns += chnUnitChar[unitPos];
chnStr = strIns + chnStr;
}
unitPos++;
section = Math.floor(section / 10);
}
if (number == 10) {
chnStr = "十"
} else if (number > 9 && number < 20) {
chnStr = chnStr.slice(1);
}
return chnStr;
},
//清除手机弹性
jubdeThemobile: function () {
var that = vm;
var deferred = Deferred();
var u = navigator.userAgent;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
} else if (u.indexOf('iPhone') > -1) {//苹果手机
//屏蔽ios下上下弹性
$(window).on('scroll.elasticity', function (e) {
e.preventDefault();
}).on('touchmove.elasticity', function (e) {
e.preventDefault();
});
} else if (u.indexOf('Windows Phone') > -1) {//winphone手机
}
deferred.resolve();
return deferred.promise;
},
screenOrientationEvent: function () {
var orientation = 0;
function screenOrientationEvent() {
if (orientation == 0) {
$("body").css({
'transform': 'rotate(90deg)',
'-webkit-transform': 'rotate(90deg)',
'-moz-transform': 'rotate(90deg)'
});
} else {
$("body").css({
'transform': 'rotate(0deg)',
'-webkit-transform': 'rotate(0deg)',
'-moz-transform': 'rotate(0deg)'
});
}
}
var innerWidthTmp = window.innerWidth;
screenOrientationEvent();
function screenOrientationListener() {
try {
var iw = window.innerWidth;//屏幕方向改变处理
if (iw != innerWidthTmp) {
if (iw > window.innerHeight) {
orientation = 90;
} else {
orientation = 0;
}//调用转屏事件
screenOrientationEvent();
innerWidthTmp = iw;
}
} catch (e) {
alert(e);
}
//间隔固定事件检查是否转屏,默认500毫秒
setTimeout("screenOrientationListener()", 500);
}
//启动横竖屏事件监听
screenOrientationListener();
},
//移动端网页强制横竖屏展示效果
screenOrientation: function (option) {
var _this = this;
_this.option = {
'mode': 'portrait',//portrait(竖屏)、landscape(横屏)
'id': option.id,//最外层容器ID
'init': false,
'callback': false
};
for (var k in option) if (option[k] != '') _this.option[k] = option[k];
var obj = document.getElementById(_this.option.id);
var className = obj.className || " ";
var w_width = obj.clientWidth;
var w_height = obj.clientHeight;
var flag = 0;
var timer;
if (_this.option.mode == "portrait")
var cssBlock =
'.' + _this.option.id + '_screenOrientation{-webkit-transform: rotateZ(-90deg) !important; transform: rotateZ(-90deg); position:relative;}';
else
var cssBlock =
'.' + _this.option.id + '_screenOrientation{-webkit-transform: rotateZ(90deg) !important; transform: rotateZ(90deg); position:relative;}';
var style = document.createElement("style");
style.type = "text/css";
style.textContent = cssBlock;
document.getElementsByTagName("head").item(0).appendChild(style);
var _width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
var _height = (window.innerHeight > 0) ? window.innerHeight : screen.height;
_this.modifyDetec = function () {
if ((_height < _width && _this.option.mode == "portrait") || (_height > _width && _this.option.mode == "landscape") && flag == 0) {
obj.style.width = _height + "px";
obj.style.height = _width + "px";
obj.style.top = -(_width - _height) * 0.5 + "px";
obj.style.left = -(_height - _width) * 0.5 + "px";
obj.className = className + " " + (_this.option.id + "_screenOrientation");
flag = 1;
if (_this.option.callback) {
_this.option.callback();
}
} else {
obj.style.width = w_width + "px";
obj.style.height = w_height + "px";
obj.className = className;
obj.style.top = " ";
obj.style.left = " ";
flag = 0;
}
}
function detectOtt() {
_width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
_height = (window.innerHeight > 0) ? window.innerHeight : screen.height;
if (window.orientation == 180 || window.orientation == 0 || window.orientation == 90 || window.orientation == -90) {
clearTimeout(timer);
timer = setTimeout(function () {
_this.modifyDetec(_width, _height);
}, 50);
}
;
}
if (_this.option.init) {
_this.option.init();
}
detectOtt();
window.addEventListener("resize", detectOtt, false);
},
setProvinces: function (address, newAddress) {
if (!newAddress) {
newAddress = []
}
// 3302
// 3502
for (var i = 0; i < address.length; i++) {
var provinceItem = address[i];
if (
provinceItem.id == '11'
|| provinceItem.id == '31'
|| provinceItem.id == '44'
|| provinceItem.id == '33'
|| provinceItem.id == '32'
|| provinceItem.id == '51'
|| provinceItem.id == '37'
|| provinceItem.id == '21'
|| provinceItem.id == '42'
|| provinceItem.id == '50'
|| provinceItem.id == '12'
|| provinceItem.id == '61'
|| provinceItem.id == '43'
|| provinceItem.id == '41'
|| provinceItem.id == '36'
|| provinceItem.id == '35'
) {
newAddress = newAddress.concat(provinceItem)
}
}
return newAddress;
},
setpY: function (productInfo, pY) {
avalon.log('setpY', productInfo)
var deferred = Deferred();
var payYears = productInfo.insurancePlanConfig.payYears;//由于接口的数据结构改变,所以2020-02-21修改,加多一层insurancePlanConfig
if (typeof payYears == 'string') {
payYears = payYears.split(',')
}
for (var i = 0; i < payYears.length; i++) {
var payYear = payYears[i];
for (var k in pY) {
var pYElement = pY[k];
if (pYElement.id == payYear) {
pYElement.visible = true;
}
}
}
deferred.resolve(pY);
return deferred.promise;
},
setTestFront: function (data2, pY, id) {
for (var i = 0; i < data2.result.length; i++) {
(function (i) {
var data2Element1 = data2.result[i];
var test_Front = '<table>' +
'<tr><td>交费期间</td>';
for (var k in pY) {
var pyItem = pY[k];
test_Front += (pyItem.visible ? '<td colspan="2">' + pyItem.value + '</td>' : '')
}
test_Front += '</tr>';
test_Front += '<tr><td>投保年龄</td>';
for (var k in pY) {
var pyItem = pY[k];
test_Front += (pyItem.visible ? '<td>男</td><td>女</td>' : '')
}
test_Front += '</tr>';
for (var j = 0; j < data2Element1.length; j++) {
var data2Element = data2Element1[j];
test_Front += '<tr>';
for (var k in data2Element) {
var data2ElementElement = data2Element[k];
if (k == 'v0') {
test_Front += '<td>' + data2ElementElement.value + '</td>';
} else {
test_Front += (data2ElementElement.visible ? '<td>' + data2ElementElement.value + '</td>' : '');
}
}
test_Front += '</tr>';
}
var test_behind = '</table>';
var div = test_Front + test_behind;
$('#' + id + i).html(div);
})(i)
}
},
getUploadImgUlr: function (cl) {//获取当前上传图片路径
var dom = $('.' + cl + ' input');
var src = getObjectURL(dom[dom.length - 1].files[0]);
if (src) {
return src
} else {
return false
}
// Array.from(dom).forEach(function (item) {
// var src = getObjectURL(item.files[0]);
// if (src) {
// return src
// } else {
// return ''
// }
// })
// 判断浏览器是否支持 createObjectURL api
function getObjectURL(file) {
var url = null;
if (window.createObjectURL != undefined) {
url = window.createObjectURL(file);
} else if (window.URL != undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
}
return url;
}
},
judgeBasicCoverage: function (resultItem) {
var that = this;