integralInfo_select.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. * 初始化人才认定申报详情对话框
  3. */
  4. var locked = false;
  5. var IntegralInfoDlg = {
  6. integralInfoData: {}
  7. };
  8. /**
  9. * 关闭此对话框
  10. */
  11. IntegralInfoDlg.close = function () {
  12. parent.layer.close(window.parent.TalentInfo.layerIndex);
  13. }
  14. /**
  15. * 初始化表格的列
  16. */
  17. IntegralInfoDlg.initFileTypeColumn = function () {
  18. return [
  19. {field: 'selectItem', checkbox: false, visible: false},
  20. {title: '附件列表', field: 'name', visible: true, align: 'left', valign: 'middle', width: "100%", 'class': 'uitd_showTip',
  21. formatter: function (value, row, index) {
  22. return '<span style="color:#ff0000;">申报"' + value + '"积分项目需要上传以下附件(带*号的附件必需上传)</span>';
  23. }
  24. },
  25. {title: '模板', field: 'templateUrl', visible: true, align: 'center', valign: 'middle', width: "8%"},
  26. {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle', width: "10%"}
  27. ]
  28. };
  29. IntegralInfoDlg.changeAndLoadFile = function () {
  30. var table = $(".fileTable");
  31. var items = $("select[name='item_id[]']");
  32. var item_id = [];
  33. for (var i = 0; i < items.length; i++) {
  34. let _id = items.eq(i).val();
  35. if (_id) {
  36. item_id.push(_id);
  37. }
  38. }
  39. if (item_id.length == 0) {
  40. table.bootstrapTable("destroy");
  41. return;
  42. }
  43. var ajax = new $ax("/common/api/findCommonFileType", function (data) {
  44. if (data == null || data.length == 0) {
  45. return;
  46. }
  47. table.bootstrapTable("destroy");
  48. table.bootstrapTable({
  49. columns: IntegralInfoDlg.initFileTypeColumn(),
  50. data: data.rows,
  51. showHeader: true,
  52. rowStyle: function (row, index) {
  53. return {classes: ""};
  54. },
  55. onPostBody: function (data) {
  56. for (var i in data) {
  57. var fileTypes = data[i].fileTypes;
  58. for (var k in fileTypes) {
  59. var fileType = fileTypes[k];
  60. /**-- 构造附件类型标题栏 --**/
  61. let name = '<div class="word-wrap">';
  62. if (fileType.must == 1) {
  63. name = name + '<i class="fa fa-paste"></i><span style="font-weight:bold;color:red;font-size:14px;font-family:宋体"> * </span> ' + fileType.name;
  64. }
  65. if (fileType.must == 2) {
  66. name = name + '<i class="fa fa-paste"></i>' + fileType.name;
  67. }
  68. name = name + '<br />' + fileType.description + '</div>'
  69. var template = "";
  70. if (fileType.templateUrl == null || fileType.templateUrl == '' || fileType.templateUrl == 'null') {
  71. template = '无';
  72. } else {
  73. template = "<button type='button' onclick=\"IntegralInfoDlg.downloadFile('" + fileType.id + "',3)\" style='margin-right: 10px' class=\"btn btn-xs btn-primary\">" +
  74. "<i class=\"fa fa-download\"></i>下载" +
  75. "</button>";
  76. }
  77. var uploadBtn = IntegralInfoDlg.validUploadButton(1, fileType.id, '', data[i].id);
  78. var tr = '<tr class="subTitleLine"><td class="uitd_showTip" style="text-align: left; vertical-align: middle; width: 82%; ">'
  79. + name +
  80. '</td>\n\
  81. \n\
  82. <td style="text-align: center; vertical-align: middle; width: 8%; ">' + template +
  83. '</td>\n\
  84. <td style="text-align: center; vertical-align: middle; width: 10%; ">' + uploadBtn +
  85. '</td></tr>';
  86. /**-- --**/
  87. var typeId = fileType.id;
  88. var files = fileType.files;
  89. var html = '<ul class="imgs"><li style="width: 70%;font-weight: bold;padding-top: 5px;">附件原名</li><li style="width: 10%;font-weight: bold;padding-top: 5px;">预览</li><li style="width: 20%;font-weight: bold;padding-top: 5px;">操作</li>';
  90. for (var key in files) {
  91. var btn = "";
  92. btn = IntegralInfoDlg.validUploadButton(2, typeId, files[key].id, files[key].relationId);
  93. var sn = files[key].url.lastIndexOf(".");
  94. var suffix = files[key].ext; //files[key].url.substring(sn + 1, files[key].url.length);
  95. var imgStr = "";
  96. if (suffix == "pdf" || suffix == "PDF") {
  97. imgStr = "<button type='button' onclick=\"Feng.showPdf('" + files[key].url + "','" + files[key].id + "','" + files[key].orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-pdf-o\" aria-hidden=\"true\"></i></button>";
  98. } else if (suffix == "xlsx" || suffix == "XLSX" || suffix == 'xls' || suffix == 'XLS' || suffix == 'docx' || suffix == 'doc' || suffix == 'DOCX' || suffix == 'DOC') {
  99. imgStr = "<button type='button' onclick=\"Feng.showExcel('" + files[key].url + "','" + files[key].id + "','" + files[key].orignName + "')\" class=\"btn btn-xs btn-danger\"><i class=\"fa fa-file-excel-o\" aria-hidden=\"true\"></i></button>";
  100. } else {
  101. imgStr = '<img class=\"imgUrl\" onclick=\"Feng.showImg(this)\" src=\"' + files[key].url + '\" style=\"width:25px;height:25px;\">';
  102. }
  103. html += '<li data-id="' + files[key].id + '">\n\
  104. <div><input type="hidden" name="uploadFiles[]" value="' + files[key].id + '"></div>\n' +
  105. '<div style="width: 70%;">' + files[key].orignName + '</div>\n' +
  106. '<div style="width: 10%;">' + imgStr + '</div>\n' +
  107. '<div style="width: 20%;">' + btn + '</div>\n\
  108. </li>';
  109. }
  110. html = html + '</ul>';
  111. table.find("tr[data-index='" + i + "'] td").eq(0).attr("colspan", 3);
  112. table.find("tr[data-index='" + i + "'] td").eq(1).remove();
  113. table.find("tr[data-index='" + i + "'] td").eq(2).remove();
  114. table.find("tr[data-index='" + i + "']").after(tr);
  115. table.find("tr[data-index='" + i + "']").next(".subTitleLine").after('<tr class="detail-view"><td colspan="5">' + html + '</td></tr>');
  116. }
  117. }
  118. $("td.uitd_showTip").bind("mouseover", function () {
  119. var htm = $(this).html();
  120. $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
  121. });
  122. },
  123. });
  124. }, function (data) {
  125. Feng.error("查询失败!" + data.responseJSON.message + "!");
  126. });
  127. var queryData = {};
  128. queryData["mainId"] = $("#id").val();
  129. queryData['project'] = CONFIG.project_integral_apply;
  130. queryData['type'] = $("#type").val();
  131. queryData["itemId"] = item_id;
  132. queryData['checkState'] = $("#checkState").val();
  133. ajax.set(queryData);
  134. ajax.start();
  135. }
  136. IntegralInfoDlg.onProjectTypeChange = function (obj) {
  137. var projectType = $(obj).val();
  138. var projectObj = $(obj).parents("table").find("select[name='projectId[]']")
  139. Feng.addAjaxSelect({
  140. "obj": projectObj,
  141. "displayCode": "id",
  142. "displayName": "name",
  143. "type": "GET",
  144. "url": "/common/api/getIntegralProjectsByType/projectType/" + projectType
  145. });
  146. }
  147. IntegralInfoDlg.onProjectChange = function (obj) {
  148. var projectId = $(obj).val();
  149. var itemObj = $(obj).parents("table").find("select[name='item_id[]']")
  150. Feng.addAjaxSelect({
  151. "obj": itemObj,
  152. "displayCode": "id",
  153. "displayName": "name",
  154. "bindData": "unit",
  155. "type": "GET",
  156. "url": "/common/api/getIntegralItemsByProject/projectId/" + projectId
  157. });
  158. }
  159. IntegralInfoDlg.onItemChange = function (obj) {
  160. var unit = $(obj).find("option:selected").data("unit");
  161. var parent = $(obj).parents("table");
  162. if (typeof unit != "undefined" && unit) {
  163. parent.find(".unit").html("(" + unit + ")");
  164. } else {
  165. parent.find(".unit").html("");
  166. }
  167. IntegralInfoDlg.changeAndLoadFile();
  168. }
  169. var currentTable = null;
  170. var currentTr = null;
  171. //选择附件并显示附件名
  172. IntegralInfoDlg.checkFile = function (content, fileTypeId, fileId, itemId) {
  173. currentTable = $(content).parents(".fileTable");
  174. var findTr = null;
  175. var curTr = $(content).parents("tr");
  176. while (!findTr) {
  177. if (curTr.prev("tr[data-index]")) {
  178. findTr = curTr.prev("tr[data-index]")
  179. } else {
  180. curTr = curTr.prev();
  181. }
  182. }
  183. currentTr = findTr.data("index");
  184. if (!IntegralInfoDlg.validateIsEdit())
  185. return;
  186. $("#upload_file").unbind("change");
  187. $("#upload_file").change(function () {
  188. if (!Feng.chkFileInvalid(this.files[0], 5, 10))
  189. return;
  190. IntegralInfoDlg.upload(fileTypeId, fileId, itemId);
  191. });
  192. $('#upload_file').val("");
  193. $('#upload_file').click();
  194. }
  195. //上传附件
  196. IntegralInfoDlg.upload = function (fileTypeId, fileId, itemId) {
  197. var id = $("#id").val();
  198. if (!IntegralInfoDlg.validateIsEdit())
  199. return;
  200. if (fileId != null && fileId != 'null') {
  201. $("#fileId").val(fileId)
  202. } else {
  203. $("#fileId").val("");
  204. }
  205. $("#mainId").val(id);
  206. $("#fileTypeId").val(fileTypeId);
  207. var index = layer.load(0, {shade: false, time: 0});
  208. $("#index").val(index);
  209. $("#relationId").val(itemId);
  210. $("#pageToken").val($("input[name=__token__]").val());
  211. $("#uploadForm").submit();
  212. }
  213. //删除附件
  214. IntegralInfoDlg.deleteFile = function (id, state) {
  215. if (!IntegralInfoDlg.validateIsEdit())
  216. return;
  217. var operation = function () {
  218. var ajax = new $ax(Feng.ctxPath + "/common/api/deleteFile", function (data) {
  219. if (data.code == 200) {
  220. Feng.success(data.msg);
  221. $("input[name='uploadFiles[]'][value='" + id + "']").parents("li").remove();
  222. //$("#fileTable").bootstrapTable("refresh", {});
  223. } else {
  224. Feng.error(data.msg);
  225. }
  226. }, function (data) {
  227. Feng.error("删除失败!" + data.responseJSON.message + "!");
  228. });
  229. ajax.set("id", id);
  230. ajax.set("type", 1);
  231. ajax.start();
  232. }
  233. Feng.confirm("删除后无法恢复,确认删除吗?", operation);
  234. }
  235. /**
  236. * 校验是否显示按钮
  237. * @param type 类型 1-上传按钮,2-修改删除按钮
  238. * @param row
  239. * @returns {string}
  240. */
  241. IntegralInfoDlg.validUploadButton = function (type, fileTypeId, fileId, itemId) {
  242. var files = $("#files").val();
  243. files = files.split(",");
  244. var checkState = $("#checkState").val();
  245. var realState = $("#realState").val();
  246. if (Feng.isEmptyStr(checkState) || checkState == 0 || (checkState == 1 && realState == 1) || (realState == 4 && files[0] == 1)) {
  247. if (type == 1) { //上传
  248. return "<button type='button' onclick=\"IntegralInfoDlg.checkFile(this," + fileTypeId + "," + null + "," + itemId + ")\" style='margin-right: 10px' class=\"btn btn-xs btn-info\">" +
  249. "<i class=\"fa fa-upload\"></i>上传" +
  250. "</button>";
  251. } else {
  252. return "<button type=\'button\' onclick=\"IntegralInfoDlg.checkFile(this," + fileTypeId + "," + fileId + "," + itemId + ")\" style=\'margin-right: 10px\' class=\"btn btn-xs btn-info\">" +
  253. "<i class=\"fa fa-paste\"></i>修改" +
  254. "</button>" +
  255. "<button type='button' onclick=\"IntegralInfoDlg.deleteFile(" + fileId + ")\" class=\"btn btn-xs btn-danger\">" +
  256. "<i class=\"fa fa-times\"></i>删除" +
  257. "</button>";
  258. }
  259. } else {
  260. return "";
  261. }
  262. }
  263. IntegralInfoDlg.downloadFile = function (id, type) {
  264. window.location.href = Feng.ctxPath + "/api/common/downloadFile?id=" + id + "&type=" + type;
  265. }
  266. //设置不可修改的字段
  267. IntegralInfoDlg.setNoChangeField = function () {
  268. $("input,textarea").each(function () {
  269. $(this).attr("readonly", "readonly");
  270. });
  271. $("select,input[type=radio]").each(function () {
  272. $(this).attr("disabled", "disabled");
  273. });
  274. }
  275. $(function () {
  276. var id = $("#id").val();
  277. var checkState = $("#checkState").val();
  278. if (id != null && id != '') {
  279. //select初始化
  280. $("select").each(function () {
  281. $(this).val($(this).attr("value")).trigger("change");
  282. });
  283. Feng.getCheckLog("logTable", {"type": CONFIG.project_integral_apply, "mainId": id, "typeFileId": "", "active": 1})
  284. }
  285. $("#card_type").val($("#card_type").attr("value"));
  286. IntegralInfoDlg.setNoChangeField();
  287. //IntegralInfoDlg.changeAndLoadFile();
  288. });