change_apply_information.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author EllisRan
  6. * @date 2022/01/21
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. $.subMenu({
  11. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  12. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  13. key: 'menu.1.0.0',
  14. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  15. callback: function (info) {
  16. if (info.mini) {
  17. $('.panel-title').addClass('fluid');
  18. $('#sub-menu').removeClass('panel-sidebar');
  19. } else {
  20. $('.panel-title').removeClass('fluid');
  21. $('#sub-menu').addClass('panel-sidebar');
  22. }
  23. autoFlashHeight();
  24. }
  25. });
  26. handleFileList(fileList);
  27. $('#file-ok').click(function () {
  28. const files = Array.from($('#file-modal')[0].files)
  29. const valiData = files.map(v => {
  30. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  31. return {
  32. size: v.size,
  33. ext
  34. }
  35. });
  36. console.log(!$('#addfujian input[name="type"]:checked').val());
  37. if (!$('#addfujian input[name="type"]:checked').val()) {
  38. toastr.error('请选择资料类型');
  39. return false;
  40. }
  41. if (validateFiles(valiData)) {
  42. if (files.length) {
  43. const formData = new FormData();
  44. formData.append('type', $('#addfujian input[name="type"]:checked').val());
  45. files.forEach(file => {
  46. formData.append('name', file.name);
  47. formData.append('size', file.size);
  48. formData.append('file', file);
  49. })
  50. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  51. handleFileList(result);
  52. $('#file-cancel').click();
  53. });
  54. }
  55. }
  56. })
  57. function handleFileList(files = []) {
  58. $('#file-content').empty();
  59. // const { uncheck, checkNo } = auditConst.status
  60. const newFiles = files.map(file => {
  61. let showDel = false;
  62. if (file.uid === cur_uid) {
  63. // if (!curAuditor) {
  64. // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
  65. // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
  66. // } else {
  67. // curAuditor.audit_id === cur_uid && (showDel = true)
  68. // }
  69. if (change.status === auditConst.status.checked) {
  70. showDel = Boolean(file.extra_upload )
  71. } else {
  72. showDel = true
  73. }
  74. }
  75. return {...file, showDel}
  76. })
  77. let html = change.filePermission ? `<tr><td colspan="6"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
  78. newFiles.forEach((file, idx) => {
  79. if (file.showDel) {
  80. html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/apply/${file.caid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
  81. } else {
  82. html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/apply/${file.caid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
  83. }
  84. })
  85. $('#file-content').append(html);
  86. }
  87. $('#file-content').on('click', 'a', function () {
  88. if ($(this).hasClass('file-del')) {
  89. const id = $(this).data('id');
  90. postData(preUrl + '/file/delete', {id}, (result) => {
  91. handleFileList(result);
  92. })
  93. }
  94. });
  95. // 回车提交
  96. $('#apply-table input').on('keypress', function () {
  97. if(window.event.keyCode === 13) {
  98. $(this).blur();
  99. }
  100. });
  101. $('#apply-table input').blur(function () {
  102. const val_name = $(this).data('name');
  103. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  104. switch(val_name) {
  105. case 'code':
  106. if(!val) {
  107. toastr.error('申请编号不能为空');
  108. $(this).val(change[val_name]);
  109. return false;
  110. }
  111. break;
  112. case 'name':
  113. if(val && val.length > 100) {
  114. toastr.error('名称超过100个字,请缩减名称');
  115. $(this).val(change[val_name]);
  116. return false;
  117. }
  118. break;
  119. case 'org_price':
  120. case 'change_price':
  121. case 'crease_price':
  122. val = val ? parseFloat(val) : null;
  123. if(val && !_.isNumber(val)) {
  124. toastr.error('请输入数字');
  125. $(this).val(change[val_name]);
  126. return false;
  127. }
  128. break;
  129. default:
  130. if(val && val.length > 255) {
  131. toastr.error('超出字段范围,请缩减');
  132. $(this).val(change[val_name]);
  133. return false;
  134. }
  135. break;
  136. }
  137. if(change[val_name] !== val) {
  138. const _self = $(this);
  139. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  140. change[val_name] = val;
  141. _self.val(change[val_name]);
  142. if (val_name === 'code') {
  143. $('#change-apply-code').text(change[val_name]);
  144. }
  145. }, function () {
  146. _self.val(change[val_name]);
  147. })
  148. } else {
  149. $(this).val(change[val_name]);
  150. }
  151. });
  152. $('#apply-table textarea').blur(function () {
  153. const val_name = $(this).data('name');
  154. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  155. if(change[val_name] !== val) {
  156. const _self = $(this);
  157. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  158. change[val_name] = val;
  159. _self.val(change[val_name]);
  160. }, function () {
  161. _self.val(change[val_name]);
  162. })
  163. } else {
  164. $(this).val(change[val_name]);
  165. }
  166. });
  167. $('#project-table select').change(function () {
  168. const val_name = $(this).attr('data-name');
  169. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  170. if(change[val_name] !== val) {
  171. const _self = $(this);
  172. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  173. change[val_name] = val;
  174. _self.val(change[val_name]);
  175. }, function () {
  176. _self.val(change[val_name]);
  177. })
  178. } else {
  179. $(this).val(change[val_name]);
  180. }
  181. })
  182. });
  183. /**
  184. * 校验文件大小、格式
  185. * @param {Array} files 文件数组
  186. */
  187. function validateFiles(files) {
  188. if (files.length > 10) {
  189. toastr.error('至多同时上传10个文件');
  190. return false
  191. }
  192. return files.every(file => {
  193. if (file.size > 1024 * 1024 * 30) {
  194. toastr.error('文件大小限制为30MB');
  195. return false
  196. }
  197. if (whiteList.indexOf('.' + file.ext) === -1) {
  198. toastr.error('请上传正确的格式文件');
  199. return false
  200. }
  201. return true
  202. })
  203. }