advance_audit.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author lanjianrong
  6. * @date 2020/8/7
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. autoFlashHeight()
  11. const decimal = 2
  12. let oldVal = null
  13. let timer = null
  14. let oldSearchVal = null
  15. handleFileList(fileList)
  16. // 控制上报弹窗的文案
  17. function checkModal(isHide) {
  18. $('#start-modal').empty()
  19. if (isHide) {
  20. // 隐藏上传按钮
  21. $('#start-modal').append('<p class="text-danger">无法上报,请设置审批流程。</p>')
  22. $('#tm-submit').hide()
  23. } else {
  24. $('#start-modal').append(`<p>确认上报第${advance.order}期${advance.type === 0 ? '开工' : '材料'}预付款?</p>`)
  25. $('#tm-submit').show()
  26. }
  27. }
  28. $('#gr-search').bind('input propertychange', function(e) {
  29. oldSearchVal = e.target.value
  30. timer && clearTimeout(timer)
  31. timer = setTimeout(() => {
  32. const newVal = $('#gr-search').val()
  33. let html = ''
  34. if (newVal && newVal === oldSearchVal) {
  35. accountList.filter(item => item && cur_uid !== item.id && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  36. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  37. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  38. class="ml-auto">${item.mobile || ''}</span></p>
  39. <span class="text-muted">${item.role || ''}</span>
  40. </dd>`
  41. })
  42. $('.book-list').empty()
  43. $('.book-list').append(html)
  44. } else {
  45. if (!$('.acc-btn').length) {
  46. accountGroup.forEach((group, idx) => {
  47. if (!group) return
  48. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  49. </a> ${group.groupName}</dt>
  50. <div class="dd-content" data-toggleid="${idx}">`
  51. group.groupList.forEach(item => {
  52. if (item.id !== cur_uid) {
  53. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  54. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  55. class="ml-auto">${item.mobile || ''}</span></p>
  56. <span class="text-muted">${item.role || ''}</span>
  57. </dd>`
  58. }
  59. });
  60. html += '</div>'
  61. })
  62. $('.book-list').empty()
  63. $('.book-list').append(html)
  64. }
  65. }
  66. }, 400);
  67. })
  68. // 添加审批流程按钮逻辑
  69. $('.book-list').on('click', 'dt', function () {
  70. const idx = $(this).find('.acc-btn').attr('data-groupid')
  71. const type = $(this).find('.acc-btn').attr('data-type')
  72. if (type === 'hide') {
  73. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  74. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  75. $(this).find('.acc-btn').attr('data-type', 'show')
  76. })
  77. } else {
  78. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  79. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  80. $(this).find('.acc-btn').attr('data-type', 'hide')
  81. })
  82. }
  83. return false
  84. })
  85. // 添加到审批流程中
  86. $('dl').on('click', 'dd', function () {
  87. const id = parseInt($(this).data('id'))
  88. if (id !== 0) {
  89. postData(preUrl + '/audit/add', { auditorId: id }, (datas) => {
  90. // <p class="m-0 ml-2"><small class="text-muted">中交第一公路工程局有限公司国道311线满别公路施工一分部</small></p>
  91. const html = [];
  92. // 如果是重新上报,添加到重新上报列表中
  93. const auditorshtml = [];
  94. for (const [index,data] of datas.entries()) {
  95. if (index !== 0) {
  96. html.push('<li class="list-group-item" auditorId="'+ data.audit_id +'">');
  97. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  98. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  99. }
  100. html.push('<span>');
  101. html.push(data.order + ' ');
  102. html.push(data.name + ' ');
  103. html.push('</span>');
  104. html.push('<small class="text-muted">');
  105. html.push(data.role);
  106. html.push('</small>');
  107. html.push(`<p class="m-0 ml-2"><small class="text-muted">${data.company}</small></p></li>`);
  108. }
  109. // 添加新审批人流程修改
  110. auditorshtml.push('<li class="list-group-item" data-auditorid="' + data.audit_id + '">');
  111. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  112. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  113. if (index === 0) {
  114. auditorshtml.push('<span class="pull-right">原报</span>');
  115. } else if (index+1 === datas.length) {
  116. auditorshtml.push('<span class="pull-right">终审</span>');
  117. } else {
  118. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  119. }
  120. auditorshtml.push('</li>');
  121. }
  122. $('#auditors').html(html.join(''));
  123. $('#auditors2').html(auditorshtml.join(''));
  124. // if ($('.fa-stop-circle').length) {
  125. // $('.fa-stop-circle').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down')
  126. // }
  127. // const auditorsHTML = `<li class="list-group-item" data-auditorId='${data.audit_id}'><i class="fa fa fa-stop-circle" ></i> ${data.name} <small class="text-muted">${data.role}</small></li>`
  128. // $('#auditors2').append(auditorsHTML)
  129. if ($('#auditors')[0].children.length > 0) {
  130. checkModal(false)
  131. }
  132. });
  133. }
  134. });
  135. // 删除审批人
  136. $('body').on('click', '#auditors li>a', function () {
  137. const li = $(this).parent()
  138. const data = {
  139. auditorId: parseInt(li.attr('auditorId')),
  140. };
  141. postData(preUrl + '/audit/delete', data, (result) => {
  142. li.remove();
  143. for (const rst of result) {
  144. const aLi = $('li[auditorId=' + rst.audit_id + ']');
  145. $('span', aLi).text(rst.order + ' ' + rst.name + ' ')
  146. }
  147. // 删除左边审核人
  148. $(`#auditors2 li[data-auditorid='${data.auditorId}']`).remove();
  149. if ($('#auditors2 li').length !== 0 && !$('#auditors2 li i').hasClass('fa-stop-circle')) {
  150. $('#auditors2 li').eq($('#auditors2 li').length-1).children('i')
  151. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  152. }
  153. for (let i = 0; i < $('#auditors2 li').length; i++) {
  154. $('#auditors2 li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors2 li').length ? '终' : transFormToChinese(i)) + '审');
  155. }
  156. })
  157. });
  158. $('#au-btn').on('click','a', function() {
  159. const content = $(this).data('target')
  160. switch (content) {
  161. case '#sub-sp':
  162. if ($('#auditors')[0].children.length) {
  163. checkModal(false)
  164. } else {
  165. checkModal(true)
  166. }
  167. break;
  168. default:
  169. break;
  170. }
  171. })
  172. // 上报审批
  173. $('#tm-submit').click(function() {
  174. const pay_ratio = parseFloat($(`.pay-input[data-type=0]`).val())
  175. const cur_amount = parseFloat(parseFloat($(`.pay-input[data-type=1]`).val()).toFixed(decimal))
  176. if (!pay_ratio || !cur_amount) {
  177. return toastr.error('请填写本期金额!')
  178. }
  179. const prev_amount = prevAdvance && prevAdvance.prev_total_amount || 0
  180. const prev_total_amount = ZhCalc.add(cur_amount, prev_amount)
  181. const remark = filterText($('#ad-remark').val())
  182. const data = {pay_ratio, cur_amount, prev_amount, prev_total_amount, remark, status: auditConst.status.checking}
  183. postData(preUrl + '/audit/start', data, (data) => {
  184. window.location.reload()
  185. }, () => {
  186. window.location.reload()
  187. })
  188. })
  189. // 重新上报
  190. $('#sp-list2-btn').click(() => {
  191. $('#tm-submit').trigger('click')
  192. })
  193. // 转化成两位小数
  194. function fixedToSub(s, decimal = 2) {
  195. return parseFloat(parseFloat(s).toFixed(decimal))
  196. }
  197. // 自动转换支付比例和本期金额
  198. $('.pay-input').on('change', function(e) {
  199. let val = parseFloat(e.target.value)
  200. const p_amount = prevAdvance && prevAdvance.prev_total_amount || 0 // 截止本期金额
  201. const re_amount = ZhCalc.sub(advancePayTotal, p_amount) // 剩余未付款的总额
  202. const min = parseFloat($(this).attr('min'))
  203. const max = parseFloat($(this).attr('max'))
  204. const type = parseInt($(this).data('type'))
  205. let pay_ratio = null
  206. let cur_amount = null
  207. let isLimitMax = false // 用来判断是否达到最大
  208. if (val < min) {
  209. // 限制最小值为min
  210. $(this).val(min)
  211. val = min
  212. }
  213. if (max && val > max) {
  214. // 限制最大值为max
  215. $(this).val(max)
  216. val = max
  217. }
  218. // 本期金额转化
  219. if (type === 1) {
  220. if (val >= re_amount) {
  221. // 限制不能超过最大值
  222. val = re_amount
  223. isLimitMax = true
  224. }
  225. $(this).val(isLimitMax ? val : fixedToSub(val, decimal)) // 重新赋值限制只有两位小数
  226. const pay_a_input = $(`.pay-input[data-type=${reverse(type)}]`)
  227. pay_ratio = ZhCalc.mul(ZhCalc.div(val, advancePayTotal), 100).toFixed(2)
  228. cur_amount = isLimitMax ? re_amount : ZhCalc.round(val, decimal)
  229. pay_a_input.val(pay_ratio)
  230. const total = ZhCalc.add(cur_amount, p_amount).toString().split('.')[1] || ''
  231. // 截止本期金额文案更新
  232. $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount), ',', isLimitMax ? total.length : 2) + '元')
  233. } else {
  234. // 支付比例转化
  235. val = fixedToSub(val)
  236. if (val.toFixed(2) === max.toFixed(2)) {
  237. // 比例达到最大,特殊处理金额的显示小数点
  238. val = fixedToSub(max, 2);
  239. isLimitMax = true
  240. }
  241. $(this).val(val) // 重新赋值限制只有两位小数
  242. const cur_m_input = $(`.pay-input[data-type=${reverse(type)}]`)
  243. cur_amount = isLimitMax ? re_amount : ZhCalc.round(ZhCalc.mul(advancePayTotal, ZhCalc.div(val, 100), 10), decimal)
  244. pay_ratio = val
  245. cur_m_input.val(cur_amount)
  246. const total = ZhCalc.add(cur_amount, p_amount).toString().split('.')[1] || ''
  247. // 截止本期金额文案更新
  248. $('#p_total2').text(formatMoney(ZhCalc.add(cur_amount, p_amount), ',', isLimitMax ? total.length : 2) + '元')
  249. }
  250. const data = {
  251. pay_ratio,
  252. cur_amount,
  253. }
  254. oldVal = {
  255. cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
  256. remark: filterText($('#ad-remark').val())
  257. }
  258. clearTimeout(timer)
  259. timer = setTimeout(() => {
  260. if (checkInput()) {
  261. update(data)
  262. clearTimeout(timer)
  263. }
  264. }, 500);
  265. })
  266. function checkInput() {
  267. const newVal = {
  268. cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
  269. remark: filterText($('#ad-remark').val())
  270. }
  271. return newVal.cur_amount === oldVal.cur_amount && newVal.remark === oldVal.remark
  272. }
  273. $('#ad-remark').on('change', function(e) {
  274. const remark = filterText(e.target.value);
  275. oldVal = {
  276. pay_ratio: parseFloat($(`.pay-input[data-type=${0}]`).val()),
  277. cur_amount: parseFloat($(`.pay-input[data-type=${1}]`).val()),
  278. remark
  279. }
  280. const data = oldVal
  281. clearTimeout(timer)
  282. timer = setTimeout(() => {
  283. if (checkInput()) {
  284. update(data)
  285. clearTimeout(timer)
  286. }
  287. }, 500);
  288. })
  289. function filterText(text) {
  290. if (!text) return null
  291. return text.replace(/(\r\n)|(\n)/g, '<br/>').replace(/\s/g, ' ')
  292. }
  293. function update(data) {
  294. postData(preUrl + '/update', data)
  295. }
  296. // $('#file-modal-target').click(function () {
  297. // $('#file-modal').trigger('click')
  298. // })
  299. $('#file-ok').click(function () {
  300. const files = Array.from($('#file-modal')[0].files)
  301. const valiData = files.map(v => {
  302. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  303. return {
  304. size: v.size,
  305. ext
  306. }
  307. })
  308. if (validateFiles(valiData)) {
  309. if (files.length) {
  310. const formData = new FormData()
  311. files.forEach(file => {
  312. formData.append('name', file.name)
  313. formData.append('size', file.size)
  314. formData.append('file', file)
  315. })
  316. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  317. handleFileList(result)
  318. $('#file-cancel').click()
  319. });
  320. }
  321. }
  322. })
  323. function handleFileList(files = []) {
  324. $('#file-content').empty()
  325. // const { uncheck, checkNo } = auditConst.status
  326. const newFiles = files.map(file => {
  327. let showDel = false;
  328. if (file.uid === cur_uid) {
  329. // if (!curAuditor) {
  330. // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
  331. // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
  332. // } else {
  333. // curAuditor.audit_id === cur_uid && (showDel = true)
  334. // }
  335. if (advance.status === auditConst.status.checked) {
  336. showDel = Boolean(file.extra_upload )
  337. } else {
  338. showDel = true
  339. }
  340. }
  341. return {...file, showDel}
  342. })
  343. let html = advance.filePermission ? `<tr><td colspan="3"><a href="#addfujian" data-toggle="modal" class="btn btn-sm btn-light text-primary" data-placement="bottom" title="" data-original-title="添加清单"><i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传附件</a></td></tr>` : '';
  344. newFiles.forEach((file, idx) => {
  345. if (file.showDel) {
  346. html += `<tr><td width="70">${idx + 1}</td><td><a href="/${file.filepath}" target="_blank">${file.filename}</a></td><td width="90"><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}">移除</a></td></tr>`
  347. } else {
  348. html += `<tr><td width="70">${idx + 1}</td><td><a href="/${file.filepath}" target="_blank">${file.filename}</a></td><td width="90"></td></tr>`
  349. }
  350. })
  351. $('#file-content').append(html)
  352. }
  353. $('#file-content').on('click', 'a', function () {
  354. if ($(this).hasClass('file-del')) {
  355. const id = $(this).data('id')
  356. postData(preUrl + '/file/del', {id}, (result) => {
  357. handleFileList(result)
  358. })
  359. }
  360. })
  361. })
  362. /**
  363. * 校验文件大小、格式
  364. * @param {Array} files 文件数组
  365. */
  366. function validateFiles(files) {
  367. if (files.length > 10) {
  368. toastr.error('至多同时上传10个文件');
  369. return false
  370. }
  371. return files.every(file => {
  372. if (file.size > 1024 * 1024 * 30) {
  373. toastr.error('文件大小限制为30MB');
  374. return false
  375. }
  376. if (whiteList.indexOf('.' + file.ext) === -1) {
  377. toastr.error('请上传正确的格式文件');
  378. return false
  379. }
  380. return true
  381. })
  382. }
  383. function reverse(num){
  384. return 1^num
  385. }
  386. function formatMoney(s, dot = ',', decimal = 2) {
  387. if (!s) {
  388. s = 0;
  389. return s.toFixed(decimal);
  390. }
  391. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '';
  392. if (!decimal) {
  393. s += '.';
  394. }
  395. const l = s.split('.')[0].split('').reverse(),
  396. r = s.split('.')[1];
  397. let t = '';
  398. for (let i = 0; i < l.length; i++) {
  399. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? dot : '');
  400. }
  401. return t.split('').reverse().join('') + (decimal === 0 ? '' : '.' + r);
  402. }