Няма описание

addOrEditContacts.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /**
  2. * 修改增加联系人信息
  3. * */
  4. $(function() {
  5. // //获取所属行业//获取税务类别//获取客户信誉等级
  6. // $.when(helper.getDropList.getlistDropByDic($('#customer_subtrade'), 'KHSSHY'),
  7. // helper.getDropList.getlistDropByDic($('#customer_taxCategory'), 'SWLB'),
  8. // helper.getDropList.getlistDropByDic($('#customer_layer'), 'KHLayer'))
  9. // .done(function() {
  10. var edit_id = helper.request.queryString("edit_id");
  11. if (edit_id) {
  12. getCustomer(edit_id);
  13. }
  14. //绑定验证(所有 input.form-control)
  15. $('#tab_user_contents').find("input[class='form-control']").on('blur keyup', valideInput);
  16. // });
  17. });
  18. //获取客户详情
  19. function getCustomer(ids) {
  20. $.getJSON(huayi.config.callcenter_url + "CustomerNew/GetCustomer", {
  21. cusid: ids, //客户id
  22. token: $.cookie("token")
  23. }, function(data) {
  24. if (data.state.toLowerCase() == "success") {
  25. var contactList = data.data.ContactList;
  26. var mid = helper.request.queryString("mid");
  27. var contactInfo = {};
  28. if(contactList && contactList.length > 0){
  29. for(var i = 0; i < contactList.length; i++) {
  30. if(contactList[i].F_ManId == mid){
  31. contactInfo = contactList[i];
  32. break;
  33. }
  34. }
  35. }
  36. if (contactInfo) {
  37. $('#F_Name').val(contactInfo.F_Name);// string 联系人姓名
  38. $('#F_Telephone').val(contactInfo.F_Telephone);// string 电话
  39. $('#F_Email').val(contactInfo.F_Email);// string 邮箱
  40. $('#F_Duties').val(contactInfo.F_Duties);// string 职务
  41. $('#F_QQ').val(contactInfo.F_QQ);// string QQ
  42. $('#F_MSN').val(contactInfo.F_MSN);// string MSN
  43. $('#F_Remark').val(contactInfo.F_Remark);// string 备注
  44. $('#customer_isMain').find('input[type="radio"][value="'+ contactInfo.F_IsMain +'"]').prop('checked', true);
  45. $('#F_Name').trigger('blur');
  46. }
  47. }
  48. });
  49. }
  50. //保存
  51. function saveCustomer() {
  52. if (!$.trim($('#F_Name').val()) ||
  53. !$.trim($('#F_Telephone').val())) {
  54. layer.msg('带红色星号的是必填项,请填写或选择后再保存!');
  55. return;
  56. }
  57. var wURL, loadIndex;
  58. var edit_id = helper.request.queryString("edit_id");
  59. var mid = helper.request.queryString("mid");
  60. if (mid) {
  61. wURL = "CustomerNew/UpdateContact";
  62. } else {
  63. wURL = "CustomerNew/AddContact";
  64. }
  65. $.ajax({
  66. type: 'post',
  67. url: huayi.config.callcenter_url + wURL,
  68. dataType: 'json',
  69. async: true,
  70. beforeSend: function() { //触发ajax请求开始时执行
  71. $('#save_btns').attr("disabled", true);
  72. $('#save_btns').text('保存中...');
  73. loadIndex = layer.load();
  74. },
  75. data: {
  76. F_CustomerId: edit_id,//int客户id,允许为0
  77. F_ManId: mid,//int 联系人id
  78. F_Name: $('#F_Name').val(),// string 联系人姓名
  79. F_Telephone: $('#F_Telephone').val(),// string 电话
  80. F_Email: $('#F_Email').val(),// string 邮箱
  81. F_Duties: $('#F_Duties').val(),// string 职务
  82. F_QQ: $('#F_QQ').val(),// string QQ
  83. F_MSN: $('#F_MSN').val(),// string MSN
  84. F_Remark: $('#F_Remark').val(),// string 备注
  85. F_IsMain: $('#customer_isMain').find('input[type="radio"]:checked').val(),//bool 是否主要联系人
  86. token: $.cookie("token")
  87. },
  88. success: function(data) {
  89. layer.close(loadIndex);
  90. if (data.state === "success") {
  91. var index = parent.layer.getFrameIndex(window.name);
  92. parent.layer.close(index);
  93. if(mid){
  94. parent.getCustomer(edit_id); //客户信息详情页面
  95. }else{
  96. parent.$('#cusList').bootstrapTable('refresh');
  97. }
  98. parent.layer.msg("保存成功");
  99. } else {
  100. $('#save_btns').attr("disabled", false);
  101. $('#save_btns').text('保存');
  102. }
  103. },
  104. error: function(textStatus) {
  105. layer.close(loadIndex);
  106. layer.confirm('网络繁忙,请稍后再试...', {
  107. icon: 7,
  108. closeBtn: 0,
  109. btn: ['确定'] //按钮
  110. });
  111. $('#save_btns').attr("disabled", false);
  112. $('#save_btns').text('保存');
  113. },
  114. complete: function(XMLHttpRequest, textStatus) {
  115. layer.close(loadIndex);
  116. if (textStatus == 'timeout') {
  117. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  118. xmlhttp.abort();
  119. layer.confirm('网络超时,请稍后再试...', {
  120. icon: 7,
  121. closeBtn: 0,
  122. btn: ['确定'] //按钮
  123. });
  124. }
  125. $('#save_btns').attr("disabled", false);
  126. $('#save_btns').text('保存');
  127. },
  128. });
  129. }
  130. //验证(所有 input.form-control)的方法
  131. function valideInput() {
  132. var _that = $(this);
  133. //console.log($(this).attr('id'));
  134. switch ($(this).attr('id')) {
  135. case 'F_Name': //验证姓名
  136. valideMethods(_that, regexs.userNameReg, '格式不正确(只能输入2-20位汉字可以包含·•)!', false);
  137. break;
  138. case 'F_Telephone': //验证电话
  139. valideMethods(_that, regexs.phone, '您输入的电话号码格式不正确!', false);
  140. break;
  141. case 'F_Email': //验证 邮箱
  142. valideMethods(_that, regexs.email, '请输入正确格式的邮箱!', true);
  143. break;
  144. case 'F_Duties': //验证 职务
  145. valideMethods(_that, regexs.chOrenOrnum, '格式不正确(只能输入中文、英文、数字)!', true);
  146. break;
  147. case 'F_QQ': //QQ
  148. valideMethods(_that, regexs.QQreg, '请输入正确格式的QQ号!', true);
  149. break;
  150. case 'F_MSN': //MSN
  151. valideMethods(_that, regexs.chOrenOrnum, '格式不正确(只能输入中文、英文、数字)!', true);
  152. break;
  153. }
  154. if ($('#tab_user_contents').find('.has-error').length > 0) {
  155. $('.project_save').attr('disabled', true);
  156. $('#save_btns').off('click', saveCustomer);
  157. } else {
  158. $('.project_save').attr('disabled', false);
  159. $('#save_btns').off('click', saveCustomer);
  160. $('#save_btns').on('click', saveCustomer);
  161. }
  162. }
  163. /**
  164. * 验证方法
  165. * _this :传递的this
  166. * regRlues: 验证的规则
  167. * msg: 提示信息
  168. * isRes:boolean 是否允许验证的内容为空,true:允许为空,false:不允许为空
  169. * */
  170. function valideMethods(_this, regRlues, msg, isRes) {
  171. var txtTpips = _this.parent().parent().find('.text-tips');
  172. if (txtTpips) {
  173. txtTpips.parent().remove();
  174. }
  175. if (!isRes) {
  176. //不为空
  177. if (!regRlues.test($.trim(_this.val()))) {
  178. _this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
  179. _this.parent().find('.glyphicon').remove();
  180. $('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  181. $('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
  182. .parent());
  183. $('.project_save').attr('disabled', true);
  184. } else {
  185. _this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
  186. _this.parent().find('.glyphicon').remove();
  187. $('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  188. }
  189. } else {
  190. //为空不验证;但是有内容就验证;
  191. if ($.trim(_this.val())) {
  192. if (!regRlues.test($.trim(_this.val()))) {
  193. _this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
  194. _this.parent().find('.glyphicon').remove();
  195. $('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  196. $('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
  197. .parent());
  198. $('.project_save').attr('disabled', true);
  199. } else {
  200. _this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
  201. _this.parent().find('.glyphicon').remove();
  202. $('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  203. }
  204. } else {
  205. _this.parent().find('.glyphicon').remove();
  206. _this.parent().parent().removeClass('has-error has-success has-feedback');
  207. }
  208. }
  209. }