开封利通水务前端

addOrEditBusiness.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * 修改增加业务信息
  3. * */
  4. //编辑器配置
  5. KindEditor.ready(function(K) {
  6. window.editor = K.create('#F_BusContent', {
  7. imgMaxSize: 10 * 1024 * 1024,
  8. minHeight: '300px',
  9. uploadJson: '../../js/kindeditor/asp.net/upload_json.ashx',
  10. fileManagerJson: '../../js/kindeditor/asp.net/file_manager_json.ashx',
  11. allowFileManager: true,
  12. afterCreate: function() {
  13. this.loadPlugin('autoheight');
  14. },
  15. items: [
  16. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  17. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  18. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  19. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  20. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  21. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
  22. 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  23. 'anchor', 'link', 'unlink', '|', 'about'
  24. ]
  25. });
  26. });
  27. $(function() {
  28. autosize($('textarea'));
  29. // //获取所属行业//获取税务类别//获取客户信誉等级
  30. // $.when(helper.getDropList.getlistDropByDic($('#customer_subtrade'), 'KHSSHY'),
  31. // helper.getDropList.getlistDropByDic($('#customer_taxCategory'), 'SWLB'),
  32. // helper.getDropList.getlistDropByDic($('#customer_layer'), 'KHLayer'))
  33. // .done(function() {
  34. var edit_id = helper.request.queryString("edit_id");
  35. if (edit_id) {
  36. getCustomer(edit_id);
  37. }
  38. //绑定验证(所有 input.form-control)
  39. $('#tab_user_contents').find("input[class='form-control']").on('blur keyup', valideInput);
  40. // });
  41. });
  42. //获取详情
  43. function getCustomer(ids) {
  44. $.getJSON(huayi.config.callcenter_url + "WoBill/GetBus", {
  45. id: ids, //id
  46. token: $.cookie("token")
  47. }, function(data) {
  48. if (data.state.toLowerCase() == "success") {
  49. data = data.data;
  50. if (data) {
  51. $('#F_BusName').val(data.F_BusName);// string 业务名称
  52. editor.html(decodeURIComponent(data.F_BusContent));// string 业务内容
  53. // $('#F_BusContent').val(data.F_BusContent);// string 业务内容
  54. $('#F_BusLabel').val(data.F_BusLabel);// string 业务标签
  55. $('#F_Remark').val(data.F_Remark);// string 备注
  56. $('#F_BusName').trigger('blur');
  57. }
  58. }
  59. });
  60. }
  61. //保存
  62. function saveCustomer() {
  63. // if (!$.trim($('#F_Name').val()) ||
  64. // !$.trim($('#F_Telephone').val())) {
  65. // layer.msg('带红色星号的是必填项,请填写或选择后再保存!');
  66. // return;
  67. // }
  68. var wURL, loadIndex;
  69. var edit_id = helper.request.queryString("edit_id");
  70. if (edit_id) {
  71. wURL = "WoBill/UpdateBus";
  72. } else {
  73. wURL = "WoBill/AddBus";
  74. }
  75. $.ajax({
  76. type: 'post',
  77. url: huayi.config.callcenter_url + wURL,
  78. dataType: 'json',
  79. async: true,
  80. beforeSend: function() { //触发ajax请求开始时执行
  81. $('#save_btns').attr("disabled", true);
  82. $('#save_btns').text('保存中...');
  83. loadIndex = layer.load();
  84. },
  85. data: {
  86. F_Id: edit_id,//主ID
  87. F_BusName: $('#F_BusName').val(),// string 业务名称
  88. F_BusLabel: $('#F_BusLabel').val(),// string 业务标签
  89. // F_BusContent: helper.filter.delHtmlTag($('#F_BusContent').val()),// string 业务内容
  90. F_BusContent: encodeURIComponent(editor.html()),// string 业务内容
  91. F_Remark: helper.filter.delHtmlTag($('#F_Remark').val()),// string 备注
  92. token: $.cookie("token")
  93. },
  94. success: function(data) {
  95. layer.close(loadIndex);
  96. if (data.state === "success") {
  97. var index = parent.layer.getFrameIndex(window.name);
  98. parent.layer.close(index);
  99. parent.$('#workorderlist').bootstrapTable('refresh');
  100. parent.layer.msg("保存成功");
  101. } else {
  102. $('#save_btns').attr("disabled", false);
  103. $('#save_btns').text('保存');
  104. }
  105. },
  106. error: function(textStatus) {
  107. layer.close(loadIndex);
  108. layer.confirm('网络繁忙,请稍后再试...', {
  109. icon: 7,
  110. closeBtn: 0,
  111. btn: ['确定'] //按钮
  112. });
  113. $('#save_btns').attr("disabled", false);
  114. $('#save_btns').text('保存');
  115. },
  116. complete: function(XMLHttpRequest, textStatus) {
  117. layer.close(loadIndex);
  118. if (textStatus == 'timeout') {
  119. var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
  120. xmlhttp.abort();
  121. layer.confirm('网络超时,请稍后再试...', {
  122. icon: 7,
  123. closeBtn: 0,
  124. btn: ['确定'] //按钮
  125. });
  126. }
  127. $('#save_btns').attr("disabled", false);
  128. $('#save_btns').text('保存');
  129. },
  130. });
  131. }
  132. //验证(所有 input.form-control)的方法
  133. function valideInput() {
  134. var _that = $(this);
  135. //console.log($(this).attr('id'));
  136. switch ($(this).attr('id')) {
  137. case 'F_BusName': //业务名称
  138. valideMethods(_that, regexs.businessname, '格式不正确(只能输入中文、英文、数字、括号和顿号 )!', true);
  139. break;
  140. case 'F_BusLabel': //业务标签
  141. valideMethods(_that, regexs.chOrenOrnum, '格式不正确(只能输入中文、英文、数字)!', true);
  142. break;
  143. }
  144. if ($('#tab_user_contents').find('.has-error').length > 0) {
  145. $('.project_save').attr('disabled', true);
  146. $('#save_btns').off('click', saveCustomer);
  147. } else {
  148. $('.project_save').attr('disabled', false);
  149. $('#save_btns').off('click', saveCustomer);
  150. $('#save_btns').on('click', saveCustomer);
  151. }
  152. }
  153. /**
  154. * 验证方法
  155. * _this :传递的this
  156. * regRlues: 验证的规则
  157. * msg: 提示信息
  158. * isRes:boolean 是否允许验证的内容为空,true:允许为空,false:不允许为空
  159. * */
  160. function valideMethods(_this, regRlues, msg, isRes) {
  161. var txtTpips = _this.parent().parent().find('.text-tips');
  162. if (txtTpips) {
  163. txtTpips.parent().remove();
  164. }
  165. if (!isRes) {
  166. //不为空
  167. if (!regRlues.test($.trim(_this.val()))) {
  168. _this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
  169. _this.parent().find('.glyphicon').remove();
  170. $('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  171. $('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
  172. .parent());
  173. $('.project_save').attr('disabled', true);
  174. } else {
  175. _this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
  176. _this.parent().find('.glyphicon').remove();
  177. $('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  178. }
  179. } else {
  180. //为空不验证;但是有内容就验证;
  181. if ($.trim(_this.val())) {
  182. if (!regRlues.test($.trim(_this.val()))) {
  183. _this.parent().parent().removeClass('has-success has-feedback').addClass('has-error has-feedback');
  184. _this.parent().find('.glyphicon').remove();
  185. $('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  186. $('<div class="col-md-10 col-md-offset-2"><span class="text-tips">' + msg + '</span></div>').appendTo(_this.parent()
  187. .parent());
  188. $('.project_save').attr('disabled', true);
  189. } else {
  190. _this.parent().parent().removeClass('has-error has-feedback').addClass('has-success has-feedback');
  191. _this.parent().find('.glyphicon').remove();
  192. $('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>').appendTo(_this.parent());
  193. }
  194. } else {
  195. _this.parent().find('.glyphicon').remove();
  196. _this.parent().parent().removeClass('has-error has-success has-feedback');
  197. }
  198. }
  199. }