advance.js 14 KB

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