measure_work.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/6/21
  7. * @version
  8. */
  9. function getMid() {
  10. return window.location.pathname.split('/')[3];
  11. }
  12. // 新增计量范围
  13. function addMeasurePos(pid) {
  14. postData('/measure/pos', {
  15. mid: window.location.pathname.split('/')[3],
  16. operate: 'add',
  17. pid: pid,
  18. }, function (data) {
  19. const tr = [];
  20. tr.push('<tr id="' + data.pid +'">');
  21. tr.push('<td>' + data.code + '</td>');
  22. tr.push('<td>' + data.name + '</td>');
  23. tr.push('<td><a href="javascript: void(0)" class="text-danger" onclick="removeMeasurePos(' + data.pid + ')">移除</a></td>');
  24. tr.push('</tr>');
  25. $('#measurePosList').append(tr.join(''));
  26. })
  27. }
  28. // 移除计量范围
  29. function removeMeasurePos(pid) {
  30. postData('/measure/pos', {
  31. mid: getMid(),
  32. operate: 'remove',
  33. pid: pid,
  34. }, function (data) {
  35. $('tr[id='+ pid +']', '#measurePosList').remove();
  36. })
  37. }
  38. //
  39. function getAuditorHtml(audit) {
  40. const html = [];
  41. html.push('<li class="list-group-item" auditorId="'+ audit.audit_id +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  42. html.push('<span>');
  43. html.push(audit.order + ' ');
  44. html.push(audit.name + ' ');
  45. html.push('</span>');
  46. html.push('<small class="text-muted">');
  47. html.push(audit.role);
  48. html.push('</small></li>')
  49. return html.join('');
  50. }
  51. function bindRemoveAuditor(obj) {
  52. obj.click(function () {
  53. const li = $(this).parent();
  54. const data = {
  55. mid: getMid(),
  56. auditorId: parseInt(li.attr('auditorId')),
  57. }
  58. postData('/measure/audit/remove', data, (data) => {
  59. li.remove();
  60. for (const a of data) {
  61. const aLi = $('li[auditorId=' + a.audit_id + ']');
  62. $('span', aLi).text(a.order + ' ' + a.name + ' ');
  63. }
  64. });
  65. });
  66. }
  67. function getAuditStatuHtml(measure) {
  68. const html = [];
  69. if (measure.status === auditConst.status.checkNo) {
  70. html.push('<a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-warning btn-sm pull-right text-dark">报审退回</a>');
  71. } else if (measure.status === auditConst.status.checking) {
  72. html.push('<a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-warning btn-sm pull-right text-dark">审批中</a>');
  73. } else if (measure.status === auditConst.status.checked) {
  74. html.push('<a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-secondary btn-sm pull-right">审批完成</a>');
  75. }
  76. if (measure.user_id === userId ) {
  77. if (!measure.status || measure.status === auditConst.status.uncheck) {
  78. html.push('<a href="#sub-sp" data-toggle="modal" data-target="#sub-sp" class="btn btn-primary btn-sm pull-right">上报审批</a>');
  79. } else if (measure.status === auditConst.status.checkNo) {
  80. html.push('<a href="#sub-sp" data-toggle="modal" data-target="#sub-sp2" class="btn btn-primary btn-sm pull-right">重新上报</a>');
  81. }
  82. html.push('<a href="#del" data-toggle="modal" data-target="#del" class="btn btn-outline-danger btn-sm pull-right">删除' + measure.code + '</a>');
  83. }
  84. return html.join('');
  85. }
  86. function getAuditListHtml(measure) {
  87. const html = [];
  88. for (const auditor of measure.auditors) {
  89. html.push('<li class="list-group-item" auditorId="' + auditor.audit_id + '">');
  90. if (auditor.status !== auditConst.status.uncheck) {
  91. html.push('<span class="' + auditConst.statusClass[auditor.status] + ' pull-right">' + auditConst.statusString[auditor.status] + '</span>');
  92. }
  93. html.push('<h5 class="card-title">' + auditor.order + ' ' + auditor.name + ' <small class="text-muted">' + auditor.role + '</small></h5>');
  94. html.push('<p class="card-text">', (auditor.opinion ? auditor.opinion : ''), ' ', (auditor.end_time ? moment(auditor.end_time).format('YYYY-MM-DD') : ''), '</p>');
  95. html.push('</li>');
  96. }
  97. return html.join('');
  98. }
  99. $(document).ready(() => {
  100. autoFlashHeight();
  101. // 上报审批 搜索
  102. $('#searchAccount').click(() => {
  103. const data = {
  104. keyword: $('#searchName').val(),
  105. }
  106. postData('/search/user', data, (data) => {
  107. const resultDiv = $('#searchResult');
  108. $('h5>span', resultDiv).text(data.name);
  109. $('#addAuditor').attr('auditorId', data.id);
  110. $('h6', resultDiv).text(data.role);
  111. $('p', resultDiv).text(data.company);
  112. resultDiv.show();
  113. }, () => {
  114. $('#searchResult').hide();
  115. });
  116. });
  117. // 上报审批 添加审批人
  118. $('#addAuditor').click(() => {
  119. const data = {
  120. mid: getMid(),
  121. auditorId: $('#addAuditor').attr('auditorId'),
  122. };
  123. postData('/measure/audit/add', data, (data) => {
  124. $('#auditors').append(getAuditorHtml(data));
  125. bindRemoveAuditor($('li[auditorId=' + data.audit_id + ']>a'));
  126. });
  127. });
  128. // 上报审批
  129. $('#auditStart').click(() => {
  130. const data = { mid: getMid() };
  131. postData('/measure/audit/start', data, function (data) {
  132. $('#sub-sp').modal('hide');
  133. // 审批状态等
  134. $('#operate').html(getAuditStatuHtml(data));
  135. // 审批流程列表
  136. $('ul', '#sp-list').html(getAuditListHtml(data));
  137. });
  138. });
  139. // 重新上报
  140. $('#auditRestart').click(() => {
  141. const data = { mid: getMid() };
  142. postData('/measure/audit/start', data, function (data) {
  143. $('#sub-sp2').modal('hide');
  144. // 审批状态等
  145. $('#operate').html(getAuditStatuHtml(data));
  146. // 审批流程列表
  147. $('ul', '#sp-list').html(getAuditListHtml(data));
  148. });
  149. });
  150. const billsTree = createNewPathTree('measure', {
  151. id: 'ledger_id',
  152. pid: 'ledger_pid',
  153. order: 'order',
  154. level: 'level',
  155. rootId: -1,
  156. keys: ['id', 'tender_id', 'ledger_id'],
  157. });
  158. let billsSpread;
  159. // 获取中间计量详细数据
  160. function getMeasureDetail(mid) {
  161. postData('/measure/detail', { mid: mid }, function(data) {
  162. // 计量范围
  163. const posHtml = [];
  164. for (const p of data.pos) {
  165. const tr = [];
  166. tr.push('<tr id="' + p.pid +'">');
  167. tr.push('<td>' + p.code + '</td>');
  168. tr.push('<td>' + p.name + '</td>');
  169. tr.push('<td><a href="javascript: void(0)" class="text-danger" onclick="removeMeasurePos(' + p.pid + ')">移除</a></td>');
  170. tr.push('</tr>');
  171. posHtml.push(tr.join(''));
  172. }
  173. $('#measurePosList').html(posHtml.join(''));
  174. // 计量清单
  175. billsTree.loadDatas(data.billsTree);
  176. treeCalc.calculateAll(billsTree, ['total_price', 'deal_totalprice', 'qc_totalprice']);
  177. if (!billsSpread) {
  178. billsSpread = SpreadJsObj.createNewSpread($('#billsSpread')[0]);
  179. const sheet = billsSpread.getActiveSheet();
  180. SpreadJsObj.initSheet(sheet, measureSpreadSetting);
  181. SpreadJsObj.loadSheetData(sheet, 'tree', billsTree);
  182. /**
  183. * 父项不可编辑
  184. * sender - {type: 'EditStarting'}
  185. * args - {sheet, sheetName, row, col, cancel}
  186. */
  187. sheet.bind(spreadNS.Events.EditStarting, function (sender, args) {
  188. const sheet = args.sheet;
  189. if (sheet.zh_tree) {
  190. const node = sheet.zh_tree.nodes[args.row];
  191. args.cancel = node ? !node.is_leaf : true;
  192. } else {
  193. args.cancel = true;
  194. }
  195. });
  196. /**
  197. * 最底层清单编辑后,提交
  198. * sender - {type: 'EditEnding'}
  199. * args - {sheet, sheetName, row, col, editor, editingText cancel}
  200. */
  201. sheet.bind(spreadNS.Events.EditEnding, function (sender, args) {
  202. const sheet = args.sheet;
  203. if (sheet.zh_tree || sheet.zh_setting) {
  204. const node = sheet.zh_tree.nodes[args.row];
  205. const col = sheet.zh_setting.cols[args.col];
  206. if (node && node.is_leaf) {
  207. const updateData = {
  208. mid: getMid(),
  209. bid: node.ledger_id,
  210. update: {},
  211. }
  212. updateData.update[col.field] = col.type === 'Number' ? parseFloat(args.editingText) : args.editingText;
  213. postData('/measure/billsUpdate', updateData, function (data) {
  214. if (sheet.zh_tree.loadLeafData) {
  215. sheet.zh_tree.loadLeafData(data);
  216. const nodes = treeCalc.calculateParent(sheet.zh_tree, node, ['deal_totalprice', 'qc_totalprice']);
  217. SpreadJsObj.reLoadNodesData(sheet, nodes);
  218. }
  219. }, function () {
  220. args.cancel = true;
  221. });
  222. } else {
  223. args.cancel = true;
  224. }
  225. } else {
  226. args.cancel = true;
  227. }
  228. });
  229. } else {
  230. SpreadJsObj.reLoadSheetData(billsSpread.getActiveSheet());
  231. }
  232. // 审批状态等
  233. $('#operate').html(getAuditStatuHtml(data));
  234. $('ul', '#sp-list').html(getAuditListHtml(data));
  235. // 上报审批 审批人列表
  236. const ad = [];
  237. for (const auditor of data.auditors) {
  238. ad.push(getAuditorHtml(auditor));
  239. }
  240. $('#auditors').html(ad.join(''));
  241. // 重新上报 审批人列表
  242. if (data.status === auditConst.status.checkNo) {
  243. $('#re-hint').text('重新上报后,将由 ' + data.auditors[0].name +' 继续审批');
  244. $('#re-auditors').html(getAuditListHtml(data));
  245. }
  246. // 绑定移除方法
  247. bindRemoveAuditor($('a', '#auditors'));
  248. });
  249. }
  250. // 新增计量清单
  251. function addMeasureBills (bid) {
  252. const data = {
  253. mid: getMid(),
  254. operate: 'add',
  255. bid: bid,
  256. };
  257. postData('/measure/bills', data, function (data) {
  258. billsTree.addData(data);
  259. SpreadJsObj.reLoadSheetData(billsSpread.getActiveSheet());
  260. });
  261. }
  262. // 移除计量清单
  263. function removeMeasureBills (bid) {
  264. const data = {
  265. mid: getMid(),
  266. operate: 'remove',
  267. bid: bid,
  268. };
  269. postData('/measure/bills', data, function (data) {
  270. billsTree.removeData(data);
  271. SpreadJsObj.reLoadSheetData(billsSpread.getActiveSheet());
  272. });
  273. }
  274. // 勾选计量清单
  275. function checkMeasureBills() {
  276. const bid = $(this).parent().parent().attr('id');
  277. if (!bid) { return; }
  278. if (this.checked) {
  279. addMeasureBills(bid);
  280. } else {
  281. removeMeasureBills(bid);
  282. }
  283. }
  284. // 添加计量清单
  285. $('#addMeasureBills').click(function () {
  286. if ($('#measurePosList').children().length === 0) {
  287. $('#add-pos').modal('show');
  288. } else {
  289. $('#add-qd').modal('show');
  290. }
  291. });
  292. // 搜索项目节部位
  293. $('#search-pos').click(function () {
  294. const keyword = $('input', '#add-pos').val();
  295. if (keyword !== '') {
  296. postData('/measure/search', {
  297. mid: getMid(),
  298. searchType: 'pos',
  299. keyword: keyword
  300. }, function (data) {
  301. const html = [];
  302. for (const d of data) {
  303. const tr = [];
  304. tr.push('<tr id="' + d.ledger_id +'">');
  305. tr.push('<td>' + d.code + '</td>');
  306. tr.push('<td>' + d.name + '</td>');
  307. tr.push('<td><a href="javascript: void(0)" onclick="addMeasurePos(' + d.ledger_id + ')">添加</a></td>');
  308. tr.push('</tr>');
  309. html.push(tr.join(''));
  310. }
  311. $('#searchedPosList').html(html.join(''));
  312. });
  313. }
  314. });
  315. // 选择计量清单
  316. $('#chooseBills').click(function () {
  317. $('#add-pos').modal('hide');
  318. $('#add-qd').modal('show');
  319. });
  320. // 搜索计量清单
  321. $('#search-bills').click(function () {
  322. const keyword = $('input', '#add-qd').val();
  323. if (keyword !== '') {
  324. postData('/measure/search', {
  325. mid: getMid(),
  326. searchType: 'bills',
  327. keyword: keyword
  328. }, function (data) {
  329. const html = [];
  330. for (const d of data) {
  331. const tr = [];
  332. const check = billsTree.getItems(d.ledger_id) ? 'checked' : '';
  333. tr.push('<tr id="' + d.ledger_id +'">');
  334. tr.push('<td>' + d.b_code + '</td>');
  335. tr.push('<td>' + d.name + '</td>');
  336. tr.push('<td>' + d.unit + '</td>');
  337. tr.push('<td>' + (d.unit_price ? d.unit_price : '') + '</td>');
  338. tr.push('<td><input type="checkbox" ' + check + '> 已选择</td>');
  339. tr.push('</tr>');
  340. html.push(tr.join(''));
  341. }
  342. $('#searchedBillsList').html(html.join(''));
  343. $('input[type=checkbox]', '#add-qd').click(checkMeasureBills);
  344. });
  345. }
  346. });
  347. // 选择计量范围
  348. $('#choosePos').click(function () {
  349. $('#add-qd').modal('hide');
  350. $('#add-pos').modal('show');
  351. });
  352. getMeasureDetail(getMid());
  353. });