/**
* 用户相关js
*
* @author CaiAoLin
* @date 2017/6/13
* @version
*/
$(document).ready(function() {
$("#info-form").submit(function() {
if (!valid()) {
return false;
}
});
$("input").blur(function () {
cleanError();
});
//获取cld接口手机号码和数据
$('.getcategory').on('click', function () {
let category = $(this).attr('data-category');
let isupgrade = $(this).attr('data-upgrade');
if (isupgrade === 'true') {
$('#upgrade-title').text($(this).attr('data-title') + ' 售后服务');
} else {
$('#upgrade-title').text('联系销售代表激活');
}
$.ajax({
type: 'get',
url: '/cld/getCategoryStaff?category=' + category,
dataType: 'json',
timeout: 5000,
success: function (response) {
if (response.error !== 0) {
alert('获取CLD人员信息失败!');
} else {
let staffList = response.data;
let staffhtml = '';
$.each(staffList, function (key, staff) {
staffhtml += '
' +
'
' +
'
' +
'
' + staff.username + '
' +
'' + staff.category + '
' +
' ' +
'
' +
'- ' + staff.qq + '
' +
'- ' + staff.telephone + '
' +
'- ' + staff.phone + '
' +
'
';
});
$('#staffList').html(staffhtml);
$('#activ').modal('show');
}
},
error: function () {
console.log('请求超时');
}
})
})
});
/**
* 验证数据
*
* @return {boolean}
*/
function valid() {
let result = true;
let name = $("#name").val();
if (name === undefined || name === '') {
showError('您得填上姓名!', $("#name"));
return false;
}
let company = $("#company").val();
if (company === undefined || company === '') {
showError('您得填上公司名称!', $("#company"));
return false;
}
let province = $("#province").val();
if (province === undefined || province === '') {
showError('您得选择企业所在地区!', $("#province"));
return false;
}
return result;
}
/**
* 提示错误
*
* @param {string} msg
* @param {object} element
* @return {void}
*/
function showError(msg, element) {
element.addClass('orm-control-danger');
if (element !== null) {
element.parent().addClass('has-danger');
}
let html = '' + msg + '
';
if (element.siblings('.form-control-feedback').length > 0) {
element.siblings('.form-control-feedback').text(msg);
} else {
element.after(html);
}
}
/**
* 清除错误提示
*
* @return {void}
*/
function cleanError() {
$("input").removeClass('orm-control-danger');
$("input").parent().removeClass('has-danger');
$(".form-control-feedback").remove();
}