advance.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.checkAgain) {
  152. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  153. <i class="fa fa-check"></i>
  154. </div>`
  155. } else if(auditor.status === auditConst.status.checking) {
  156. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  157. <i class="fa fa-ellipsis-h"></i>
  158. </div>`
  159. } else {
  160. historyHTML += `<div class="timeline-item-icon bg-secondary text-light"></div>`
  161. }
  162. historyHTML += `<div class="timeline-item-content">
  163. <div class="card">
  164. <div class="card-body p-3">
  165. <div class="card-text">
  166. <p class="mb-1"><span class="h5">${auditor.name}</span><span
  167. class="pull-right ${auditConst.statusClass[auditor.status]}">${auditConst.statusString[auditor.status]}</span>
  168. </p>
  169. <p class="text-muted mb-0">${auditor.role}</p>
  170. </div>
  171. </div>`
  172. if (auditor.opinion) {
  173. historyHTML += `<div class="card-body p-3 border-top">
  174. <p style="margin: 0;">${auditor.opinion}</p>
  175. </div>`
  176. }
  177. historyHTML += `</div></div></li>`
  178. } else {
  179. historyHTML += `<li class="timeline-list-item pb-2">
  180. <div class="timeline-item-date">
  181. ${formatDate(auditor.end_time)}
  182. </div>`
  183. if(index < auditors.length - 1) {
  184. historyHTML += `<div class="timeline-item-tail"></div>`
  185. }
  186. if(auditor.status === auditConst.status.checked) {
  187. historyHTML += `<div class="timeline-item-icon bg-success text-light">
  188. <i class="fa fa-check"></i>
  189. </div>`
  190. } else if(auditor.status === auditConst.status.checkNo || auditor.status === auditConst.status.checkNoPre) {
  191. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  192. <i class="fa fa-level-up"></i>
  193. </div>`
  194. } else if(auditor.status === auditConst.status.checkAgain) {
  195. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  196. <i class="fa fa-check"></i>
  197. </div>`
  198. } else if(auditor.status === auditConst.status.checking) {
  199. historyHTML += `<div class="timeline-item-icon bg-warning text-light">
  200. <i class="fa fa-ellipsis-h"></i>
  201. </div>`
  202. } else {
  203. historyHTML += `<div class="timeline-item-icon bg-secondary text-light"></div>`
  204. }
  205. historyHTML += `<div class="timeline-item-content">
  206. <div class="card">
  207. <div class="card-body p-3">
  208. <div class="card-text">
  209. <p class="mb-1"><span class="h5">${auditor.name}</span>
  210. <span
  211. class="pull-right
  212. ${auditConst.statusClass[auditor.status]}">${auditor.status !== auditConst.status.uncheck ? auditConst.statusString[auditor.status] : ''}
  213. ${auditor.status === auditConst.status.checkNo ? user.name : ''}
  214. ${auditor.status === auditConst.status.checkNoPre ? auditors[index-1].name : ''}
  215. </span>
  216. </p>
  217. <p class="text-muted mb-0">${auditor.role}</p>
  218. </div>
  219. </div>`
  220. if (auditor.opinion) {
  221. historyHTML += `<div class="card-body p-3 border-top">
  222. <p style="margin: 0;">${auditor.opinion} </p>
  223. </div>`
  224. }
  225. historyHTML += `</div></div></li>`
  226. }
  227. })
  228. historyHTML += '</ul></div>'
  229. })
  230. $('#audit-list').empty()
  231. $('#audit-list').append(historyHTML)
  232. })
  233. })
  234. $('a[data-target="#del-qi"').on('click', function () {
  235. const id = $(this).data('id')
  236. const order = $(this).data('order') //期数
  237. $('#del-qi').find('.modal-body').children()[0].innerText = `确认删除「第${order}期」?`
  238. $('#del-qi #del-confirm').click(function() {
  239. postData(`${window.location.pathname}/delete`, {id}, (res) => {
  240. console.log(res);
  241. window.location.reload()
  242. })
  243. })
  244. })
  245. function formatMoney(s, dot = ',', decimal = 2) {
  246. if (!s) {
  247. s = 0;
  248. return s.toFixed(decimal);
  249. }
  250. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '';
  251. if (!decimal) {
  252. s += '.';
  253. }
  254. const l = s.split('.')[0].split('').reverse(),
  255. r = s.split('.')[1];
  256. let t = '';
  257. for (let i = 0; i < l.length; i++) {
  258. t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? dot : '');
  259. }
  260. const num = t.split('').reverse().join('') + (decimal === 0 ? '' : '.' + r);
  261. return num.replace('-,', '-');
  262. }
  263. function transFormToChinese(num) {
  264. const changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  265. const unit = ['', '十', '百', '千', '万'];
  266. num = parseInt(num);
  267. const getWan = temp => {
  268. const strArr = temp.toString().split('').reverse();
  269. let newNum = '';
  270. for (let i = 0; i < strArr.length; i++) {
  271. 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;
  272. }
  273. return strArr.length === 2 && newNum.indexOf('一十') !== -1 ? newNum.replace('一十', '十') : newNum;
  274. };
  275. const overWan = Math.floor(num / 10000);
  276. let noWan = num % 10000;
  277. if (noWan.toString().length < 4) noWan = '0' + noWan;
  278. return overWan ? getWan(overWan) + '万' + getWan(noWan) : getWan(num);
  279. }
  280. function formatDate(date) {
  281. if (!date) return '';
  282. date = new Date(date)
  283. const year = date.getFullYear();
  284. let mon = date.getMonth() + 1;
  285. let day = date.getDate();
  286. let hour = date.getHours();
  287. let minute = date.getMinutes();
  288. let scond = date.getSeconds();
  289. if (mon < 10) {
  290. mon = '0' + mon.toString();
  291. }
  292. if (day < 10) {
  293. day = '0' + day.toString();
  294. }
  295. if (hour < 10) {
  296. hour = '0' + hour.toString();
  297. }
  298. if (minute < 10) {
  299. minute = '0' + minute.toString();
  300. }
  301. if (scond < 10) {
  302. scond = '0' + scond.toString();
  303. }
  304. return `${year}<span>${mon}-${day}</span><span>${hour}:${minute}:${scond}</span>`;
  305. }
  306. })