visitGroup_info.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * 初始化走访小组配置详情对话框
  3. */
  4. var VisitGroupInfoDlg = {
  5. visitGroupInfoData : {},
  6. validateFields: {
  7. year: {
  8. validators: {
  9. notEmpty: {
  10. message: '申报年度不能为空'
  11. }
  12. }
  13. },
  14. name:{
  15. validators: {
  16. notEmpty: {
  17. message: '审核小组不能为空'
  18. }
  19. }
  20. },
  21. }
  22. };
  23. /**
  24. * 清除数据
  25. */
  26. VisitGroupInfoDlg.clearData = function() {
  27. this.visitGroupInfoData = {};
  28. }
  29. /**
  30. * 设置对话框中的数据
  31. *
  32. * @param key 数据的名称
  33. * @param val 数据的具体值
  34. */
  35. VisitGroupInfoDlg.set = function(key, val) {
  36. this.visitGroupInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
  37. return this;
  38. }
  39. /**
  40. * 设置对话框中的数据
  41. *
  42. * @param key 数据的名称
  43. * @param val 数据的具体值
  44. */
  45. VisitGroupInfoDlg.get = function(key) {
  46. return $("#" + key).val();
  47. }
  48. /**
  49. * 关闭此对话框
  50. */
  51. VisitGroupInfoDlg.close = function() {
  52. parent.layer.close(window.parent.VisitGroup.layerIndex);
  53. }
  54. /**
  55. * 收集数据
  56. */
  57. VisitGroupInfoDlg.collectData = function() {
  58. this
  59. .set('id')
  60. .set('type')
  61. .set('year')
  62. .set('name');
  63. }
  64. /**
  65. * 提交添加
  66. */
  67. VisitGroupInfoDlg.addSubmit = function() {
  68. this.clearData();
  69. this.collectData();
  70. if(Feng.isEmptyStr(this.visitGroupInfoData.name)){
  71. Feng.info("核查小组不能为空");
  72. return;
  73. }
  74. var talentTypeArr = new Array();
  75. var talentTypes = "";
  76. var errorMsg = "";
  77. $(".child").each(function (index){
  78. var talentType = $(this).find("[name='talentType']").val();
  79. if(Feng.isEmptyStr(talentType)){
  80. errorMsg = "人才标签不能为空";
  81. return false;
  82. }
  83. if(talentTypeArr.indexOf(talentType)>=0){
  84. errorMsg = "存在重复的人才标签";
  85. return false;
  86. }
  87. var streets = $(this).find("[name='street']").val();
  88. if(Feng.isEmptyStr(streets)){
  89. errorMsg = "核查镇街不能为空";
  90. return false;
  91. }
  92. talentTypeArr.push(talentType);
  93. talentTypes = talentTypes + talentType +"-" + streets.join(",") + ";"
  94. });
  95. if(Feng.isNotEmptyStr(errorMsg)){
  96. Feng.info(errorMsg);
  97. return;
  98. }
  99. this.visitGroupInfoData['talentType'] = talentTypes.substring(0,talentTypes.length-1);;
  100. if(Feng.isEmptyStr(this.visitGroupInfoData.talentType)){
  101. Feng.error("标签镇街关系不能为空");return ;
  102. }
  103. //提交信息
  104. var ajax = new $ax(Feng.ctxPath + "/visitGroup/add", function(data){
  105. if(data.code=="200"){
  106. Feng.success(data.msg);
  107. window.parent.VisitGroup.table.refresh();
  108. VisitGroupInfoDlg.close();
  109. }else{
  110. Feng.error(data.msg);
  111. }
  112. },function(data){
  113. Feng.error("添加失败!" + data.responseJSON.message + "!");
  114. });
  115. ajax.set(this.visitGroupInfoData);
  116. ajax.start();
  117. }
  118. /**
  119. * 提交修改
  120. */
  121. VisitGroupInfoDlg.editSubmit = function() {
  122. this.clearData();
  123. this.collectData();
  124. if (!this.validate()) {
  125. return;
  126. }
  127. if(Feng.isEmptyStr(this.visitGroupInfoData.talentType)){
  128. Feng.error("核查人才标签不能为空");return ;
  129. }
  130. if(Feng.isEmptyStr(this.visitGroupInfoData.street)){
  131. Feng.error("核查镇街不能为空");return ;
  132. }
  133. //提交信息
  134. var ajax = new $ax(Feng.ctxPath + "/visitGroup/update", function(data){
  135. if(data.code=="200"){
  136. Feng.success(data.msg);
  137. window.parent.VisitGroup.table.refresh();
  138. VisitGroupInfoDlg.close();
  139. }else{
  140. Feng.error(data.msg);
  141. }
  142. },function(data){
  143. Feng.error("修改失败!" + data.responseJSON.message + "!");
  144. });
  145. ajax.set(this.visitGroupInfoData);
  146. ajax.start();
  147. }
  148. /**
  149. * 验证数据是否为空
  150. */
  151. VisitGroupInfoDlg.validate = function () {
  152. $('#visitGroupInfoForm').data("bootstrapValidator").resetForm();
  153. $('#visitGroupInfoForm').bootstrapValidator('validate');
  154. return $("#visitGroupInfoForm").data('bootstrapValidator').isValid();
  155. }
  156. VisitGroupInfoDlg.insertRow = function (){
  157. $("#childData").append("<div class=\"col-sm-12 child\">\n" +
  158. " <div class=\"rowGroup col-sm-5\">\n" +
  159. " <select class=\"form-control\" name=\"talentType\" data-placeholder=\"核查人才标签\" onchange=\"VisitGroupInfoDlg.talentTypeChange(this)\">\n" +
  160. $("#talentTypeData").html()+
  161. " </select>\n" +
  162. " </div>\n" +
  163. " <div class=\"rowGroup col-sm-5\">\n" +
  164. " <select class=\"chosen\" name=\"street\" placeholder=\"核查镇街\" multiple>\n" +
  165. " </select>\n" +
  166. " </div>\n" +
  167. " <div class=\"reduce\" onclick=\"$(this).parent().remove()\"></div>\n" +
  168. " </div>");
  169. $(".chosen").on('chosen:ready', function(e, params) {
  170. $(".chosen-container-single .chosen-single").css("padding","3px 0px 0px 2px");
  171. });
  172. $(".chosen").chosen({
  173. width:"100%",
  174. });
  175. }
  176. VisitGroupInfoDlg.talentTypeChange = function (content){
  177. var talentType = $(content).val();
  178. var year = $("#year").val();
  179. var next = $(content).parent().next().children().eq(0);
  180. next.empty();
  181. if(Feng.isEmptyStr(year)){
  182. Feng.info("请先选择申报年度");
  183. $(content).val("");
  184. return ;
  185. }
  186. //提交信息
  187. var ajax = new $ax(Feng.ctxPath + "/visitGroup/getStreetByTalentType", function(data){
  188. if(data == null || data.length == 0){
  189. Feng.info("当前年度该人才标签无未绑定的镇街");
  190. return;
  191. }
  192. var html = '<option value="">请选择</option>';
  193. for(var obj of data){
  194. html = html + '<option value="'+obj.code+'">'+obj.name+'</option>';
  195. }
  196. next.append(html);
  197. next.trigger('chosen:updated');
  198. },function(data){
  199. Feng.error("查询失败!" + data.responseJSON.message + "!");
  200. });
  201. ajax.set("year",year);
  202. ajax.set("type",$("#type").val());
  203. ajax.set("talentType",talentType);
  204. ajax.start();
  205. }
  206. $(function() {
  207. // Feng.initValidator("visitGroupInfoForm", VisitGroupInfoDlg.validateFields);
  208. $(".chosen").on('chosen:ready', function(e, params) {
  209. $(".chosen-container-single .chosen-single").css("padding","4px 0px 0px 4px");
  210. });
  211. $('.chosen').chosen({
  212. // search_contains:false,
  213. // enable_split_word_search: true
  214. width:"100%",
  215. });
  216. //下拉框数据回显
  217. if(Feng.isNotEmptyStr($("#id").val())){
  218. $("select").each(function () {
  219. $(this).val($(this).attr("value"));
  220. });
  221. $(".street").each(function (){
  222. $(this).val($(this).attr("value").split(",")).trigger('chosen:updated');
  223. })
  224. }
  225. // $("[name='street']").chosen({width: '100%',placeholder_text_multiple: '请选择核查镇街'});
  226. // $("#talentType").val($("#talentType").attr("value").split(",")).trigger("chosen:updated");
  227. // $("#street").val($("#street").attr("value").split(",")).trigger("chosen:updated");
  228. });