construction_info.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. $(function () {
  2. autoFlashHeight();
  3. //编辑input及textarea
  4. $('.edit-input').on('change', function () {
  5. const newVal = _.trim($(this).val());
  6. const id = $(this).data('id');
  7. if (newVal.length > 1000) {
  8. toastr.error('内容字符长度不能超过1000');
  9. return false;
  10. }
  11. updateJsonData(newVal, id);
  12. });
  13. $('.edit-textarea').on('change', function () {
  14. const newVal = $(this).val();
  15. const id = $(this).data('id');
  16. if (newVal.length > 10000) {
  17. toastr.error('内容字符长度不能超过10000');
  18. return false;
  19. }
  20. updateJsonData(newVal, id);
  21. });
  22. function updateJsonData(newVal, id) {
  23. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/save`, { type: 'update_json', updateData: { key: id, value: newVal } }, function (result) {
  24. });
  25. }
  26. // 审签人选择
  27. let timer = null
  28. let oldSearchVal = null
  29. $('#gr-search').bind('input propertychange', function(e) {
  30. oldSearchVal = e.target.value
  31. timer && clearTimeout(timer)
  32. timer = setTimeout(() => {
  33. const newVal = $('#gr-search').val()
  34. let html = ''
  35. if (newVal && newVal === oldSearchVal) {
  36. accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  37. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  38. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  39. class="ml-auto">${item.mobile || ''}</span></p>
  40. <span class="text-muted">${item.role || ''}</span>
  41. </dd>`
  42. })
  43. $('.book-list').empty()
  44. $('.book-list').append(html)
  45. } else {
  46. if (!$('.acc-btn').length) {
  47. accountGroup.forEach((group, idx) => {
  48. if (!group) return
  49. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  50. </a> ${group.groupName}</dt>
  51. <div class="dd-content" data-toggleid="${idx}">`
  52. group.groupList.forEach(item => {
  53. if (item.id !== cur_uid) {
  54. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  55. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  56. class="ml-auto">${item.mobile || ''}</span></p>
  57. <span class="text-muted">${item.role || ''}</span>
  58. </dd>`
  59. }
  60. });
  61. html += '</div>'
  62. })
  63. $('.book-list').empty()
  64. $('.book-list').append(html)
  65. }
  66. }
  67. }, 400);
  68. })
  69. // 添加审批流程按钮逻辑
  70. $('.book-list').on('click', 'dt', function () {
  71. const idx = $(this).find('.acc-btn').attr('data-groupid')
  72. const type = $(this).find('.acc-btn').attr('data-type')
  73. if (type === 'hide') {
  74. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  75. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  76. $(this).find('.acc-btn').attr('data-type', 'show')
  77. })
  78. } else {
  79. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  80. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  81. $(this).find('.acc-btn').attr('data-type', 'hide')
  82. })
  83. }
  84. return false
  85. });
  86. // 添加到审批流程中
  87. $('dl').on('click', 'dd', function () {
  88. const id = parseInt($(this).data('id'));
  89. if (id) {
  90. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/save`, { type: 'set_shenpi', uid: id }, function (result) {
  91. $('#show-shenpi-btn').hide();
  92. $('#show-shenpi span').text(result.shenpi_username);
  93. $('#show-shenpi').show();
  94. });
  95. }
  96. });
  97. $('.remove-shenpi-btn').on('click', function () {
  98. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/save`, { type: 'remove_shenpi' }, function (result) {
  99. $('#show-shenpi-btn').show();
  100. $('#show-shenpi span').text('');
  101. $('#show-shenpi').hide();
  102. });
  103. });
  104. $('body').on('click', '#start-btn', function () {
  105. // 判断是否已选择审签人,有则提交
  106. const username = $('#show-shenpi span').text() || $('#show-shenpi-input').val();
  107. if (username == '') {
  108. toastr.error('请选择审签人再提交');
  109. return false;
  110. }
  111. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/save`, { type: 'start' }, function (result) {
  112. window.location.reload();
  113. });
  114. });
  115. $('#edit-start').click(function () {
  116. // $('#edit-end').show();
  117. $('#edit-start').hide();
  118. $('.edit-input').removeAttr('readonly');
  119. $('.edit-textarea').removeAttr('readonly');
  120. $(this).siblings('span').hide();
  121. $(this).parents('.title-main').append('<a href="javascript:void(0);" id="start-btn" class="btn btn-sm btn-primary pull-right mr-2">提交审签</a>');
  122. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/save`, { type: 'checkNo' }, function (result) {
  123. // window.location.reload();
  124. });
  125. });
  126. // $('#edit-end').click(function () {
  127. // $('#edit-start').show();
  128. // $('#edit-end').hide();
  129. // $('.edit-input').attr('readonly', true);
  130. // $('.edit-textarea').attr('readonly', true);
  131. // });
  132. $('#check-btn').click(function () {
  133. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/save`, { type: 'checked' }, function (result) {
  134. window.location.reload();
  135. });
  136. });
  137. // 上传附件
  138. $('#upload-file-btn').click(function () {
  139. const files = $('#upload-file')[0].files;
  140. const formData = new FormData();
  141. for (const file of files) {
  142. if (file === undefined) {
  143. toastr.error('未选择上传文件!');
  144. return false;
  145. }
  146. const filesize = file.size;
  147. if (filesize > 30 * 1024 * 1024) {
  148. toastr.error('文件大小过大!');
  149. return false;
  150. }
  151. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  152. if (whiteList.indexOf(fileext) === -1) {
  153. toastr.error('只能上传指定格式的附件!');
  154. return false;
  155. }
  156. formData.append('size', filesize);
  157. formData.append('file[]', file);
  158. }
  159. if (!filePermission) {
  160. toastr.error('无权限上传!');
  161. return false;
  162. }
  163. postDataWithFile(`/sp/${spid}/construction/${tender_id}/log/${log_id}/file/upload`, formData, function (data) {
  164. attData = data.concat(attData);
  165. // 重新生成List
  166. getAllList();
  167. $('#upload').modal('hide');
  168. }, function () {
  169. });
  170. $('#upload-file').val('');
  171. });
  172. // 删除附件
  173. $('body').on('click', '.delete-file', function () {
  174. let attid = $(this).data('attid');
  175. const data = {id: attid};
  176. postData(`/sp/${spid}/construction/${tender_id}/log/${log_id}/file/delete`, data, function (result) {
  177. // 删除到attData中
  178. const att_index = attData.findIndex(function (item) {
  179. return item.id === parseInt(attid);
  180. });
  181. attData.splice(att_index, 1);
  182. getAllList();
  183. });
  184. });
  185. // $('#attList').on('click', '.file-atn', function() {
  186. // const id = $(this).attr('f-id');
  187. // postData(`/construction/${tender_id}/log/${log_id}/file/${id}/download`, {}, (data) => {
  188. // const { filepath } = data;
  189. // $('#file-upload').attr('href', filepath);
  190. // $('#file-upload')[0].click();
  191. // })
  192. // });
  193. // 生成附件列表
  194. function getAllList() {
  195. let html = '';
  196. for(const [index,att] of attData.entries()) {
  197. html += `<tr class="text-center">
  198. <td width="5%">${index+1}</td>
  199. <td class="text-left"><a href="${att.filepath}" target="_blank">${att.filename}${att.fileext}</a></td>
  200. <td width="15%">${moment(att.upload_time).format("YYYY-MM-DD HH:mm:ss")}</td>
  201. <td width="10%">
  202. <a href="/sp/${spid}/construction/${tender_id}/log/${log_id}/file/${att.id}/download" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  203. html += (att.uid === accountId && (logStatus === constructionStatusConst.checked ? Boolean(att.extra_upload) : true)) ?
  204. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  205. html += `</td>`;
  206. }
  207. $('#attList').html(html);
  208. $('#attList').on('click', 'tr', function() {
  209. $('#attList tr').removeClass('bg-light');
  210. $(this).addClass('bg-light');
  211. });
  212. }
  213. });