integralInfo_select.js 13 KB

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