| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- /**
- * 修改增加联系人信息
- * */
- $(function() {
- // //获取所属行业//获取税务类别//获取客户信誉等级
- // $.when(helper.getDropList.getlistDropByDic($('#customer_subtrade'), 'KHSSHY'),
- // helper.getDropList.getlistDropByDic($('#customer_taxCategory'), 'SWLB'),
- // helper.getDropList.getlistDropByDic($('#customer_layer'), 'KHLayer'))
- // .done(function() {
- var edit_id = helper.request.queryString("edit_id");
- if (edit_id) {
- getCustomer(edit_id);
- }
- //绑定验证(所有 input.form-control)
- $('#tab_user_contents').find("input[class='form-control']").on('blur keyup', valideInput);
- // });
- });
- //获取客户详情
- function getCustomer(ids) {
- $.getJSON(huayi.config.callcenter_url + "CustomerNew/GetCustomer", {
- cusid: ids, //客户id
- token: $.cookie("token")
- }, function(data) {
- if (data.state.toLowerCase() == "success") {
- var contactList = data.data.ContactList;
- var mid = helper.request.queryString("mid");
- var contactInfo = {};
- if(contactList && contactList.length > 0){
- for(var i = 0; i < contactList.length; i++) {
- if(contactList[i].F_ManId == mid){
- contactInfo = contactList[i];
- break;
- }
- }
- }
- if (contactInfo) {
- $('#F_Name').val(contactInfo.F_Name);// string 联系人姓名
- $('#F_Telephone').val(contactInfo.F_Telephone);// string 电话
- $('#F_Email').val(contactInfo.F_Email);// string 邮箱
- $('#F_Duties').val(contactInfo.F_Duties);// string 职务
- $('#F_QQ').val(contactInfo.F_QQ);// string QQ
- $('#F_MSN').val(contactInfo.F_MSN);// string MSN
- $('#F_Remark').val(contactInfo.F_Remark);// string 备注
- $('#customer_isMain').find('input[type="radio"][value="'+ contactInfo.F_IsMain +'"]').prop('checked', true);
- $('#F_Name').trigger('blur');
- }
- }
- });
- }
- //保存
- function saveCustomer() {
- if (!$.trim($('#F_Name').val()) ||
- !$.trim($('#F_Telephone').val())) {
- layer.msg('带红色星号的是必填项,请填写或选择后再保存!');
- return;
- }
- var wURL, loadIndex;
- var edit_id = helper.request.queryString("edit_id");
- var mid = helper.request.queryString("mid");
- if (mid) {
- wURL = "CustomerNew/UpdateContact";
- } else {
- wURL = "CustomerNew/AddContact";
- }
- $.ajax({
- type: 'post',
- url: huayi.config.callcenter_url + wURL,
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('#save_btns').attr("disabled", true);
- $('#save_btns').text('保存中...');
- loadIndex = layer.load();
- },
- data: {
- F_CustomerId: edit_id,//int客户id,允许为0
- F_ManId: mid,//int 联系人id
- F_Name: $('#F_Name').val(),// string 联系人姓名
- F_Telephone: $('#F_Telephone').val(),// string 电话
- F_Email: $('#F_Email').val(),// string 邮箱
- F_Duties: $('#F_Duties').val(),// string 职务
- F_QQ: $('#F_QQ').val(),// string QQ
- F_MSN: $('#F_MSN').val(),// string MSN
- F_Remark: $('#F_Remark').val(),// string 备注
- F_IsMain: $('#customer_isMain').find('input[type="radio"]:checked').val(),//bool 是否主要联系人
- token: $.cookie("token")
- },
- success: function(data) {
- layer.close(loadIndex);
- if (data.state === "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- if(mid){
- parent.getCustomer(edit_id); //客户信息详情页面
- }else{
- parent.$('#cusList').bootstrapTable('refresh');
- }
- parent.layer.msg("保存成功");
- } else {
- $('#save_btns').attr("disabled", false);
- $('#save_btns').text('保存');
- }
- },
- error: function(textStatus) {
- layer.close(loadIndex);
- layer.confirm('网络繁忙,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- $('#save_btns').attr("disabled", false);
- $('#save_btns').text('保存');
- },
- complete: function(XMLHttpRequest, textStatus) {
- layer.close(loadIndex);
- if (textStatus == 'timeout') {
- var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
- xmlhttp.abort();
- layer.confirm('网络超时,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- }
- $('#save_btns').attr("disabled", false);
- $('#save_btns').text('保存');
- },
- });
- }
- //验证(所有 input.form-control)的方法
- function valideInput() {
- var _that = $(this);
- //console.log($(this).attr('id'));
- switch ($(this).attr('id')) {
- case 'F_Name': //验证姓名
- valideMethods(_that, regexs.userNameReg, '格式不正确(只能输入2-20位汉字可以包含·•)!', false);
- break;
- case 'F_Telephone': //验证电话
- valideMethods(_that, regexs.phone, '您输入的电话号码格式不正确!', false);
- break;
- case 'F_Email': //验证 邮箱
- valideMethods(_that, regexs.email, '请输入正确格式的邮箱!', true);
- break;
- case 'F_Duties': //验证 职务
- valideMethods(_that, regexs.chOrenOrnum, '格式不正确(只能输入中文、英文、数字)!', true);
- break;
- case 'F_QQ': //QQ
- valideMethods(_that, regexs.QQreg, '请输入正确格式的QQ号!', true);
- break;
- case 'F_MSN': //MSN
- valideMethods(_that, regexs.chOrenOrnum, '格式不正确(只能输入中文、英文、数字)!', true);
- break;
- }
- if ($('#tab_user_contents').find('.has-error').length > 0) {
- $('.project_save').attr('disabled', true);
- $('#save_btns').off('click', saveCustomer);
- } else {
- $('.project_save').attr('disabled', false);
- $('#save_btns').off('click', saveCustomer);
- $('#save_btns').on('click', saveCustomer);
- }
- }
- /**
- * 验证方法
- * _this :传递的this
- * regRlues: 验证的规则
- * msg: 提示信息
- * isRes:boolean 是否允许验证的内容为空,true:允许为空,false:不允许为空
- * */
- function valideMethods(_this, regRlues, msg, isRes) {
- var txtTpips = _this.parent().parent().find('.text-tips');
- if (txtTpips) {
- txtTpips.parent().remove();
- }
- if (!isRes) {
- //不为空
- if (!regRlues.test($.trim(_this.val()))) {
- _this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
- _this.parent().find('.glyphicon').remove();
- $('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
- $('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
- .parent());
- $('.project_save').attr('disabled', true);
- } else {
- _this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
- _this.parent().find('.glyphicon').remove();
- $('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
- }
- } else {
- //为空不验证;但是有内容就验证;
- if ($.trim(_this.val())) {
- if (!regRlues.test($.trim(_this.val()))) {
- _this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
- _this.parent().find('.glyphicon').remove();
- $('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
- $('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
- .parent());
- $('.project_save').attr('disabled', true);
- } else {
- _this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
- _this.parent().find('.glyphicon').remove();
- $('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
- }
- } else {
- _this.parent().find('.glyphicon').remove();
- _this.parent().parent().removeClass('has-error has-success has-feedback');
- }
- }
- }
|