change_project_information.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. if (validateFiles(valiData)) {
  37. if (files.length) {
  38. const formData = new FormData()
  39. files.forEach(file => {
  40. formData.append('name', file.name)
  41. formData.append('size', file.size)
  42. formData.append('file', file)
  43. })
  44. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  45. handleFileList(result);
  46. $('#file-cancel').click()
  47. });
  48. }
  49. }
  50. })
  51. function handleFileList(files = []) {
  52. $('#file-content').empty();
  53. // const { uncheck, checkNo } = auditConst.status
  54. const newFiles = files.map(file => {
  55. let showDel = false;
  56. if (file.uid === cur_uid) {
  57. // if (!curAuditor) {
  58. // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
  59. // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
  60. // } else {
  61. // curAuditor.audit_id === cur_uid && (showDel = true)
  62. // }
  63. if (change.status === auditConst.status.checked) {
  64. showDel = Boolean(file.extra_upload )
  65. } else {
  66. showDel = true
  67. }
  68. }
  69. return {...file, showDel}
  70. })
  71. let html = change.filePermission ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
  72. newFiles.forEach((file, idx) => {
  73. if (file.showDel) {
  74. html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
  75. } else {
  76. html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td></td></tr>`
  77. }
  78. })
  79. $('#file-content').append(html);
  80. }
  81. $('#file-content').on('click', 'a', function () {
  82. if ($(this).hasClass('file-del')) {
  83. const id = $(this).data('id');
  84. postData(preUrl + '/file/delete', {id}, (result) => {
  85. handleFileList(result);
  86. })
  87. }
  88. });
  89. // 回车提交
  90. $('#project-table input').on('keypress', function () {
  91. if(window.event.keyCode === 13) {
  92. $(this).blur();
  93. }
  94. });
  95. $('#project-table input').blur(function () {
  96. const val_name = $(this).data('name');
  97. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  98. switch(val_name) {
  99. case 'code':
  100. if(!val) {
  101. toastr.error('立项书编号不能为空');
  102. $(this).val(change[val_name]);
  103. return false;
  104. }
  105. break;
  106. case 'name':
  107. if(!val) {
  108. toastr.error('工程名称不能为空');
  109. $(this).val(change[val_name]);
  110. return false;
  111. } else if(val.length > 100) {
  112. toastr.error('名称超过100个字,请缩减名称');
  113. $(this).val(change[val_name]);
  114. return false;
  115. }
  116. break;
  117. case 'org_price':
  118. case 'change_price':
  119. case 'crease_price':
  120. val = val ? parseFloat(val) : null;
  121. if(val && !_.isNumber(val)) {
  122. toastr.error('请输入数字');
  123. $(this).val(change[val_name]);
  124. return false;
  125. }
  126. break;
  127. default:
  128. if(val && val.length > 255) {
  129. toastr.error('超出字段范围,请缩减');
  130. $(this).val(change[val_name]);
  131. return false;
  132. }
  133. break;
  134. }
  135. if(change[val_name] !== val) {
  136. const _self = $(this);
  137. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  138. change[val_name] = val;
  139. _self.val(change[val_name]);
  140. if (val_name === 'code') {
  141. $('#change-project-code').text(change[val_name]);
  142. }
  143. }, function () {
  144. _self.val(change[val_name]);
  145. })
  146. } else {
  147. $(this).val(change[val_name]);
  148. }
  149. })
  150. $('#project-table textarea').blur(function () {
  151. const val_name = $(this).data('name');
  152. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  153. if(change[val_name] !== val) {
  154. const _self = $(this);
  155. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  156. change[val_name] = val;
  157. _self.val(change[val_name]);
  158. }, function () {
  159. _self.val(change[val_name]);
  160. })
  161. } else {
  162. $(this).val(change[val_name]);
  163. }
  164. })
  165. });
  166. /**
  167. * 校验文件大小、格式
  168. * @param {Array} files 文件数组
  169. */
  170. function validateFiles(files) {
  171. if (files.length > 10) {
  172. toastr.error('至多同时上传10个文件');
  173. return false
  174. }
  175. return files.every(file => {
  176. if (file.size > 1024 * 1024 * 30) {
  177. toastr.error('文件大小限制为30MB');
  178. return false
  179. }
  180. if (whiteList.indexOf('.' + file.ext) === -1) {
  181. toastr.error('请上传正确的格式文件');
  182. return false
  183. }
  184. return true
  185. })
  186. }