identifyCondition_info.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. * 初始化认定条件管理详情对话框
  3. */
  4. var IdentifyConditionInfoDlg = {
  5. identifyConditionInfoData: {},
  6. validateFields: {
  7. talentLevel: {
  8. validators: {
  9. notEmpty: {
  10. message: '人才层次不能为空'
  11. }
  12. }
  13. },
  14. type: {
  15. validators: {
  16. notEmpty: {
  17. message: '人才类别不能为空'
  18. }
  19. }
  20. },
  21. name: {
  22. validators: {
  23. notEmpty: {
  24. message: '名称不能为空'
  25. }
  26. }
  27. },
  28. active: {
  29. validators: {
  30. notEmpty: {
  31. message: '启用状态不能为空'
  32. }
  33. }
  34. }
  35. }
  36. };
  37. /**
  38. * 清除数据
  39. */
  40. IdentifyConditionInfoDlg.clearData = function () {
  41. this.identifyConditionInfoData = {};
  42. }
  43. /**
  44. * 设置对话框中的数据
  45. *
  46. * @param key 数据的名称
  47. * @param val 数据的具体值
  48. */
  49. IdentifyConditionInfoDlg.set = function (key, val) {
  50. this.identifyConditionInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
  51. return this;
  52. }
  53. /**
  54. * 设置对话框中的数据
  55. *
  56. * @param key 数据的名称
  57. * @param val 数据的具体值
  58. */
  59. IdentifyConditionInfoDlg.get = function (key) {
  60. return $("#" + key).val();
  61. }
  62. /**
  63. * 关闭此对话框
  64. */
  65. IdentifyConditionInfoDlg.close = function () {
  66. parent.layer.close(window.parent.IdentifyCondition.layerIndex);
  67. }
  68. /**
  69. * 收集数据
  70. */
  71. IdentifyConditionInfoDlg.collectData = function () {
  72. this
  73. .set('id')
  74. .set('type')
  75. .set('talentLevel')
  76. .set('name')
  77. .set('active')
  78. .set('description');
  79. var companys = $("#companyIds").val();
  80. var bindFileTypes = $("#bindFileTypes").val();
  81. var company_ids = "", bind_fts_ids = "";
  82. for (var key in companys) {
  83. if (Feng.isNotEmptyStr(companys[key])) {
  84. company_ids = company_ids + companys[key] + ",";
  85. }
  86. }
  87. if (Feng.isNotEmptyStr(company_ids)) {
  88. company_ids = company_ids.substring(0, company_ids.length - 1);
  89. }
  90. for (var key in bindFileTypes) {
  91. if (Feng.isNotEmptyStr(bindFileTypes[key])) {
  92. bind_fts_ids = bind_fts_ids + bindFileTypes[key] + ",";
  93. }
  94. }
  95. if (Feng.isNotEmptyStr(bind_fts_ids)) {
  96. bind_fts_ids = bind_fts_ids.substring(0, bind_fts_ids.length - 1);
  97. }
  98. this.identifyConditionInfoData['companyIds'] = company_ids;
  99. this.identifyConditionInfoData['bindFileTypes'] = bind_fts_ids;
  100. var chks = $("#relationTable input[type=checkbox]:checked");
  101. var relation = {};
  102. for (var i = 0; i < chks.length; i++) {
  103. var companyId = $(chks[i]).data("company-id");
  104. if (typeof relation[companyId] == "undefined") {
  105. relation[companyId] = $(chks[i]).val();
  106. } else {
  107. relation[companyId] += "," + $(chks[i]).val();
  108. }
  109. }
  110. this.identifyConditionInfoData['relation'] = relation;
  111. }
  112. IdentifyConditionInfoDlg.otherValid = function () {
  113. if (this.identifyConditionInfoData.companyIds != '' && this.identifyConditionInfoData.bindFileTypes != '') {
  114. var fileTypes = this.identifyConditionInfoData.bindFileTypes.split(",");
  115. var total = fileTypes.length;
  116. var _goal = 0;
  117. for (var i = 0; i < total; i++) {
  118. var typeId = fileTypes[i];
  119. _goal += $("input[type=checkbox][value='" + typeId + "']:checked").length > 0 ? 1 : 0;
  120. }
  121. if (_goal != total) {
  122. Feng.error("选择了审核单位及审核附件后,每个附件必须与其中一个审核单位关联");
  123. return false;
  124. }
  125. }
  126. return true;
  127. }
  128. /**
  129. * 提交添加
  130. */
  131. IdentifyConditionInfoDlg.addSubmit = function () {
  132. this.clearData();
  133. this.collectData();
  134. if (!this.validate() || !IdentifyConditionInfoDlg.otherValid()) {
  135. return;
  136. }
  137. var ajax = new $ax("/admin/talent_condition/add", function (data) {
  138. if (data.code == "200") {
  139. Feng.success(data.msg);
  140. window.parent.IdentifyCondition.table.refresh();
  141. IdentifyConditionInfoDlg.close();
  142. } else {
  143. Feng.error(data.msg);
  144. }
  145. }, function (data) {
  146. Feng.error("添加失败!" + data.responseJSON.message + "!");
  147. });
  148. ajax.set(this.identifyConditionInfoData);
  149. ajax.start();
  150. }
  151. /**
  152. * 提交修改
  153. */
  154. IdentifyConditionInfoDlg.editSubmit = function () {
  155. this.clearData();
  156. this.collectData();
  157. if (!this.validate() || !IdentifyConditionInfoDlg.otherValid()) {
  158. return;
  159. }
  160. var ajax = new $ax(Feng.ctxPath + "/admin/talent_condition/edit", function (data) {
  161. if (data.code == "200") {
  162. Feng.success(data.msg);
  163. window.parent.IdentifyCondition.table.refresh();
  164. IdentifyConditionInfoDlg.close();
  165. } else {
  166. Feng.error(data.msg);
  167. }
  168. }, function (data) {
  169. Feng.error("修改失败!" + data.responseJSON.message + "!");
  170. });
  171. ajax.set(this.identifyConditionInfoData);
  172. ajax.start();
  173. }
  174. IdentifyConditionInfoDlg.onTypeChange = function () {
  175. var type = $("#type").val();
  176. Feng.addAjaxSelect({
  177. "id": "bindFileTypes",
  178. "displayCode": "id",
  179. "displayName": "name",
  180. "type": "GET",
  181. "url": Feng.ctxPath + "/common/api/getConditionFileTypesByType/type/" + type
  182. });
  183. $("#bindFileTypes").trigger("chosen:updated");
  184. }
  185. IdentifyConditionInfoDlg.onCompanyOrTypeChange = function () {
  186. var companyIds = $("#companyIds").val();
  187. var bindFileTypes = $("#bindFileTypes").val();
  188. IdentifyConditionInfoDlg.buildRelationTable(companyIds, bindFileTypes);
  189. }
  190. IdentifyConditionInfoDlg.fstLoad = true;
  191. IdentifyConditionInfoDlg.buildRelationTable = function (companyIds, bindFileTypes) {
  192. var companyWithFileType = $("#companyWithFileType").val();
  193. var setting = [];
  194. if (companyWithFileType) {
  195. var companyTmps = companyWithFileType.split(";")
  196. for (var i in companyTmps) {
  197. var _companyTmp = companyTmps[i].split(":");
  198. var _companyId = _companyTmp[0];
  199. var _fileTypes = _companyTmp[1].split(",");
  200. setting[_companyId] = _fileTypes;
  201. }
  202. }
  203. var trs = $("#relationTable tbody").find("tr");
  204. trs.each(function (index, tr) {
  205. if (!companyIds || companyIds.indexOf($(tr).data("id").toString()) == -1)
  206. $(tr).remove();
  207. })
  208. for (let i in companyIds) {
  209. let companyId = companyIds[i];
  210. if (companyId == "")
  211. continue;
  212. var cfg = setting[companyId];
  213. if ($("#relationTable tbody").find("tr[data-id='" + companyId + "']").length > 0) {
  214. var chks = $("#relationTable tbody").find("tr[data-id='" + companyId + "']").find("input[type=checkbox]");
  215. chks.each(function (index, chk) {
  216. if (!bindFileTypes || bindFileTypes.indexOf($(chk).val().toString()) == -1)
  217. $(chk).parents("li").remove();
  218. })
  219. for (let n in bindFileTypes) {
  220. let fileType = bindFileTypes[n];
  221. if ($("#relationTable tbody").find("tr[data-id='" + companyId + "']").find("input[value='" + fileType + "']").length == 0) {
  222. let typename = $("#bindFileTypes option[value='" + fileType + "']").text();
  223. let disabled = $("input[type=checkbox][value='" + fileType + "']:checked").length > 0 ? "disabled" : "";
  224. let li = '<li><label for="relation[' + companyId + ']">' + typename + '</label><input type="checkbox" data-company-id="' + companyId + '" value="' + fileType + '" ' + disabled + ' onchange="IdentifyConditionInfoDlg.onCheckChange(this);"></li>';
  225. $("#relationTable tbody").find("tr[data-id='" + companyId + "'] ul").append(li);
  226. }
  227. }
  228. } else {
  229. let newTr = "";
  230. let companyName = $("#companyIds option[value='" + companyId + "']").text();
  231. newTr = '<tr data-id="' + companyId + '"><td style="width:10%;">' + companyName + '</td><td style="width:90%"><ul>';
  232. for (let n in bindFileTypes) {
  233. let fileType = bindFileTypes[n];
  234. let typename = $("#bindFileTypes option[value='" + fileType + "']").text();
  235. var checked = "";
  236. if (typeof cfg != "undefined" && cfg.indexOf(fileType) > -1 && $("input[type=checkbox][value='" + fileType + "']:checked").length == 0)
  237. checked = "checked";
  238. if (IdentifyConditionInfoDlg.fstLoad && checked == "checked") {
  239. $("input[type=checkbox][value='" + fileType + "']").prop("disabled", true);
  240. }
  241. let disabled = $("input[type=checkbox][value='" + fileType + "']:checked").length > 0 ? "disabled" : "";
  242. newTr += '<li><label for="relation[' + companyId + ']">' + typename + '</label><input type="checkbox" data-company-id="' + companyId + '" value="' + fileType + '" ' + checked + " " + disabled + ' onchange="IdentifyConditionInfoDlg.onCheckChange(this);"></li>';
  243. }
  244. newTr += '</ul></td></tr>'
  245. $("#relationTable tbody").append(newTr);
  246. }
  247. }
  248. IdentifyConditionInfoDlg.fstLoad = false;
  249. }
  250. IdentifyConditionInfoDlg.onCheckChange = function (chk) {
  251. var typeId = $(chk).val();
  252. if ($(chk).is(":checked")) {
  253. $("input[type=checkbox][value='" + typeId + "']").prop("disabled", true);
  254. $(chk).removeAttr("disabled");
  255. } else {
  256. $("input[type=checkbox][value='" + typeId + "']").removeAttr("disabled");
  257. }
  258. }
  259. /**
  260. * 验证数据是否为空
  261. */
  262. IdentifyConditionInfoDlg.validate = function () {
  263. $('#identifyConditionInfoForm').data("bootstrapValidator").resetForm();
  264. $('#identifyConditionInfoForm').bootstrapValidator('validate');
  265. return $("#identifyConditionInfoForm").data('bootstrapValidator').isValid();
  266. }
  267. $(function () {
  268. Feng.initValidator("identifyConditionInfoForm", IdentifyConditionInfoDlg.validateFields);
  269. var arr = [{
  270. "name": "talentLevel",
  271. "code": "talent_arrange"
  272. }];
  273. Feng.findChildDictBatch(JSON.stringify(arr));
  274. Feng.addAjaxSelect({
  275. "id": "companyIds",
  276. "displayCode": "id",
  277. "displayName": "name",
  278. "type": "GET",
  279. "url": Feng.ctxPath + "/common/api/getCompanyKvs"
  280. });
  281. $('#companyIds').chosen({
  282. search_contains: true,
  283. disable_search: false,
  284. width: "100%",
  285. enable_split_word_search: true
  286. });
  287. $('#bindFileTypes').chosen({
  288. search_contains: true,
  289. disable_search: false,
  290. width: "100%",
  291. enable_split_word_search: true
  292. });
  293. //下拉框数据回显
  294. $("select").each(function () {
  295. $(this).val($(this).attr("selectVal"));
  296. });
  297. var companyIds = $("#companyIds").attr("selectVal");
  298. if (Feng.isNotEmptyStr(companyIds)) {
  299. $("#companyIds").val(companyIds.split(",")).trigger("chosen:updated");
  300. }
  301. var type = $("#type").val();
  302. if (type > 0) {
  303. IdentifyConditionInfoDlg.onTypeChange();
  304. }
  305. var bindFileTypes = $("#bindFileTypes").attr("selectVal");
  306. if (Feng.isNotEmptyStr(bindFileTypes)) {
  307. $("#bindFileTypes").val(bindFileTypes.split(",")).trigger("chosen:updated");
  308. }
  309. IdentifyConditionInfoDlg.onCompanyOrTypeChange();
  310. });