modal.ejs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. <!--删除标段-->
  2. <div class="modal fade" id="del-bg" data-backdrop="static">
  3. <div class="modal-dialog" role="document">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <h5 class="modal-title">确认删除变更</h5>
  7. </div>
  8. <div class="modal-body">
  9. <h5>删除后,数据无法恢复,请谨慎操作。</h5>
  10. </div>
  11. <form class="modal-footer" action="/tender/<%- tender.id %>/change/delete" method="post">
  12. <input type="hidden" name="cid" id="delete-cid" value="">
  13. <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
  14. <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">取消</button>
  15. <button type="submit" class="btn btn-danger btn-sm">确定删除</button>
  16. </form>
  17. </div>
  18. </div>
  19. </div>
  20. <!--审批流程/结果-->
  21. <div class="modal fade" id="sp-list" data-backdrop="static">
  22. <div class="modal-dialog modal-lg" role="document">
  23. <div class="modal-content">
  24. <div class="modal-header">
  25. <h5 class="modal-title">审批流程</h5>
  26. </div>
  27. <div class="modal-body">
  28. <div class="row">
  29. <div class="col-4 modal-height-500" style="overflow: auto">
  30. <div class="card mt-3">
  31. <ul class="list-group list-group-flush" id="auditor-list">
  32. </ul>
  33. </div>
  34. </div>
  35. <div class="col-8 modal-height-500" style="overflow: auto" id="audit-list">
  36. </div>
  37. </div>
  38. </div>
  39. <div class="modal-footer">
  40. <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <% if (tender.user_id === ctx.session.sessionUser.accountId) { %>
  46. <!--弹出添加变更令-->
  47. <div class="modal fade" id="add-bj-modal" data-backdrop="static">
  48. <div class="modal-dialog" role="document">
  49. <div class="modal-content">
  50. <div class="modal-header">
  51. <h5 class="modal-title">新建变更令</h5>
  52. </div>
  53. <div class="modal-body">
  54. <div class="form-group">
  55. <label>申请编号<b class="text-danger">*</b></label>
  56. <div class="input-group">
  57. <input type="text" class="form-control form-control-sm is-invalid" placeholder="请输入变更令号" value="变更申请编号" id="bj-code">
  58. <div class="input-group-append" id="autoCodeShow" <% if (codeRule.length === 0) { %>style="display: none"<% } %>>
  59. <button class="btn btn-sm btn-outline-secondary" type="button" title="自动编号" id="autoCode"><i class="fa fa-repeat"></i></button>
  60. </div>
  61. <div class="invalid-feedback" style="display: none" id="bjHint">您输入的编号已存在。</div>
  62. </div>
  63. </div>
  64. <% if (ctx.session.sessionProject.page_show.openChangePlan) { %>
  65. <div class="form-group">
  66. <label>关联变更方案</label>
  67. <select class="form-control form-control-sm" id="plan-code">
  68. <option></option>
  69. <% for (const cp of changePlanList) { %>
  70. <% if (ctx.helper._.indexOf(apLists, cp.code) === -1) { %>
  71. <option><%- cp.code %></option>
  72. <% } %>
  73. <% } %>
  74. </select>
  75. </div>
  76. <input value="" type="hidden" id="bj-name">
  77. <% } else { %>
  78. <div class="form-group">
  79. <label>变更工程名称<b class="text-danger">*</b></label>
  80. <input class="form-control form-control-sm" value="" type="text" id="bj-name">
  81. <div class="invalid-feedback" style="display: none" id="name_error_msg">名称超过100个字,请缩减名称。</div>
  82. </div>
  83. <input type="hidden" value="" id="plan-code">
  84. <% } %>
  85. </div>
  86. <div class="modal-footer">
  87. <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal" id="addCancel">关闭</button>
  88. <a href="javascript: void(0)" class="btn btn-primary btn-sm" id="addOk">确认新建</a>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <!--设置-->
  94. <div class="modal fade" id="setting" data-backdrop="static">
  95. <div class="modal-dialog" role="document">
  96. <div class="modal-content">
  97. <div class="modal-header">
  98. <h5 class="modal-title">变更令设置</h5>
  99. </div>
  100. <div class="modal-body">
  101. <ul class="nav nav-tabs mb-3" role="tablist">
  102. <li class="nav-item">
  103. <a class="nav-link active" data-toggle="tab" href="#bianhao" role="tab" aria-controls="home" aria-selected="true">编号规则</a>
  104. </li>
  105. </ul>
  106. <div class="tab-content">
  107. <div class="tab-pane active" id="bianhao">
  108. <h5>
  109. 当前规则:
  110. <span id="preview">
  111. <% if (codeRule && codeRule instanceof Array) { %>
  112. <% const preview = []; %>
  113. <% for (const rule of codeRule) { %>
  114. <% preview.push(rule.preview); %>
  115. <% } %>
  116. <%- preview.join(tender.c_connector !== null && tender.c_connector !== '3' ? ruleConst.connectorString[tender.c_connector] : ''); %>
  117. <% } %>
  118. </span>
  119. </h5>
  120. <h5 id="ruleParts">
  121. <% if (codeRule && codeRule instanceof Array) { %>
  122. <% for (const rule of codeRule) { %>
  123. <span class="badge badge-light" title="<%- ruleConst.ruleString[rule.rule_type] %>">
  124. <span>
  125. <%- rule.preview %>
  126. </span>
  127. <a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>
  128. </span>
  129. <% } %>
  130. <% } %>
  131. </h5>
  132. <h5 class="my-3">连接符</h5>
  133. <div class="form-group">
  134. <select class="form-control form-control-sm connector-change">
  135. <option disabled selected>请选择</option>
  136. <% for (const index in ruleConst.connectorString) { %>
  137. <option value="<%- index %>" <% if (tender.c_connector !== null && tender.c_connector === parseInt(index)) { %>selected<% } %>><%- ruleConst.connectorString[index] %></option>
  138. <% } %>
  139. </select>
  140. </div>
  141. <h5 class="my-3">添加新规则组件</h5>
  142. <div class="form-group">
  143. <select class="form-control form-control-sm rule-change">
  144. <option disabled selected>请选择组件</option>
  145. <% for (const index in ruleConst.ruleString) { %>
  146. <option value="<%- index %>"><%- ruleConst.ruleString[index] %></option>
  147. <% } %>
  148. </select>
  149. </div>
  150. <div class="form-group" id="format" style="display: none">
  151. <label>自动编号位数</label>
  152. <input min="3" class="form-control form-control-sm" step="1" max="6" value="3" type="number">
  153. </div>
  154. <div class="form-group" id="text" style="display: none">
  155. <label>起始编号</label>
  156. <input class="form-control form-control-sm" value="001" type="text">
  157. </div>
  158. <button class="btn btn-sm btn-outline-primary" id="addRule">添加组件</button>
  159. </div>
  160. </div>
  161. </div>
  162. <div class="modal-footer">
  163. <% if (tender.c_rule_first) { %><button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal" id="changeFirst">暂时不需要</button><% } %>
  164. <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal" id="hide_modal" <% if (tender.c_rule_first) { %>style="display: none"<% } %>>关闭</button>
  165. <button type="button" class="btn btn-primary btn-sm" id="setRule">确定添加</button>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <!--批量上报变更令-->
  171. <div class="modal fade" id="batch-sb" data-backdrop="static" style="">
  172. <div class="modal-dialog modal-lg" style="max-width:1100px;" role="document">
  173. <div class="modal-content">
  174. <div class="modal-header">
  175. <h5 class="modal-title">批量上报变更令</h5>
  176. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  177. <span aria-hidden="true">&times;</span>
  178. </button>
  179. </div>
  180. <div class="modal-body">
  181. <div class="row">
  182. <!-- 左侧变更令 -->
  183. <div class="col-6" >
  184. <div class="modal-height-500" style="overflow-y:auto;">
  185. <table class="table table-hover table-bordered">
  186. <thead>
  187. <tr>
  188. <th width="15%" class="text-center"><div class="align-middle"><input id="select-all-uncheck" type="checkbox"></div></th>
  189. <th width="40%">变更令编号</th>
  190. <th width="">原审批流程</th>
  191. </tr>
  192. </thead>
  193. <tbody id="uncheck_list">
  194. </tbody>
  195. </table>
  196. </div>
  197. </div>
  198. <!-- 右侧新审批流程 -->
  199. <div class="col-6">
  200. <div class=" ml-auto">
  201. <div class="dropdown text-right" id="show-audit-select">
  202. </div>
  203. <div class="card mt-1">
  204. <div class="card-header">
  205. 审批流程
  206. </div>
  207. <div class="modal-height-500" style="overflow-y:auto;">
  208. <ul class="list-group list-group-flush" id="auditList">
  209. </ul>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. <div class="alert alert-warning mt-2 mb-0">批量操作会覆盖原审批流程,请合理选择。</div>
  216. </div>
  217. <div class="modal-footer">
  218. <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
  219. <button class="btn btn-sm btn-primary" id="batch_uncheck_btn">确定</button>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <!--批量上报变更令进度条modal-->
  225. <div class="modal fade" id="batch-sb-progress" data-backdrop="static" style="">
  226. <div class="modal-dialog" role="document">
  227. <div class="modal-content">
  228. <div class="modal-header">
  229. <h5 class="modal-title">批量上报变更令</h5>
  230. </div>
  231. <div class="modal-body">
  232. <div class="progress">
  233. <div class="progress-tz-bar progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
  234. </div>
  235. <div class="mt-1 progress-tz-text">台账获取并处理中...</div>
  236. <div class="change-progress">
  237. </div>
  238. </div>
  239. <div class="modal-footer" style="display: none">
  240. <button class="btn btn-sm btn-primary" onclick="window.location.reload();">刷新页面</button>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. <% } %>
  246. <!--批量审批变更令-->
  247. <div class="modal fade" id="batch-sp" data-backdrop="static" style="">
  248. <div class="modal-dialog modal-lg" role="document">
  249. <div class="modal-content">
  250. <div class="modal-header">
  251. <h5 class="modal-title">批量审批变更令</h5>
  252. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  253. <span aria-hidden="true">&times;</span>
  254. </button>
  255. </div>
  256. <div class="modal-body">
  257. <div class="modal-height-500" style="overflow-y:auto;">
  258. <table class="table table-hover table-bordered">
  259. <thead>
  260. <tr>
  261. <th width="5%"><div class="align-middle text-center"><input type="checkbox" id="select-all-checking"></div></th>
  262. <th width="25%">变更令编号</th>
  263. <th width="">变更令名称</th>
  264. <th width="25%">批量编号</th>
  265. </tr>
  266. </thead>
  267. <tbody id="checking_list">
  268. </tbody>
  269. </table>
  270. </div>
  271. </div>
  272. <div class="modal-footer">
  273. <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
  274. <button type="button" class="btn btn-sm btn-primary" id="batch_checking_btn">确定</button>
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. <!--批量审批变更令进度条modal-->
  280. <div class="modal fade" id="batch-sp-progress" data-backdrop="static" style="">
  281. <div class="modal-dialog" role="document">
  282. <div class="modal-content">
  283. <div class="modal-header">
  284. <h5 class="modal-title">批量审批变更令</h5>
  285. </div>
  286. <div class="modal-body">
  287. <div class="progress">
  288. <div class="progress-tz-bar progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
  289. </div>
  290. <div class="mt-1 progress-tz-text">台账获取并处理中...</div>
  291. <div class="change-progress">
  292. </div>
  293. </div>
  294. <div class="modal-footer" style="display: none">
  295. <button class="btn btn-sm btn-primary" onclick="window.location.reload();">刷新页面</button>
  296. </div>
  297. </div>
  298. </div>
  299. </div>
  300. <script>
  301. const ruleType = <%- ruleType %>;
  302. const ruleConst = JSON.parse('<%- JSON.stringify(ruleConst) %>');
  303. let codeRule = JSON.parse('<%- JSON.stringify(codeRule) %>');
  304. let connectorRule = '<%- tender.c_connector %>';
  305. let cRuleFirst = '<%- tender.c_rule_first %>';
  306. const tenderId = '<%- ctx.tender.id %>';
  307. const auditConst = JSON.parse(unescape('<%- escape(JSON.stringify(auditConst)) %>'));
  308. const auditType = JSON.parse('<%- JSON.stringify(auditType) %>');
  309. $('#audit-list').on('click', 'a', function() {
  310. const type = $(this).data('target')
  311. const auditCard = $(this).parent().parent()
  312. if (type === 'show') {
  313. $(this).data('target', 'hide')
  314. auditCard.find('.fold-card').slideDown('swing', () => {
  315. auditCard.find('#end-target').text($(this).data('idx') + '#')
  316. auditCard.find('#fold-btn').text('收起历史审核记录')
  317. })
  318. } else {
  319. $(this).data('target', 'show')
  320. auditCard.find('.fold-card').slideUp('swing', () => {
  321. auditCard.find('#end-target').text('1#')
  322. auditCard.find('#fold-btn').text('展开历史审核记录')
  323. })
  324. }
  325. });
  326. </script>
  327. <script src="/public/js/moment/moment.min.js"></script>
  328. <script src="/public/js/decimal.min.js"></script>
  329. <script src="/public/js/zh_calc.js"></script>
  330. <script src="/public/js/path_tree.js"></script>
  331. <script src="/public/js/gcl_gather.js"></script>
  332. <script>
  333. const shenpiConst = JSON.parse(unescape('<%- escape(JSON.stringify(shenpiConst)) %>'));
  334. const precision = JSON.parse('<%- JSON.stringify(precision) %>');
  335. $(function () {
  336. const intervalIds = {};
  337. <% if (tender.user_id === ctx.session.sessionUser.accountId) { %>
  338. let this_cid = null;
  339. let shenpi_status = shenpiConst.sp_status.sqspr;
  340. let accountList, accountGroup;
  341. let uncheckList = [];
  342. // 批量上报变更令部分
  343. $('#batch-sb').on('show.bs.modal', function () {
  344. postData(`/tender/${tenderId}/change/batch/fun`, { type: 'get_report_list' }, function (res) {
  345. let html = '';
  346. $('#select-all-uncheck').prop('checked', false);
  347. shenpi_status = res.shenpi_status;
  348. uncheckList = res.uncheckList;
  349. for (const l of res.uncheckList) {
  350. html += '<tr>' +
  351. `<td class="text-center"><input type="checkbox" value="${l.cid}"></td>` +
  352. `<td class=""><a href="/tender/${tenderId}/change/${l.cid}/information" target="_blank">${l.code}</a></td>` +
  353. '<td>' + setAuditList(l.auditList) +'</td>' +
  354. '</tr>';
  355. }
  356. $('#uncheck_list').html(html);
  357. if (res.uncheckList.length > 0) {
  358. $('#uncheck_list tr').eq(0).addClass('table-warning');
  359. this_cid = res.uncheckList[0].cid;
  360. makeSpList(res.uncheckList[0].auditList);
  361. } else {
  362. $('#uncheck_list tr').removeClass('table-warning');
  363. this_cid = null;
  364. makeSpList([]);
  365. }
  366. let showAuditSelectHtml = '';
  367. if (res.spGroupList && res.spGroupList.length > 0 && shenpi_status === shenpiConst.sp_status.gdspl) {
  368. let optionHtml = '';
  369. for (const g of res.spGroupList) { %>
  370. optionHtml += `<option value="${g.id}" ${res.uncheckList.length > 0 && g.id === res.uncheckList[0].sp_group ? 'selected' : ''}>${g.name}</option>`;
  371. }
  372. showAuditSelectHtml += '<div class="row">' +
  373. '<div class="col-7"></div>' +
  374. '<div class="col-5">' +
  375. '<select class="form-control form-control-sm change-sp-group">' + optionHtml + '</select>' +
  376. '</div></div>';
  377. } else {
  378. accountList = res.accountList;
  379. accountGroup = res.accountGroup;
  380. showAuditSelectHtml += getSelectAuditHtml('report');
  381. }
  382. $('#show-audit-select').html(showAuditSelectHtml);
  383. })
  384. });
  385. function setAuditList(auditList) {
  386. let html = [];
  387. // 去除原报
  388. if (auditList.length > 1) {
  389. for (const [i,a] of auditList.entries()) {
  390. if (i === 0) continue;
  391. const oneAuditNames = _.map(a, 'name');
  392. let names = oneAuditNames.join('、');
  393. if (oneAuditNames.length > 1) {
  394. names = (a[0].audit_type === auditType.key.and ? '(会)' : (a[0].audit_type === auditType.key.or ? '(或)' : '')) + names;
  395. }
  396. html.push(names);
  397. }
  398. }
  399. return html.join('-');
  400. }
  401. function getSelectAuditHtml(code) {
  402. let divhtml = '';
  403. accountGroup.forEach((group, idx) => {
  404. let didivhtml = '';
  405. if(group) {
  406. group.groupList.forEach(item => {
  407. didivhtml += '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  408. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  409. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  410. ' <span class="text-muted">' + item.role + '</span>\n' +
  411. ' </dd>\n';
  412. });
  413. divhtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="' + idx + '" data-type="hide"><i class="fa fa-plus-square"></i></a> ' + group.groupName + '</dt>\n' +
  414. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  415. ' </div>\n';
  416. }
  417. });
  418. const html =
  419. ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + code + '_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  420. ' 添加审批流程\n' +
  421. ' </button>\n' +
  422. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  423. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  424. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  425. ' <dl class="list-unstyled book-list">\n' + divhtml +
  426. ' </dl>\n' +
  427. ' </div>\n';
  428. return html;
  429. }
  430. // uncheckList tr 切换
  431. $('#uncheck_list').on('click', 'tr', function () {
  432. $('#uncheck_list tr').removeClass('table-warning');
  433. $(this).addClass('table-warning');
  434. this_cid = $(this).find('a').attr('href').split('/')[4];
  435. makeSpList(uncheckList.find(l => l.cid === this_cid).auditList);
  436. });
  437. $('#uncheck_list').on('click', 'input[type="checkbox"]', function (e) {
  438. e.stopPropagation();
  439. });
  440. // uncheckList tr全选
  441. $('#select-all-uncheck').click(function () {
  442. $('#uncheck_list tr').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
  443. });
  444. let timer = null;
  445. let oldSearchVal = null;
  446. $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
  447. oldSearchVal = e.target.value;
  448. timer && clearTimeout(timer);
  449. timer = setTimeout(() => {
  450. const newVal = $(this).val();
  451. const code = $(this).attr('data-code');
  452. let html = '';
  453. if (newVal && newVal === oldSearchVal) {
  454. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  455. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  456. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  457. class="ml-auto">${item.mobile || ''}</span></p>
  458. <span class="text-muted">${item.role || ''}</span>
  459. </dd>`;
  460. });
  461. $('#' + code + '_dropdownMenu .book-list').empty();
  462. $('#' + code + '_dropdownMenu .book-list').append(html);
  463. } else {
  464. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  465. accountGroup.forEach((group, idx) => {
  466. if (!group) return;
  467. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  468. </a> ${group.groupName}</dt>
  469. <div class="dd-content" data-toggleid="${idx}">`;
  470. group.groupList.forEach(item => {
  471. // if (item.id !== changesUid) {
  472. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  473. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  474. class="ml-auto">${item.mobile || ''}</span></p>
  475. <span class="text-muted">${item.role || ''}</span>
  476. </dd>`;
  477. // }
  478. });
  479. html += '</div>';
  480. });
  481. $('#' + code + '_dropdownMenu .book-list').empty();
  482. $('#' + code + '_dropdownMenu .book-list').append(html);
  483. }
  484. }
  485. }, 400);
  486. });
  487. // 添加审批流程按钮逻辑
  488. $('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
  489. const idx = $(this).find('.acc-btn').attr('data-groupid');
  490. const type = $(this).find('.acc-btn').attr('data-type');
  491. if (type === 'hide') {
  492. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  493. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  494. $(this).find('.acc-btn').attr('data-type', 'show');
  495. })
  496. } else {
  497. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  498. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  499. $(this).find('.acc-btn').attr('data-type', 'hide');
  500. })
  501. }
  502. return false;
  503. });
  504. // 添加到审批流程中
  505. $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
  506. const id = parseInt($(this).data('id'));
  507. if (!this_cid) {
  508. toastr.error('请选择变更令');
  509. return false;
  510. }
  511. if (id !== 0) {
  512. postData('/tender/' + tenderId + '/change/' + this_cid + '/information/audit/add', { auditorId: id }, (datas) => {
  513. makeSpList(datas);
  514. const index = uncheckList.findIndex(item => item.cid === this_cid);
  515. if (index !== -1) {
  516. uncheckList[index].auditList = datas;
  517. $('#uncheck_list tr').eq(index).children('td').eq(2).html(setAuditList(datas));
  518. }
  519. });
  520. }
  521. });
  522. // 移除审批流程的审批人
  523. $('body').on('click', '#auditList li a', function () {
  524. const uid = $(this).parents('li').attr('data-auditid');
  525. const li = $(this).parents('li');
  526. const data = {
  527. auditorId: uid,
  528. };
  529. if (!this_cid) {
  530. toastr.error('请选择变更令');
  531. return false;
  532. }
  533. postData('/tender/' + tenderId + '/change/' + this_cid + '/information/audit/delete', data, (datas) => {
  534. li.remove();
  535. let liIndex = 1;
  536. $('#auditList li').each(function () {
  537. $(this).children('.col-auto').eq(0).text(liIndex);
  538. liIndex++;
  539. });
  540. const index = uncheckList.findIndex(item => item.cid === this_cid);
  541. if (index !== -1) {
  542. uncheckList[index].auditList = datas;
  543. $('#uncheck_list tr').eq(index).children('td').eq(2).html(setAuditList(datas));
  544. }
  545. });
  546. });
  547. // 切换审批组
  548. $('body').on('change', '.change-sp-group', function () {
  549. const data = {
  550. type: 'change_sp_group',
  551. sp_group: parseInt($(this).val()),
  552. }
  553. if (!this_cid) {
  554. toastr.error('请选择变更令');
  555. return false;
  556. }
  557. if (!data.sp_group) {
  558. toastr.error('请选择固定审批组');
  559. return false;
  560. }
  561. console.log(data);
  562. postData('/tender/' + tenderId + '/change/' + this_cid + '/information/audit/spgroup', data, (datas) => {
  563. makeSpList(datas);
  564. const index = uncheckList.findIndex(item => item.cid === this_cid);
  565. if (index !== -1) {
  566. uncheckList[index].auditList = datas;
  567. $('#uncheck_list tr').eq(index).children('td').eq(2).html(setAuditList(datas));
  568. }
  569. });
  570. });
  571. function makeSpList(datas) {
  572. const html = [];
  573. // 如果是重新上报,添加到重新上报列表中
  574. const auditorshtml = [];
  575. if (datas.length > 0) {
  576. for (const [index,data] of datas.entries()) {
  577. if (index !== 0) {
  578. html.push('<li class="list-group-item d-flex" data-auditid="'+ data[0].uid +'">');
  579. html.push(`<div class="col-auto">${index}</div>`);
  580. html.push('<div class="col">');
  581. for (const auditor of data) {
  582. html.push(`<div class="d-inline-block mx-1" auditorId="${auditor.uid}"><i class="fa fa-user text-muted"></i> ${auditor.name} <small class="text-muted">${auditor.role}</small></div>`);
  583. }
  584. html.push('</div>');
  585. html.push('<div class="col-auto">');
  586. // todo 添加会签或签时
  587. if (data[0].audit_type !== auditType.key.common) {
  588. html.push(`<span class="badge badge-pill badge-${auditType.info[data[0].audit_type].class} badge-bg-small"><small>${auditType.info[data[0].audit_type].long}</small></span>`);
  589. }
  590. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  591. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  592. }
  593. html.push('</div>');
  594. html.push('</li>');
  595. }
  596. }
  597. }
  598. $('#auditList').html(html.join(''));
  599. }
  600. $('#batch_uncheck_btn').click(function () {
  601. // 至少勾选一个
  602. if ($('#uncheck_list input:checked').length === 0) {
  603. toastr.error('请至少勾选一个变更令');
  604. return false;
  605. }
  606. const cids = [];
  607. $('#uncheck_list input:checked').each(function () {
  608. cids.push($(this).val());
  609. });
  610. $('#batch-sb').modal('hide');
  611. $('#batch-sb-progress').modal('show');
  612. $('#batch-sb-progress .progress-tz-bar').css('width', '0%');
  613. $('#batch-sb-progress .modal-footer').hide();
  614. setProgress($('#batch-sb-progress .progress-tz-bar'), 30, 'tz1');
  615. $('#batch-sb-progress .progress-tz-text').text('台账数据获取中...').removeClass('text-success');
  616. let changeListData;
  617. let gclGatherData;
  618. postData('/tender/' + tenderId + '/change/defaultBills', { form: 'batch' }, async function (result) {
  619. gclGatherModel.loadLedgerData(result.bills);
  620. gclGatherModel.loadPosData(result.pos);
  621. gclGatherData = gclGatherModel.gatherGclData();
  622. gclGatherData = _.filter(gclGatherData, function (item) {
  623. return item.leafXmjs && item.leafXmjs.length !== 0;
  624. });
  625. for (const ggd in gclGatherData) {
  626. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  627. gclGatherData.splice(ggd, 1);
  628. }
  629. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  630. let hadcid = 0;
  631. for (const xmj of gclGatherData[ggd].leafXmjs) {
  632. const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
  633. const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  634. if (changeLedger || changePos) {
  635. xmj.cid = 1;
  636. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  637. hadcid = 1;
  638. }
  639. }
  640. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  641. }
  642. // console.log(gclGatherData);
  643. // 数组去重
  644. const dealBillList = result.dealBills;
  645. for (const db of gclGatherData) {
  646. const exist_index = dealBillList.findIndex(function (item) {
  647. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  648. });
  649. if (exist_index !== -1) {
  650. dealBillList.splice(exist_index, 1);
  651. }
  652. }
  653. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  654. console.log(changeListData);
  655. stopProgress($('#batch-sb-progress .progress-tz-bar'), 'tz1');
  656. $('#batch-sb-progress .progress-tz-text').text('台账数据加载完成').addClass('text-success');
  657. $('#batch-sb-progress .change-progress').html('');
  658. for (const c of cids) {
  659. const cInfo = uncheckList.find(item => item.cid === c);
  660. if (cInfo) {
  661. $('#batch-sb-progress .change-progress').append(`<div id="change-${cInfo.cid}-progress"><div class="mt-3 progress">` +
  662. '<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>' +
  663. '</div>' +
  664. `<div class="mt-1">变更令 <b>${cInfo.code}</b> <span class="progress-change-text">上报处理中...</span></div></div>`);
  665. await checkAndChange(cInfo, changeListData, result.changeLedgerList);
  666. }
  667. }
  668. $('#batch-sb-progress .modal-footer').show();
  669. });
  670. });
  671. <% } %>
  672. let checkingList = [];
  673. $('#batch-sp').on('show.bs.modal', function () {
  674. postData(`/tender/${tenderId}/change/batch/fun`, { type: 'get_shenpi_list' }, function (res) {
  675. let html = '';
  676. $('#select-all-checking').prop('checked', false);
  677. checkingList = res.checkingList;
  678. for (const l of res.checkingList) {
  679. const finalHtml = l.is_finalAudit ? `<input type="text" class="form-control form-control-sm final_pcode_input" data-cid="${l.cid}" value="${l.p_code}" />` : '';
  680. html += '<tr>' +
  681. `<td class="text-center"><input type="checkbox" value="${l.cid}"></td>` +
  682. `<td class=""><a href="/tender/${tenderId}/change/${l.cid}/information" target="_blank">${l.code}</a></td>` +
  683. `<td>${l.name}</td>` +
  684. `<td>${finalHtml}</td>` +
  685. '</tr>';
  686. }
  687. $('#checking_list').html(html);
  688. });
  689. });
  690. $('body').on('change', '.final_pcode_input', function () {
  691. const cid = $(this).data('cid');
  692. const cInfo = checkingList.find(item => item.cid === cid);
  693. cInfo.p_code = $(this).val();
  694. });
  695. $('#checking_list').on('click', 'input[type="checkbox"]', function (e) {
  696. e.stopPropagation();
  697. });
  698. // uncheckList tr全选
  699. $('#select-all-checking').click(function () {
  700. $('#checking_list tr').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
  701. });
  702. $('#batch_checking_btn').click(function () {
  703. // 至少勾选一个
  704. if ($('#checking_list input:checked').length === 0) {
  705. toastr.error('请至少勾选一个变更令');
  706. return false;
  707. }
  708. const cids = [];
  709. $('#checking_list input:checked').each(function () {
  710. cids.push($(this).val());
  711. });
  712. $('#batch-sp').modal('hide');
  713. $('#batch-sp-progress').modal('show');
  714. $('#batch-sp-progress .progress-tz-bar').css('width', '0%');
  715. $('#batch-sp-progress .modal-footer').hide();
  716. setProgress($('#batch-sp-progress .progress-tz-bar'), 30, 'tz2');
  717. $('#batch-sp-progress .progress-tz-text').text('台账数据获取中...').removeClass('text-success');
  718. let changeListData;
  719. let gclGatherData;
  720. postData('/tender/' + tenderId + '/change/defaultBills', { from: 'batch' }, async function (result) {
  721. gclGatherModel.loadLedgerData(result.bills);
  722. gclGatherModel.loadPosData(result.pos);
  723. gclGatherData = gclGatherModel.gatherGclData();
  724. gclGatherData = _.filter(gclGatherData, function (item) {
  725. return item.leafXmjs && item.leafXmjs.length !== 0;
  726. });
  727. for (const ggd in gclGatherData) {
  728. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  729. gclGatherData.splice(ggd, 1);
  730. }
  731. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  732. let hadcid = 0;
  733. for (const xmj of gclGatherData[ggd].leafXmjs) {
  734. const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
  735. const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  736. if (changeLedger || changePos) {
  737. xmj.cid = 1;
  738. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  739. hadcid = 1;
  740. }
  741. }
  742. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  743. }
  744. // console.log(gclGatherData);
  745. // 数组去重
  746. const dealBillList = result.dealBills;
  747. for (const db of gclGatherData) {
  748. const exist_index = dealBillList.findIndex(function (item) {
  749. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  750. });
  751. if (exist_index !== -1) {
  752. dealBillList.splice(exist_index, 1);
  753. }
  754. }
  755. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  756. console.log(changeListData);
  757. stopProgress($('#batch-sp-progress .progress-tz-bar'), 'tz2');
  758. $('#batch-sp-progress .progress-tz-text').text('台账数据加载完成').addClass('text-success');
  759. $('#batch-sp-progress .change-progress').html('');
  760. for (const c of cids) {
  761. const cInfo = checkingList.find(item => item.cid === c);
  762. if (cInfo) {
  763. $('#batch-sp-progress .change-progress').append(`<div class="mt-3" id="change-${cInfo.cid}-progress"><div>变更令 <a href="/tender/${cInfo.tid}/change/${cInfo.cid}/information" target="_blank"><b>${cInfo.code}</b></a> :</div><div class="progress">` +
  764. '<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>' +
  765. '</div>' +
  766. `<div class="mt-1"><span class="progress-change-text">审批处理中...</span></div></div>`);
  767. await checkAndChange(cInfo, changeListData, result.changeLedgerList, 'checking');
  768. }
  769. }
  770. $('#batch-sp-progress .modal-footer').show();
  771. }, function (res) {
  772. }, false);
  773. });
  774. let value = 0;
  775. // let interval;
  776. let stop = false;
  777. function setProgress(_this, time = 50, name) {
  778. let intervalId = setInterval(function () {
  779. if (value < 100) {
  780. value = parseInt(value) + 1;
  781. _this.css("width", value + "%").text(value + "%");
  782. } else if (value === 100) {
  783. value = parseInt(value) + 1;
  784. value = 30;
  785. }
  786. }, time);
  787. intervalIds[name] = intervalId;
  788. }
  789. function resetProgress(_this) {
  790. _this.removeClass('bg-success');
  791. _this.css("width", "0%").text("0%").attr('aria-valuenow', '0');
  792. }
  793. function failProgress(_this, name) {
  794. if (intervalIds[name]) {
  795. _this.addClass('bg-danger');
  796. _this.css("width", "100%").text("失败");
  797. value = 0;
  798. stop = true;
  799. clearInterval(intervalIds[name]);
  800. intervalIds[name] = 0;
  801. }
  802. }
  803. function stopProgress(_this, name) {
  804. if (intervalIds[name]) {
  805. _this.addClass('bg-success');
  806. _this.css("width", "100%").text("100%");
  807. value = 0;
  808. stop = true;
  809. clearInterval(intervalIds[name]);
  810. intervalIds[name] = 0;
  811. }
  812. }
  813. async function checkAndChange(cInfo, changeListData, changeLedgerList, status = 'uncheck') {
  814. setProgress($(`#change-${cInfo.cid}-progress .progress-bar`), 30, `change-${cInfo.cid}`);
  815. // 根据已添加的清单显示
  816. if (cInfo.changeList.length > 0 && cInfo.changeList[0]) {
  817. const removeList = [];
  818. const updateList = [];
  819. const updateGclIdList = [];
  820. for (const [index,clinfo] of cInfo.changeList.entries()) {
  821. if (clinfo.lid != 0) {
  822. let listinfo = changeListData.find(function (item) {
  823. return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
  824. });
  825. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  826. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  827. const newlistinfo = changeListData.find(function (item) {
  828. return (item.id !== undefined && item.id == clinfo.gcl_id) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id }));
  829. });
  830. if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  831. listinfo = newlistinfo;
  832. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  833. // 更新lid
  834. cInfo.changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  835. }
  836. }
  837. if (listinfo === undefined) {
  838. // 针对旧数据获取清单信息
  839. listinfo = changeListData[clinfo.lid - 1];
  840. if (listinfo === undefined) {
  841. removeList.push(clinfo);
  842. break;
  843. }
  844. }
  845. const [info, needUpdate] = makePushBwmx(clinfo, listinfo, removeList, updateList);
  846. if (needUpdate) break;
  847. if (_.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  848. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  849. const updateInfo = {};
  850. if (info.code !== clinfo.xmj_code) {
  851. updateInfo.xmj_code = info.code;
  852. // changeList[index].xmj_code = info.code;
  853. }
  854. if (info.jldy !== clinfo.xmj_jldy) {
  855. updateInfo.xmj_jldy = info.jldy;
  856. // changeList[index].xmj_jldy = info.jldy;
  857. }
  858. if (info.dwgc !== clinfo.xmj_dwgc) {
  859. updateInfo.xmj_dwgc = info.dwgc;
  860. // changeList[index].xmj_dwgc = info.dwgc;
  861. }
  862. if (info.fbgc !== clinfo.xmj_fbgc) {
  863. updateInfo.xmj_fbgc = info.fbgc;
  864. // changeList[index].xmj_fbgc = info.fbgc;
  865. }
  866. if (info.fxgc !== clinfo.xmj_fxgc) {
  867. updateInfo.xmj_fxgc = info.fxgc;
  868. // changeList[index].xmj_fxgc = info.fxgc;
  869. }
  870. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  871. updateGclIdList.push(clinfo.gcl_id);
  872. // updateInfo.gcl_id = info.id;
  873. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  874. break;
  875. }
  876. }
  877. }
  878. }
  879. await sleep(2000);
  880. if (updateList.length > 0 || removeList.length > 0) {
  881. console.log(updateList, removeList);
  882. failProgress($('#change-' + cInfo.cid + '-progress .progress-bar'), `change-${cInfo.cid}`);
  883. $('#change-' + cInfo.cid + '-progress .mt-1').addClass('text-danger');
  884. $('#change-' + cInfo.cid + '-progress .progress-change-text').text('清单数据发生变化,需要进入到详情页处理');
  885. return;
  886. }
  887. // 上报或审批变更令
  888. let ss = true;
  889. if (status === 'uncheck') {
  890. postDataWithAsync('/tender/' + tenderId + '/change/' + cInfo.cid + '/information/audit/start', {}, function () {
  891. }, function (res) {
  892. ss = false;
  893. failProgress($('#change-' + cInfo.cid + '-progress .progress-bar'), `change-${cInfo.cid}`);
  894. $('#change-' + cInfo.cid + '-progress .mt-1').addClass('text-danger');
  895. $('#change-' + cInfo.cid + '-progress .progress-change-text').text(res);
  896. return;
  897. }, false);
  898. } else {
  899. const pData = {
  900. change_id: cInfo.cid,
  901. w_code: cInfo.code,
  902. status: auditConst.status.checked,
  903. sdesc: '同意',
  904. }
  905. if (cInfo.is_finalAudit) {
  906. if (cInfo.p_code) {
  907. pData.p_code = cInfo.p_code;
  908. const postData2 = {
  909. p_code: cInfo.p_code,
  910. };
  911. let returnflag = true;
  912. postDataWithAsync('/tender/' + tenderId + '/change/' + cInfo.cid + '/check/codeRepeat',postData2, function (result) {
  913. }, function (data) {
  914. returnflag = false;
  915. });
  916. if (!returnflag) {
  917. failProgress($('#change-' + cInfo.cid + '-progress .progress-bar'), `change-${cInfo.cid}`);
  918. $('#change-' + cInfo.cid + '-progress .mt-1').addClass('text-danger');
  919. $('#change-' + cInfo.cid + '-progress .progress-change-text').text('批复编号不能与其它变更令重复!');
  920. return;
  921. }
  922. } else {
  923. failProgress($('#change-' + cInfo.cid + '-progress .progress-bar'), `change-${cInfo.cid}`);
  924. $('#change-' + cInfo.cid + '-progress .mt-1').addClass('text-danger');
  925. $('#change-' + cInfo.cid + '-progress .progress-change-text').text('变更令号(批复编号)不能为空!');
  926. return;
  927. }
  928. }
  929. postDataWithAsync('/tender/' + tenderId + '/change/approval', pData, function (result) {
  930. }, function (res) {
  931. ss = false;
  932. failProgress($('#change-' + cInfo.cid + '-progress .progress-bar'), `change-${cInfo.cid}`);
  933. $('#change-' + cInfo.cid + '-progress .mt-1').addClass('text-danger');
  934. $('#change-' + cInfo.cid + '-progress .progress-change-text').text(res);
  935. return;
  936. }, false);
  937. }
  938. if (ss) {
  939. stopProgress($('#change-' + cInfo.cid + '-progress .progress-bar'), `change-${cInfo.cid}`);
  940. $('#change-' + cInfo.cid + '-progress .mt-1').addClass('text-success');
  941. $('#change-' + cInfo.cid + '-progress .progress-change-text').text((status === 'uncheck' ? '上报' : '审批') + '成功');
  942. }
  943. }
  944. }
  945. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  946. if (showWaiting) showWaitingView();
  947. $.ajax({
  948. type:"POST",
  949. url: url,
  950. data: {'data': JSON.stringify(data)},
  951. dataType: 'json',
  952. cache: false,
  953. async: false,
  954. timeout: 60000,
  955. beforeSend: function(xhr) {
  956. let csrfToken = Cookies.get('csrfToken_j');
  957. xhr.setRequestHeader('x-csrf-token', csrfToken);
  958. },
  959. success: function(result){
  960. if (result.err === 0) {
  961. if (successCallback) {
  962. successCallback(result.data);
  963. }
  964. } else {
  965. toastr.error(result.msg);
  966. if (errorCallBack) {
  967. errorCallBack(result.msg);
  968. }
  969. }
  970. if (showWaiting) closeWaitingView();
  971. },
  972. error: function(jqXHR, textStatus, errorThrown){
  973. toastr.error('error: ' + textStatus + " " + errorThrown);
  974. if (errorCallBack) {
  975. errorCallBack();
  976. }
  977. if (showWaiting) closeWaitingView();
  978. }
  979. });
  980. };
  981. function sleep(millisecond) {
  982. return new Promise(resolve => {
  983. setTimeout(() => {
  984. resolve()
  985. }, millisecond)
  986. })
  987. }
  988. function isObjEqual(o1,o2){
  989. var props1 = Object.getOwnPropertyNames(o1);
  990. var props2 = Object.getOwnPropertyNames(o2);
  991. if (props1.length != props2.length) {
  992. return false;
  993. }
  994. for (var i = 0,max = props1.length; i < max; i++) {
  995. var propName = props1[i];
  996. if (o1[propName] !== o2[propName]) {
  997. return false;
  998. }
  999. }
  1000. return true;
  1001. }
  1002. function makePushBwmx(clinfo, listinfo, removeList, updateList) {
  1003. let info = '';
  1004. let needUpdate = false;
  1005. const checkKey = ['name', 'code', 'unit', 'unit_price'];
  1006. const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
  1007. if (listinfo.leafXmjs !== undefined) {
  1008. const leafInfo = listinfo.leafXmjs.find(function (item) {
  1009. // const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id)) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
  1010. const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
  1011. if (flag && item.code === clinfo.xmj_code) {
  1012. return flag && item.code === clinfo.xmj_code;
  1013. }
  1014. return flag;
  1015. });
  1016. if (leafInfo) {
  1017. const oneUpdate = { id: clinfo.id };
  1018. // 判断要不要更新名称,单位,原数量,单价
  1019. checkKey.forEach(function (key) {
  1020. if (listinfo[key] !== clinfo[key]) {
  1021. oneUpdate[key] = listinfo[key];
  1022. // clinfo[key] = listinfo[key];
  1023. if (key === 'unit') {
  1024. const changeKey = ['oamount', 'oamount2', 'camount'];
  1025. changeKey.forEach(function (key) {
  1026. const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
  1027. if (value !== clinfo[key]) {
  1028. oneUpdate[key] = value;
  1029. // clinfo[key] = value;
  1030. }
  1031. });
  1032. }
  1033. needUpdate = true;
  1034. }
  1035. });
  1036. checkLeafKey.forEach(function (key) {
  1037. // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
  1038. if (key === 'oamount') {
  1039. if (leafInfo.quantity !== clinfo[key]) {
  1040. oneUpdate[key] = leafInfo.quantity;
  1041. // clinfo[key] = leafInfo.quantity;
  1042. needUpdate = true;
  1043. }
  1044. } else if (key === 'bwmx') {
  1045. if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
  1046. oneUpdate[key] = leafInfo[key];
  1047. // clinfo[key] = leafInfo[key];
  1048. needUpdate = true;
  1049. } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
  1050. oneUpdate[key] = leafInfo.jldy;
  1051. // clinfo[key] = leafInfo.jldy;
  1052. needUpdate = true;
  1053. }
  1054. } else {
  1055. if (leafInfo[key] !== clinfo['xmj_' + key]) {
  1056. oneUpdate['xmj_' + key] = leafInfo[key];
  1057. // clinfo['xmj_' + key] = leafInfo[key];
  1058. needUpdate = true;
  1059. }
  1060. }
  1061. });
  1062. if (needUpdate) {
  1063. updateList.push(oneUpdate);
  1064. }
  1065. info = leafInfo;
  1066. } else {
  1067. removeList.push(clinfo);
  1068. needUpdate = true;
  1069. }
  1070. }
  1071. return [info, needUpdate];
  1072. }
  1073. function findDecimal(unit) {
  1074. let value = precision.other.value;
  1075. const changeUnits = precision;
  1076. for (const d in changeUnits) {
  1077. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  1078. value = changeUnits[d].value;
  1079. break;
  1080. }
  1081. }
  1082. return value;
  1083. }
  1084. // 编号排序,多重判断
  1085. function sortByCode(a, b) {
  1086. let code1 = a.code.split('-');
  1087. let code2 = b.code.split('-');
  1088. let code1length = code1.length;
  1089. let code2length = code2.length;
  1090. for (let i = 0; i < code1length; i ++) {
  1091. if (i+1 <= code2length) {
  1092. if (code1[i] != code2[i]) {
  1093. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  1094. return parseInt(code1[i]) - parseInt(code2[i]);
  1095. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  1096. return 1;
  1097. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  1098. return -1;
  1099. } else {
  1100. const str1length = code1[i].length;
  1101. const str2length = code2[i].length;
  1102. for (let j = 0; j < str1length; j++) {
  1103. if (j+1 <= str2length) {
  1104. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  1105. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  1106. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  1107. if (str1length == str2length) {
  1108. return 0;
  1109. } else {
  1110. return str1length - str2length;
  1111. }
  1112. }
  1113. } else {
  1114. if (j+1 >= str1length) {
  1115. return 1;
  1116. } else {
  1117. return -1;
  1118. }
  1119. }
  1120. }
  1121. }
  1122. } else if (i+1 == code1length && code1[i] == code2[i]) {
  1123. if (code1length == code2length) {
  1124. return 0;
  1125. } else {
  1126. return code1length - code2length;
  1127. }
  1128. }
  1129. } else {
  1130. if (i+1 >= code1length) {
  1131. return 1;
  1132. } else {
  1133. return -1;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. });
  1139. </script>