identifyCondition_info.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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('talentLevelCat')
  77. .set('name')
  78. .set('active')
  79. .set('description')
  80. .set('isSalary');
  81. var companys = $("#companyIds").val();
  82. var bindFileTypes = $("#bindFileTypes").val();
  83. var company_ids = "", bind_fts_ids = "";
  84. for (var key in companys) {
  85. if (Feng.isNotEmptyStr(companys[key])) {
  86. company_ids = company_ids + companys[key] + ",";
  87. }
  88. }
  89. if (Feng.isNotEmptyStr(company_ids)) {
  90. company_ids = company_ids.substring(0, company_ids.length - 1);
  91. }
  92. for (var key in bindFileTypes) {
  93. if (Feng.isNotEmptyStr(bindFileTypes[key])) {
  94. bind_fts_ids = bind_fts_ids + bindFileTypes[key] + ",";
  95. }
  96. }
  97. if (Feng.isNotEmptyStr(bind_fts_ids)) {
  98. bind_fts_ids = bind_fts_ids.substring(0, bind_fts_ids.length - 1);
  99. }
  100. this.identifyConditionInfoData['companyIds'] = company_ids;
  101. this.identifyConditionInfoData['bindFileTypes'] = bind_fts_ids;
  102. var chks = $("#relationTable input[type=checkbox]:checked");
  103. var relation = {};
  104. for (var i = 0; i < chks.length; i++) {
  105. var companyId = $(chks[i]).data("company-id");
  106. if (typeof relation[companyId] == "undefined") {
  107. relation[companyId] = $(chks[i]).val();
  108. } else {
  109. relation[companyId] += "," + $(chks[i]).val();
  110. }
  111. }
  112. this.identifyConditionInfoData['relation'] = relation;
  113. }
  114. IdentifyConditionInfoDlg.otherValid = function () {
  115. if (this.identifyConditionInfoData.companyIds == '') {
  116. Feng.error("请选择审核单位");
  117. return false;
  118. }
  119. if (this.identifyConditionInfoData.bindFileTypes == '') {
  120. Feng.error("请选择审核附件");
  121. return false;
  122. }
  123. var companyIds = this.identifyConditionInfoData.companyIds.split(",");
  124. var total = companyIds.length;
  125. var _goal = 0;
  126. for (var i = 0; i < total; i++) {
  127. var companyId = companyIds[i];
  128. _goal += $("input[type=checkbox][data-company-id='" + companyId + "']:checked").length > 0 ? 1 : 0;
  129. }
  130. if (_goal != total) {
  131. Feng.error("存在审核单位没有成功关联附件");
  132. return false;
  133. }
  134. var fileTypes = this.identifyConditionInfoData.bindFileTypes.split(",");
  135. total = fileTypes.length;
  136. _goal = 0;
  137. for (var i = 0; i < total; i++) {
  138. var typeId = fileTypes[i];
  139. _goal += $("input[type=checkbox][value='" + typeId + "']:checked").length > 0 ? 1 : 0;
  140. }
  141. if (_goal != total) {
  142. Feng.error("选择了审核单位及审核附件后,每个附件必须与其中一个审核单位关联");
  143. return false;
  144. }
  145. return true;
  146. }
  147. /**
  148. * 提交添加
  149. */
  150. IdentifyConditionInfoDlg.addSubmit = function () {
  151. this.clearData();
  152. this.collectData();
  153. if (!this.validate() || !IdentifyConditionInfoDlg.otherValid()) {
  154. return;
  155. }
  156. var ajax = new $ax("/admin/talent_condition/add", function (data) {
  157. if (data.code == "200") {
  158. Feng.success(data.msg);
  159. window.parent.IdentifyCondition.table.refresh();
  160. IdentifyConditionInfoDlg.close();
  161. } else {
  162. Feng.error(data.msg);
  163. }
  164. }, function (data) {
  165. Feng.error("添加失败!" + data.responseJSON.message + "!");
  166. });
  167. ajax.set(this.identifyConditionInfoData);
  168. ajax.start();
  169. }
  170. /**
  171. * 提交修改
  172. */
  173. IdentifyConditionInfoDlg.editSubmit = function () {
  174. this.clearData();
  175. this.collectData();
  176. if (!this.validate() || !IdentifyConditionInfoDlg.otherValid()) {
  177. return;
  178. }
  179. var ajax = new $ax(Feng.ctxPath + "/admin/talent_condition/edit", function (data) {
  180. if (data.code == "200") {
  181. Feng.success(data.msg);
  182. window.parent.IdentifyCondition.table.refresh();
  183. IdentifyConditionInfoDlg.close();
  184. } else {
  185. Feng.error(data.msg);
  186. }
  187. }, function (data) {
  188. Feng.error("修改失败!" + data.responseJSON.message + "!");
  189. });
  190. ajax.set(this.identifyConditionInfoData);
  191. ajax.start();
  192. }
  193. IdentifyConditionInfoDlg.onTypeChange = function () {
  194. var type = $("#type").val();
  195. Feng.addAjaxSelect({
  196. "id": "bindFileTypes",
  197. "displayCode": "id",
  198. "displayName": "name",
  199. "type": "GET",
  200. "url": Feng.ctxPath + "/common/api/getConditionFileTypesByType/type/" + type
  201. });
  202. $("#bindFileTypes").trigger("chosen:updated");
  203. }
  204. IdentifyConditionInfoDlg.onLayerChange = function () {
  205. var lv = $("#talentLevel").val();
  206. Feng.addAjaxSelect({
  207. "id": "talentLevelCat",
  208. "displayCode": "code",
  209. "displayName": "name",
  210. "type": "GET",
  211. "url": Feng.ctxPath + "/common/api/getLayerCatsByLayer/level/" + lv
  212. });
  213. }
  214. IdentifyConditionInfoDlg.onCompanyOrTypeChange = function () {
  215. var companyIds = $("#companyIds").val();
  216. var bindFileTypes = $("#bindFileTypes").val();
  217. IdentifyConditionInfoDlg.buildRelationTable(companyIds, bindFileTypes);
  218. }
  219. IdentifyConditionInfoDlg.fstLoad = true;
  220. IdentifyConditionInfoDlg.buildRelationTable = function (companyIds, bindFileTypes) {
  221. var companyWithFileType = $("#companyWithFileType").val();
  222. var setting = [];
  223. if (companyWithFileType) {
  224. var companyTmps = companyWithFileType.split(";")
  225. for (var i in companyTmps) {
  226. var _companyTmp = companyTmps[i].split(":");
  227. var _companyId = _companyTmp[0];
  228. var _fileTypes = _companyTmp[1].split(",");
  229. setting[_companyId] = _fileTypes;
  230. }
  231. }
  232. var trs = $("#relationTable tbody").find("tr");
  233. trs.each(function (index, tr) {
  234. if (!companyIds || companyIds.indexOf($(tr).data("id").toString()) == -1)
  235. $(tr).remove();
  236. })
  237. for (let i in companyIds) {
  238. let companyId = companyIds[i];
  239. if (companyId == "")
  240. continue;
  241. var cfg = setting[companyId];
  242. if ($("#relationTable tbody").find("tr[data-id='" + companyId + "']").length > 0) {
  243. var chks = $("#relationTable tbody").find("tr[data-id='" + companyId + "']").find("input[type=checkbox]");
  244. chks.each(function (index, chk) {
  245. if (!bindFileTypes || bindFileTypes.indexOf($(chk).val().toString()) == -1)
  246. $(chk).parents("li").remove();
  247. })
  248. for (let n in bindFileTypes) {
  249. let fileType = bindFileTypes[n];
  250. if ($("#relationTable tbody").find("tr[data-id='" + companyId + "']").find("input[value='" + fileType + "']").length == 0) {
  251. let typename = $("#bindFileTypes option[value='" + fileType + "']").text();
  252. let disabled = $("input[type=checkbox][value='" + fileType + "']:checked").length > 0 ? "disabled" : "";
  253. let li = '<li><label for="relation[' + companyId + ']">' + typename + '</label><input type="checkbox" data-company-id="' + companyId + '" value="' + fileType + '" ' + disabled + ' onchange="IdentifyConditionInfoDlg.onCheckChange(this);"></li>';
  254. $("#relationTable tbody").find("tr[data-id='" + companyId + "'] ul").append(li);
  255. }
  256. }
  257. } else {
  258. let newTr = "";
  259. let companyName = $("#companyIds option[value='" + companyId + "']").text();
  260. newTr = '<tr data-id="' + companyId + '"><td style="width:10%;">' + companyName + '</td><td style="width:90%"><ul>';
  261. for (let n in bindFileTypes) {
  262. let fileType = bindFileTypes[n];
  263. let typename = $("#bindFileTypes option[value='" + fileType + "']").text();
  264. var checked = "";
  265. if (typeof cfg != "undefined" && cfg.indexOf(fileType) > -1 && $("input[type=checkbox][value='" + fileType + "']:checked").length == 0)
  266. checked = "checked";
  267. if (IdentifyConditionInfoDlg.fstLoad && checked == "checked") {
  268. $("input[type=checkbox][value='" + fileType + "']").prop("disabled", true);
  269. }
  270. let disabled = $("input[type=checkbox][value='" + fileType + "']:checked").length > 0 ? "disabled" : "";
  271. newTr += '<li><label for="relation[' + companyId + ']">' + typename + '</label><input type="checkbox" data-company-id="' + companyId + '" value="' + fileType + '" ' + checked + " " + disabled + ' onchange="IdentifyConditionInfoDlg.onCheckChange(this);"></li>';
  272. }
  273. newTr += '</ul></td></tr>'
  274. $("#relationTable tbody").append(newTr);
  275. }
  276. }
  277. IdentifyConditionInfoDlg.fstLoad = false;
  278. }
  279. IdentifyConditionInfoDlg.onCheckChange = function (chk) {
  280. var typeId = $(chk).val();
  281. if ($(chk).is(":checked")) {
  282. $("input[type=checkbox][value='" + typeId + "']").prop("disabled", true);
  283. $(chk).removeAttr("disabled");
  284. } else {
  285. $("input[type=checkbox][value='" + typeId + "']").removeAttr("disabled");
  286. }
  287. }
  288. /**
  289. * 验证数据是否为空
  290. */
  291. IdentifyConditionInfoDlg.validate = function () {
  292. $('#identifyConditionInfoForm').data("bootstrapValidator").resetForm();
  293. $('#identifyConditionInfoForm').bootstrapValidator('validate');
  294. return $("#identifyConditionInfoForm").data('bootstrapValidator').isValid();
  295. }
  296. $(function () {
  297. Feng.initValidator("identifyConditionInfoForm", IdentifyConditionInfoDlg.validateFields);
  298. var arr = [{
  299. "name": "talentLevel",
  300. "code": "talent_arrange"
  301. }];
  302. Feng.findChildDictBatch(JSON.stringify(arr));
  303. Feng.addAjaxSelect({
  304. "id": "companyIds",
  305. "displayCode": "id",
  306. "displayName": "name",
  307. "type": "GET",
  308. "url": Feng.ctxPath + "/common/api/getCompanyKvs"
  309. });
  310. $('#companyIds').chosen({
  311. search_contains: true,
  312. disable_search: false,
  313. width: "100%",
  314. enable_split_word_search: true
  315. });
  316. $('#bindFileTypes').chosen({
  317. search_contains: true,
  318. disable_search: false,
  319. width: "100%",
  320. enable_split_word_search: true
  321. });
  322. //下拉框数据回显
  323. $("select").each(function () {
  324. $(this).val($(this).attr("selectVal"));
  325. });
  326. var lv = $("#talentLevel").val();
  327. if (lv > 0) {
  328. IdentifyConditionInfoDlg.onLayerChange();
  329. $("#talentLevelCat").val($("#talentLevelCat").attr("selectVal"));
  330. }
  331. var companyIds = $("#companyIds").attr("selectVal");
  332. if (Feng.isNotEmptyStr(companyIds)) {
  333. $("#companyIds").val(companyIds.split(",")).trigger("chosen:updated");
  334. }
  335. var type = $("#type").val();
  336. if (type > 0) {
  337. IdentifyConditionInfoDlg.onTypeChange();
  338. }
  339. var bindFileTypes = $("#bindFileTypes").attr("selectVal");
  340. if (Feng.isNotEmptyStr(bindFileTypes)) {
  341. $("#bindFileTypes").val(bindFileTypes.split(",")).trigger("chosen:updated");
  342. }
  343. IdentifyConditionInfoDlg.onCompanyOrTypeChange();
  344. });