identifyCondition_info.js 13 KB

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