advance.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author lanjianrong
  6. * @date 2020/8/12
  7. * @version
  8. */
  9. $(document).ready(function () {
  10. $('#advance_add').click(function() {
  11. postData(`${window.location.pathname}/${type}/create`, {}, res => {
  12. const html = `<tr>
  13. <td><a href="/tender/${res.tid}/advance/${res.id}/detail" data-id="${res.id}">第${res.order}期</a></td>
  14. <td>${res.pay_ratio || 0}%</td>
  15. <td class="text-right">${formatMoney((res.cur_amount || 0), ',', decimal)}</td>
  16. <td class="text-right">${formatMoney((res.prev_amount || 0), ',', decimal)}</td>
  17. <td class="text-right">${formatMoney((res.prev_total_amount || 0),',', decimal)}</td>
  18. <td><a class="btn btn-sm" href="#file" data-toggle="modal" data-target="#file"><i class="fa fa-paperclip "></i> 3</a></td>
  19. <td>${auditConst.statusString[res.status]}</td>
  20. <td><a href="/tender/${res.tid}/advance/${res.id}/detail" class="btn btn-primary btn-sm">编辑</a></td>
  21. </tr>`
  22. $('#advanceList').prepend(html)
  23. $('#advance_add').remove()
  24. window.location.href = `${window.location.pathname}/${res.id}/detail`
  25. })
  26. return false
  27. })
  28. $('#advanceList').on('click', `a[href="#file"]`, function() {
  29. const { fileList = [] } = advanceList.find(item => item.id === parseInt($(this).data('id')))
  30. $('#file-content').empty()
  31. let html = `<thead>
  32. <tr>
  33. <th width="70%">文件名</th>
  34. <th width="20%">上传时间</th>
  35. <th width="10%">操作</th>
  36. </tr>
  37. </thead>`
  38. fileList.forEach(file => {
  39. html+= `<tr>
  40. <td>${file.filename}</td>
  41. <td>${new Date(file.create_time).toLocaleDateString()}</td>
  42. <td>
  43. <a href="/${file.filepath}" target="_blank" title="下载"><i class="fa fa-download"></i></a>
  44. </td>
  45. </tr>`
  46. })
  47. $('#file-content').append(html)
  48. })
  49. $('a[data-target="#sp-list" ]').on('click', function () {
  50. const id = $(this).data('vid')
  51. postData(`${window.location.pathname.replace('/material', '')}/${id}/auditors`, {}, (res) => {
  52. const { auditHistory, auditors, user } = res
  53. let auditorsHTML = ''
  54. let historyHTML = ''
  55. auditors.forEach((auditor, idx) => {
  56. if (idx === 0) {
  57. auditorsHTML += `<li class="list-group-item">
  58. <i class="fa fa fa-play-circle fa-rotate-90"></i> ${auditor.name}
  59. <small class="text-muted">${auditor.role}</small>
  60. <span class="pull-right">原报</span>
  61. </li>`
  62. } else if(idx === auditors.length -1 && idx !== 0) {
  63. auditorsHTML += `<li class="list-group-item">
  64. <i class="fa fa fa-stop-circle"></i> ${auditor.name}
  65. <small class="text-muted">${auditor.role}</small>
  66. <span class="pull-right">终审</span>
  67. </li>`
  68. } else {
  69. auditorsHTML += `<li class="list-group-item">
  70. <i class="fa fa-chevron-circle-down"></i> ${auditor.name}
  71. <small class="text-muted">${auditor.role}</small>
  72. <span class="pull-right">${transFormToChinese(idx)}审</span>
  73. </li>`
  74. }
  75. })
  76. $('#auditor-list').empty()
  77. $('#auditor-list').append(auditorsHTML)
  78. auditHistory.forEach((auditors, idx) => {
  79. historyHTML += `<div class="${idx < auditHistory.length - 1 ? 'fold-card' : ''}">
  80. <div class="text-center text-muted"
  81. ${idx === auditHistory.length - 1 ? 'id="end-target"' : ""}>
  82. ${idx === auditHistory.length - 1 ? 1 : idx+1}#</div>
  83. <ul class="timeline-list list-unstyled mt-2">`
  84. auditors.forEach((auditor, index) => {
  85. if (index === 0) {
  86. historyHTML += `<li class="timeline-list-item pb-2">
  87. <div class="timeline-item-date">
  88. ${formatDate(auditor.create_time)}
  89. </div>
  90. <div class="timeline-item-tail"></div>
  91. <div class="timeline-item-icon bg-success text-light">
  92. <i class="fa fa-caret-down"></i>
  93. </div>
  94. <div class="timeline-item-content">
  95. <div class="card">
  96. <div class="card-body p-3">
  97. <div class="card-text">
  98. <p class="mb-1"><span
  99. class="h5">${user.name}</span><span
  100. class="pull-right text-success">${idx !== 0 ? '重新' : ''}上报审批</span>
  101. </p>
  102. <p class="text-muted mb-0">${user.role}</p>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </li>
  108. <li class="timeline-list-item pb-2">
  109. <div class="timeline-item-date">
  110. ${formatDate(auditor.end_time)}
  111. </div>`
  112. if(index < auditors.length - 1) {
  113. historyHTML += `<div class="timeline-item-tail"></div>`
  114. }
  115. if(auditor.status === auditConst.status.checked) {
  116. historyHTML += `<div class="timeline-item-icon bg-success text-light">
  117. <i class="fa fa-check"></i>
  118. </div>`
  119. } else if(auditor.status === auditConst.status.checkNo || auditor.status === auditConst.status.checkNoPre) {
  120. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  121. <i class="fa fa-level-up"></i>
  122. </div>`
  123. } else if(auditor.status === auditConst.status.checking) {
  124. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  125. <i class="fa fa-ellipsis-h"></i>
  126. </div>`
  127. } else {
  128. historyHTML += `<div class="timeline-item-icon bg-secondary text-light"></div>`
  129. }
  130. historyHTML += `<div class="timeline-item-content">
  131. <div class="card">
  132. <div class="card-body p-3">
  133. <div class="card-text">
  134. <p class="mb-1"><span class="h5">${auditor.name}</span><span
  135. class="pull-right ${auditConst.statusClass[auditor.status]}">${auditConst.statusString[auditor.status]}</span>
  136. </p>
  137. <p class="text-muted mb-0">${auditor.role}</p>
  138. </div>
  139. </div>`
  140. if (auditor.opinion) {
  141. historyHTML += `<div class="card-body p-3 border-top">
  142. <p style="margin: 0;">${auditor.opinion}</p>
  143. </div>`
  144. }
  145. historyHTML += `</div></div></li>`
  146. } else {
  147. historyHTML += `<li class="timeline-list-item pb-2">
  148. <div class="timeline-item-date">
  149. ${formatDate(auditor.end_time)}
  150. </div>`
  151. if(index < auditors.length - 1) {
  152. historyHTML += `<div class="timeline-item-tail"></div>`
  153. }
  154. if(auditor.status === auditConst.status.checked) {
  155. historyHTML += `<div class="timeline-item-icon bg-success text-light">
  156. <i class="fa fa-check"></i>
  157. </div>`
  158. } else if(auditor.status === auditConst.status.checkNo || auditor.status === auditConst.status.checkNoPre) {
  159. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  160. <i class="fa fa-level-up"></i>
  161. </div>`
  162. } else if(auditor.status === auditConst.status.checking) {
  163. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  164. <i class="fa fa-ellipsis-h"></i>
  165. </div>`
  166. } else {
  167. historyHTML += `<div class="timeline-item-icon bg-secondary text-light"></div>`
  168. }
  169. historyHTML += `<div class="timeline-item-content">
  170. <div class="card">
  171. <div class="card-body p-3">
  172. <div class="card-text">
  173. <p class="mb-1"><span class="h5">${auditor.name}</span>
  174. <span
  175. class="pull-right
  176. ${auditConst.statusClass[auditor.status]}">${auditor.status !== auditConst.status.uncheck ? auditConst.statusString[auditor.status] : ''}
  177. ${auditor.status === auditConst.status.checkNo ? user.name : ''}
  178. ${auditor.status === auditConst.status.checkNoPre ? auditors[index-1].name : ''}
  179. </span>
  180. </p>
  181. <p class="text-muted mb-0">${auditor.role}</p>
  182. </div>
  183. </div>`
  184. if (auditor.opinion) {
  185. historyHTML += `<div class="card-body p-3 border-top">
  186. <p style="margin: 0;">${auditor.opinion} </p>
  187. </div>`
  188. }
  189. historyHTML += `</div></div></li>`
  190. }
  191. })
  192. historyHTML += '</ul></div>'
  193. if(idx === auditHistory.length - 1 && auditHistory.length !== 1) {
  194. historyHTML += `<div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show"
  195. data-idx="${idx + 1}">展开历史审批流程</a></div>`
  196. }
  197. })
  198. $('#audit-list').empty()
  199. $('#audit-list').append(historyHTML)
  200. })
  201. })
  202. function formatMoney(s, dot = ',', decimal = 2) {
  203. if (!s) {
  204. s = 0;
  205. return s.toFixed(decimal);
  206. }
  207. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '';
  208. if (!decimal) {
  209. s += '.';
  210. }
  211. const l = s.split('.')[0].split('').reverse(),
  212. r = s.split('.')[1];
  213. let t = '';
  214. for (let i = 0; i < l.length; i++) {
  215. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? dot : '');
  216. }
  217. return t.split('').reverse().join('') + (decimal === 0 ? '' : '.' + r);
  218. }
  219. function transFormToChinese(num) {
  220. const changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  221. const unit = ['', '十', '百', '千', '万'];
  222. num = parseInt(num);
  223. const getWan = temp => {
  224. const strArr = temp.toString().split('').reverse();
  225. let newNum = '';
  226. for (let i = 0; i < strArr.length; i++) {
  227. newNum = (i == 0 && strArr[i] == 0 ? '' : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? '' : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
  228. }
  229. return strArr.length === 2 && newNum.indexOf('一十') !== -1 ? newNum.replace('一十', '十') : newNum;
  230. };
  231. const overWan = Math.floor(num / 10000);
  232. let noWan = num % 10000;
  233. if (noWan.toString().length < 4) noWan = '0' + noWan;
  234. return overWan ? getWan(overWan) + '万' + getWan(noWan) : getWan(num);
  235. }
  236. function formatDate(date) {
  237. if (!date) return '';
  238. date = new Date(date)
  239. const year = date.getFullYear();
  240. let mon = date.getMonth() + 1;
  241. let day = date.getDate();
  242. let hour = date.getHours();
  243. let minute = date.getMinutes();
  244. let scond = date.getSeconds();
  245. if (mon < 10) {
  246. mon = '0' + mon.toString();
  247. }
  248. if (day < 10) {
  249. day = '0' + day.toString();
  250. }
  251. if (hour < 10) {
  252. hour = '0' + hour.toString();
  253. }
  254. if (minute < 10) {
  255. minute = '0' + minute.toString();
  256. }
  257. if (scond < 10) {
  258. scond = '0' + scond.toString();
  259. }
  260. return `${year}<span>${mon}-${day}</span><span>${hour}:${minute}:${scond}</span>`;
  261. }
  262. })