ZZDianXin_UI - 郑州电信 演示

addOrEditCustomer.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * 增加或编辑客户档案
  3. * */
  4. $(document).ready(function() {
  5. var cid = helper.request.queryString("cid");
  6. //获取乡镇或单位下拉
  7. helper.getDropList.getlistDropByDic($('#t_county'), 'JBDW').then(function() {
  8. if(cid) {
  9. getCustomer(cid); //获取信息
  10. }
  11. });
  12. //保存
  13. $('#btn_save').on('click', saveCustomer);
  14. });
  15. //添加或编辑保存
  16. function saveCustomer() {
  17. var telreg = /^\d{0,12}$/;
  18. var cid = helper.request.queryString("cid");
  19. if(!$.trim($('#t_name').val())) {
  20. layer.confirm('请输入客户姓名!', {
  21. icon: 2,
  22. btn: ['确定']
  23. });
  24. return;
  25. }
  26. if($.trim($('#t_mobile').val())){
  27. if(!telreg.test($.trim($('#t_mobile').val()))) {
  28. layer.confirm('请输入正确的手机号!', {
  29. icon: 2,
  30. btn: ['确定']
  31. });
  32. return;
  33. }
  34. }
  35. if($.trim($('#t_tel').val())){
  36. if(!telreg.test($.trim($('#t_tel').val()))) {
  37. layer.confirm('请输入正确的号码!', {
  38. icon: 2,
  39. btn: ['确定']
  40. });
  41. return;
  42. }
  43. }
  44. $.post(huayi.config.callcenter_url + "Customer/AddCustomer", {
  45. id: cid, //int 否 修改时不需要,默认为0
  46. cusname: $('#t_name').val(), // string 是 姓名
  47. mobile: $('#t_mobile').val(),// string 否 手机号
  48. telphone: $('#t_tel').val(),// string 否 电话
  49. address: $('#t_address').val(),// string 否 住址
  50. countryid: $('#t_county').val(),// int 否 乡镇或单位id 默认为0
  51. token: $.cookie("token")
  52. }, function(result) {
  53. result = $.parseJSON(result);
  54. if(result.state.toLowerCase() == "success") {
  55. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  56. parent.layer.close(index); //再执行关闭
  57. parent.initTable();
  58. parent.layer.msg("保存成功");
  59. }
  60. });
  61. }
  62. //获取信息
  63. function getCustomer(cid) {
  64. $.getJSON(huayi.config.callcenter_url + 'Customer/GetCustomer', {
  65. cid: cid,
  66. token: $.cookie("token")
  67. }, function(result) {
  68. if(result.state.toLowerCase() == "success") {
  69. var res = result.data;
  70. if(res) {
  71. $('#t_name').val(res.cusname); //姓名
  72. $("#t_mobile").val(res.mobile); //手机号
  73. $("#t_tel").val(res.telphone); //电话
  74. $("#t_address").val(res.address); //地址
  75. $('#t_county').val(res.countryid);// int 否 乡镇或单位id 默认为0
  76. }
  77. }
  78. })
  79. }