enterprise_change_edit.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. var locked = false;
  2. var EpChangeEdit = {
  3. epChangeEditData: {},
  4. validateFields: {
  5. newName: {validators: {notEmpty: {message: '学校名称不能为空'}}}, //, regexp: {regexp: /^([\u4E00-\u9FA5]|\(|\)){1,100}$/, message: "单位名称只允许中文"}
  6. newIdCard: {validators: {notEmpty: {message: '统一社会信用代码不能为空'}}},
  7. newLegal: {validators: {notEmpty: {message: '法人代表不能为空'}}}, //, regexp: {regexp: /^[\u4e00-\u9fa5]{1,50}$/, message: "法人代表只允许中文"}
  8. newProvince: {validators: {notEmpty: {message: '请选择学校所在省份'}}},
  9. newCity: {validators: {notEmpty: {message: '请选择学校所在市'}}},
  10. newCounty: {
  11. validators: {
  12. callback: {
  13. message: "请选择学校所在县/区",
  14. callback: function (value, validator) {
  15. if ($("#newProvince").val() > 0 && $("#newCity").val() > 0 && $("#newCounty option").length > 1 && $("#newCounty option:selected").length == 0) {
  16. //当省市都有值时,如果县有列表,必选
  17. return false;
  18. }
  19. return true;
  20. }
  21. }
  22. }
  23. },
  24. newAddress: {validators: {notEmpty: {message: '学校地址不能为空'}}},
  25. newAgentName: {validators: {notEmpty: {message: '人才联络员不能为空'}}},
  26. newEphone: {
  27. validators: {
  28. notEmpty: {
  29. message: '学校电话不能为空'
  30. },
  31. regexp: {
  32. regexp: /(^(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})))$/,
  33. message: "学校电话格式不正确"
  34. }
  35. }
  36. },
  37. newAgentPhone: {
  38. validators: {
  39. notEmpty: {
  40. message: '人才联络员电话不能为空'
  41. },
  42. regexp: {
  43. regexp: /(^(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})))$/,
  44. message: "人才联络员电话格式不正确"
  45. }
  46. }
  47. },
  48. newAgentEmail: {
  49. validators: {
  50. notEmpty: {
  51. message: '电子邮箱不能为空'
  52. },
  53. emailAddress: {
  54. message: "电子邮箱格式不正确"
  55. }
  56. }
  57. }
  58. }
  59. };
  60. /**
  61. * 清除数据
  62. */
  63. EpChangeEdit.clearData = function () {
  64. this.epChangeEditData = {};
  65. }
  66. /**
  67. * 设置对话框中的数据
  68. *
  69. * @param key 数据的名称
  70. * @param val 数据的具体值
  71. */
  72. EpChangeEdit.set = function (key, val) {
  73. this.epChangeEditData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
  74. return this;
  75. }
  76. /**
  77. * 设置对话框中的数据
  78. *
  79. * @param key 数据的名称
  80. * @param val 数据的具体值
  81. */
  82. EpChangeEdit.get = function (key) {
  83. return $("#" + key).val();
  84. }
  85. /**
  86. * 关闭此对话框
  87. */
  88. EpChangeEdit.close = function () {
  89. parent.layer.close(window.parent.EnterpriseCenter.layerIndex);
  90. }
  91. /**
  92. * 收集数据
  93. */
  94. EpChangeEdit.collectData = function () {
  95. this
  96. .set('id')
  97. .set('type')
  98. .set('newName')
  99. .set('newIdCard')
  100. .set('newLegal')
  101. .set('newProvince')
  102. .set('newCity')
  103. .set('newCounty')
  104. .set('newAddress')
  105. .set('newEphone')
  106. .set('newAgentName')
  107. .set('newAgentPhone')
  108. .set('newAgentEmail')
  109. .set('enterprise_id');
  110. }
  111. /**
  112. * 验证数据
  113. */
  114. EpChangeEdit.validate = function () {
  115. $('#ecr_form').data("bootstrapValidator").resetForm();
  116. $('#ecr_form').bootstrapValidator('validate');
  117. return $("#ecr_form").data('bootstrapValidator').isValid();
  118. }
  119. EpChangeEdit.initFileTable = function () {
  120. $("#fileTable").bootstrapTable({
  121. url: Feng.ctxPath + "/common/api/listCurrencyFileType",
  122. method: 'POST',
  123. contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  124. search: false, // 是否显示表格搜索,此搜索是客户端搜索,不会进服务端
  125. showRefresh: false, // 是否显示刷新按钮
  126. clickToSelect: true, // 是否启用点击选中行
  127. singleSelect: true, // 设置True 将禁止多选
  128. striped: true, // 是否显示行间隔色
  129. escape: true,
  130. pagination: false, // 设置为 true 会在表格底部显示分页条
  131. paginationHAlign: "left",
  132. paginationDetailHAlign: "right",
  133. sidePagination: "server", // 设置在哪里进行分页,可选值为 'client' 或者 'server'
  134. showColumns: false,
  135. detailView: true, //是否显示父子表
  136. pageList: [10, 30, 50],
  137. queryParams: function (params) {
  138. return $.extend({"type": "enterpriseChange"}, params)
  139. },
  140. rowStyle: function (row, index) {
  141. return {classes: "info"};
  142. },
  143. columns: EpChangeEdit.initFileTypeColumn(),
  144. onPostBody: function () {
  145. $("td.uitd_showTip").bind("mouseover", function () {
  146. var htm = $(this).html();
  147. $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
  148. });
  149. },
  150. onLoadSuccess: function (data) {
  151. $("#fileTable").bootstrapTable('expandAllRows');
  152. },
  153. onExpandRow: function (index, row, $detail) {
  154. var ajax = new $ax(Feng.ctxPath + "/common/api/listTalentCommonFile", function (data) {
  155. if (data == null || data.length == 0) {
  156. return;
  157. }
  158. var checkState = $("#checkState").length > 0 ? $("#checkState").val() : 1;
  159. var files = "";
  160. if (checkState != 1) {
  161. files = $("#files").val().split(",");
  162. }
  163. var html = '<ul class="imgs"><li style="width: 80%;font-weight: bold;padding-top: 5px;">附件原名</li><li style="width: 10%;font-weight: bold;padding-top: 5px;">预览</li><li style="width: 10%;font-weight: bold;padding-top: 5px;">操作</li>';
  164. for (var key in data) {
  165. var sn = data[key].url.lastIndexOf(".");
  166. var suffix = data[key].ext;//data[key].url.substring(sn+1,data[key].url.length);
  167. var imgStr = "";
  168. if (suffix == "pdf" || suffix == "PDF") {
  169. imgStr = "<button type='button' onclick=\"Feng.showPdf('" + data[key].url + "','" + data[key].id + "','" + data[key].orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-pdf-o\" aria-hidden=\"true\"></i></button>";
  170. } else if (suffix == "xlsx" || suffix == "XLSX" || suffix == 'xls' || suffix == 'XLS' || suffix == 'docx' || suffix == 'doc' || suffix == 'DOCX' || suffix == 'DOC') {
  171. imgStr = "<button type='button' onclick=\"Feng.showExcel('" + data[key].url + "','" + data[key].id + "','" + data[key].orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-excel-o\" aria-hidden=\"true\"></i></button>";
  172. } else {
  173. imgStr = '<img class=\"imgUrl\" src=\"' + data[key].url + '\" style=\"width:25px;height:25px;\">';
  174. }
  175. var btn = "<button type=\'button\' onclick=\"EpChangeEdit.checkFile('" + row.id + "','" + data[key].id + "')\" style=\'margin-right: 10px\' class=\"btn btn-xs btn-info\"><i class=\"fa fa-paste\"></i>修改</button>" +
  176. "<button type='button' onclick=\"EpChangeEdit.deleteFile('" + data[key].id + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-times\"></i>删除</button>";
  177. html = html + '<li style="display: none">' + data[key].id + '</li>\n' +
  178. '<li style="width: 80%;padding-top: 5px;">' + data[key].orignName + '</li>\n' +
  179. '<li style="width: 10%;">' + imgStr + '</li>\n' +
  180. '<li style="width: 10%;padding-top: 2px;">' + (checkState == 1 ? btn : (files.indexOf(data[key].typeId.toString()) > -1 ? btn : "")) + '</li>';
  181. }
  182. html = html + '</ul>';
  183. $detail.html(html);
  184. $(".imgs").viewer({
  185. // toolbar:false,
  186. fullscreen: false
  187. });
  188. }, function (data) {
  189. Feng.error("查询失败!" + data.responseJSON.message + "!");
  190. });
  191. var queryData = {};
  192. queryData["mainId"] = $("#id").val();
  193. queryData["typeId"] = row.id;
  194. ajax.set(queryData);
  195. ajax.start();
  196. }
  197. });
  198. }
  199. EpChangeEdit.initFileTypeColumn = function () {
  200. return [
  201. {field: 'selectItem', checkbox: false, visible: false},
  202. {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle', width: "30%", 'class': 'uitd_showTip',
  203. formatter: function (value, row, index) {
  204. if (row.must == 1) {
  205. return '<i class="fa fa-paste"></i><span style="font-weight:bold;color:red;font-size:14px;font-family:宋体"> * </span> ' + value;
  206. }
  207. if (row.must == 2) {
  208. return '<i class="fa fa-paste"></i>' + value;
  209. }
  210. }
  211. },
  212. {title: '备注', field: 'description', visible: true, align: 'center', valign: 'middle', width: "50%", 'class': 'uitd_showTip',
  213. formatter: function (value, row, index) {
  214. return '<span style="color: red">' + value + '</span>';
  215. }
  216. },
  217. {title: '模板', field: 'templateUrl', visible: true, align: 'center', valign: 'middle', width: "10%",
  218. formatter: function (value, row, index) {
  219. if (value == null || value == '' || value == 'null') {
  220. return '无';
  221. }
  222. return "<button type='button' onclick=\"Feng.downloadFile('" + row.id + "',3)\" style='margin-right: 10px' class=\"btn btn-xs btn-primary\">" +
  223. "<i class=\"fa fa-download\"></i>下载" +
  224. "</button>";
  225. }
  226. },
  227. {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle', width: "10%",
  228. formatter: function (value, row, index) {
  229. var checkState = $("#checkState").length > 0 ? $("#checkState").val() : 1;
  230. if (checkState == 1) {
  231. return "<button type='button' onclick=\"EpChangeEdit.checkFile('" + value + "','" + null + "')\" style='margin-right: 10px' class=\"btn btn-xs btn-info\">" +
  232. "<i class=\"fa fa-upload\"></i>上传" +
  233. "</button>";
  234. } else {
  235. var files = $("#files").val().split(",");
  236. if (files.indexOf(value.toString()) != -1) {
  237. return "<button type='button' onclick=\"EpChangeEdit.checkFile('" + value + "','" + null + "')\" style='margin-right: 10px' class=\"btn btn-xs btn-info\">" +
  238. "<i class=\"fa fa-upload\"></i>上传" +
  239. "</button>";
  240. } else {
  241. return "";
  242. }
  243. }
  244. }
  245. }
  246. ]
  247. }
  248. //选择附件并显示附件名
  249. EpChangeEdit.checkFile = function (fileTypeId, fileId) {
  250. var checkState = $("#checkState").val();
  251. if (checkState == 2) {
  252. Feng.error("正在审核中,无法修改");
  253. return;
  254. }
  255. if (checkState == 4) {
  256. Feng.error("审核通过,无法修改");
  257. return;
  258. }
  259. $("#upload_file").unbind("change");
  260. $("#upload_file").change(function () {
  261. if (!Feng.chkFileInvalid(this.files[0], 5, 10, ["image/jpeg", "image/gif", "image/png", "image/jpg", "application/pdf"], "只允许上传PDF或图片"))
  262. return;
  263. EpChangeEdit.upload(fileTypeId, fileId);
  264. });
  265. $('#upload_file').val("");
  266. $('#upload_file').click()
  267. }
  268. //上传附件
  269. EpChangeEdit.upload = function (fileTypeId, fileId) {
  270. if (fileId != null && fileId != 'null') {
  271. $("#fileId").val(fileId)
  272. } else {
  273. $("#fileId").val("");
  274. }
  275. $("#mainId").val($("#id").val());
  276. $("#typeId").val(fileTypeId);
  277. var index = layer.load(0, {shade: false, time: 0});
  278. $("#index").val(index);
  279. $("#uploadForm").submit();
  280. }
  281. //删除附件
  282. EpChangeEdit.deleteFile = function (id) {
  283. var checkState = $("#checkState").val();
  284. if (checkState == 2) {
  285. Feng.error("正在审核中,无法修改");
  286. return;
  287. }
  288. if (checkState == 4) {
  289. Feng.error("审核通过,无法删除");
  290. return;
  291. }
  292. var operation = function () {
  293. var ajax = new $ax("/common/api/deleteTalentCommonFile", function (data) {
  294. if (data.code == 200) {
  295. Feng.success(data.msg);
  296. $("#fileTable").bootstrapTable("refresh", {});
  297. } else {
  298. Feng.error(data.msg);
  299. }
  300. }, function (data) {
  301. Feng.error("删除失败!" + data.responseJSON.message + "!");
  302. });
  303. ajax.set("id", id);
  304. ajax.start();
  305. }
  306. Feng.confirm("删除后无法恢复,确认删除吗?", operation);
  307. }
  308. EpChangeEdit.addSubmit = function () {
  309. this.clearData();
  310. this.collectData();
  311. if (!this.validate()) {
  312. return;
  313. }
  314. var checkState = $("#checkState").val();
  315. if (checkState == 2 || checkState == 5 || checkState == 7) {
  316. Feng.info("正在审核中,无法修改")
  317. return;
  318. }
  319. if (checkState == 4) {
  320. Feng.info("已审核通过,无法修改")
  321. return;
  322. }
  323. // $(".layui-layer-btn0",parent.document).css("pointer-events","none");
  324. if (locked) {
  325. Feng.info("保存进行中,请耐心等候")
  326. return;
  327. }
  328. locked = true;
  329. layer.load(0, {shade: false, time: 0});
  330. /*var ajax = new $ax(Feng.ctxPath + "/enterprise/api/upsert", function (data) {
  331. if (data.code == "200") {
  332. Feng.success(data.msg);
  333. $("#fileLi").removeAttr("style");
  334. $("#id").val(data.obj.id);
  335. $("#checkState").val(data.obj.checkState);
  336. window.parent.EnterpriseCenter.table.refresh();
  337. } else {
  338. Feng.info(data.msg);
  339. }
  340. // $(".layui-layer-btn0",parent.document).css("pointer-events","block");
  341. locked = false;
  342. }, function (data) {
  343. Feng.error("添加失败!" + data.responseJSON.msg + "!");
  344. locked = false;
  345. });
  346. ajax.set(this.epChangeEditData);
  347. ajax.start();*/
  348. $("#ecr_form :input").removeAttr("disabled");
  349. $("#ecr_form").attr("action", "/enterprise/api/upsert");
  350. $("#ecr_form")[0].submit();
  351. };
  352. /**
  353. * 提交审核
  354. */
  355. EpChangeEdit.submitToCheck = function () {
  356. if (locked) {
  357. Feng.info("保存进行中,请耐心等候")
  358. return;
  359. }
  360. var id = $("#id").val();
  361. if (id == null || id == "") {
  362. Feng.info("请先填写基础信息并上传附件");
  363. return;
  364. }
  365. var checkState = $("#checkState").val();
  366. if (checkState == 2 || checkState == 5) {
  367. Feng.error("正在审核中,无法修改");
  368. return;
  369. }
  370. if (checkState == 4) {
  371. Feng.error("审核通过,无法修改");
  372. return;
  373. }
  374. $(".layui-layer-btn1", parent.document).css("pointer-events", "none");
  375. var operation = function () {
  376. var ajax = new $ax(Feng.ctxPath + "/enterprise/api/submitToCheck", function (data) {
  377. if (data.code == 200) {
  378. Feng.success(data.msg);
  379. window.parent.EnterpriseCenter.table.refresh();
  380. EpChangeEdit.close();
  381. } else {
  382. Feng.error(data.msg);
  383. }
  384. $(".layui-layer-btn1", parent.document).css("pointer-events", "block");
  385. }, function (data) {
  386. Feng.error("提交审核失败!" + data.responseJSON.message + "!");
  387. $(".layui-layer-btn1", parent.document).css("pointer-events", "block");
  388. });
  389. ajax.set("id", id);
  390. ajax.start();
  391. }
  392. Feng.confirm("请确认基础信息已核对无误,相应附件已上传,一旦提交,无法修改", operation);
  393. }
  394. EpChangeEdit.setFieldDisabled = function () {
  395. var checkState = $("#checkState").length > 0 ? $("#checkState").val() : 1;
  396. if (checkState != 1) {
  397. $("#ecr_form :input").prop("disabled", true);
  398. $("#ecr_form :button").css("display", "none");
  399. var fields = $("#fields").val().split(",");
  400. for (var i in fields) {
  401. $("#" + fields[i]).removeAttr("disabled");
  402. }
  403. var files = $("#files").val().split(",");
  404. for (var i in files) {
  405. switch (files[i]) {
  406. case "newImgurl":
  407. $("#imgurl").removeAttr("disabled");
  408. $("#imgurl").parent().find("button").removeAttr("disabled").css("display", "block");
  409. break;
  410. case "newBankImg":
  411. $("#bankImg").removeAttr("disabled");
  412. $("#bankImg").parent().find("button").removeAttr("disabled").css("display", "block");
  413. break;
  414. case "newDomainImg":
  415. $("#domainImg").removeAttr("disabled");
  416. $("#domainImg").parent().find("button").removeAttr("disabled").css("display", "block");
  417. break;
  418. case "newTypeImg":
  419. $("#typeImg").removeAttr("disabled");
  420. $("#typeImg").parent().find("button").removeAttr("disabled").css("display", "block");
  421. break;
  422. case "newBeian":
  423. $("#beian").removeAttr("disabled");
  424. $("#beian").parent().find("button").removeAttr("disabled").css("display", "block");
  425. break;
  426. }
  427. }
  428. }
  429. }
  430. EpChangeEdit.callBack = function (data) {
  431. layer.closeAll();
  432. EpChangeEdit.setFieldDisabled();
  433. locked = false;
  434. Feng.info(data.msg);
  435. if (data.code == 200) {
  436. $("#id").val(data.id);
  437. $("input[type=file]").val("");
  438. window.parent.EnterpriseCenter.table.refresh();
  439. }
  440. };
  441. EpChangeEdit.downloadFile = function (id) {
  442. window.location.href = Feng.ctxPath + '/enterprisechangeRecord/downloadFile?id=' + id;
  443. };
  444. $("#imgurl,#bankImg,#beian,#domainImg,#typeImg").change(function (e) {
  445. var that = this;
  446. if (!Feng.chkFileInvalid(that.files[0], 5, 10, ["image/jpeg", "image/gif", "image/png", "image/jpg", "application/pdf"], "只允许上传PDF或图片")) {
  447. return;
  448. }
  449. var file = that.files[0];
  450. var imgSrc;
  451. var reader = new FileReader();
  452. reader.readAsDataURL(file);
  453. reader.onload = function () {
  454. if (Feng.isImg(file.type)) {
  455. imgSrc = this.result;
  456. $(that).prev("img").attr("src", imgSrc);
  457. } else {
  458. $(that).prev("img").attr("src", Feng.ctxPath + "/static/img/Pdf.png");
  459. Feng.info("上传成功!<span style='color:red;'>*点击图标可预览</span>");
  460. }
  461. };
  462. });
  463. $("img").click(function () {
  464. var fileInput = $(this).next("input");
  465. var file = fileInput[0].files[0];
  466. if (typeof file != "undefined" && file.type == "application/pdf") {
  467. var url = URL.createObjectURL(file);
  468. var filename = file.name;
  469. //window.open(url)
  470. Feng.pdfReader(url, filename);
  471. } else {
  472. var url = $(this).data("url");
  473. if (typeof url != "undefined") {
  474. Feng.showPdf(url);
  475. }
  476. }
  477. })
  478. EpChangeEdit.afterSelectProvince = function () {
  479. var province = $("#newProvince").val();
  480. $("#newCity").empty();
  481. $("#newCounty").empty();
  482. if (province == null || province == '') {
  483. return;
  484. }
  485. Feng.addAjaxSelect({
  486. "id": "newCity",
  487. "displayCode": "code",
  488. "displayName": "name",
  489. "type": "GET",
  490. "url": Feng.ctxPath + "/common/tool/findCityByProvinceSelect/code/" + province
  491. });
  492. }
  493. /**
  494. * 加载县
  495. */
  496. EpChangeEdit.afterSelectCity = function () {
  497. var city = $("#newCity").val();
  498. $("#newCounty").empty();
  499. if (city == null || city == '') {
  500. return;
  501. }
  502. Feng.addAjaxSelect({
  503. "id": "newCounty",
  504. "displayCode": "code",
  505. "displayName": "name",
  506. "type": "GET",
  507. "url": Feng.ctxPath + "/common/tool/findCountyByCitySelect/code/" + city
  508. });
  509. }
  510. $(function () {
  511. EpChangeEdit.setFieldDisabled();
  512. var type = $("#type").val();
  513. var special = parseInt($("#special").val());
  514. $('#ecr_form').bootstrapValidator({
  515. feedbackIcons: {
  516. valid: 'glyphicon glyphicon-ok',
  517. invalid: 'glyphicon glyphicon-remove',
  518. validating: 'glyphicon glyphicon-refresh'
  519. },
  520. group: '.rowGroup',
  521. fields: EpChangeEdit.validateFields,
  522. live: 'enabled',
  523. message: '该字段不能为空'
  524. });
  525. //加载省份
  526. Feng.addAjaxSelect({
  527. "id": "newProvince",
  528. "displayCode": "code",
  529. "displayName": "name",
  530. "type": "GET",
  531. "url": Feng.ctxPath + "/common/tool/getProvinceSelect"
  532. });
  533. $("select").each(function () {
  534. $(this).val($(this).attr("value"));
  535. $(this).trigger("change");
  536. })
  537. var id = $("#id").val();
  538. if (id != null && id != '') {
  539. $("#fileLi").removeAttr("style");
  540. } else {
  541. $("#fileLi").attr("style", "pointer-events: none");
  542. }
  543. });