advance.js 15 KB

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