stage.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. function checkTzMeasureType () {
  10. return tender.measure_type === measureType.tz.value;
  11. }
  12. /**
  13. * 从cookie中读取缓存的列显示设置,没有则取默认
  14. * @returns {*[]}
  15. */
  16. function customColDisplay () {
  17. const defaultSetting = [
  18. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  19. { title: '施工图复核', fields: ['quantity', 'total_price'], visible: true },
  20. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  21. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  22. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  23. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  24. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  25. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp'], visible: true },
  26. { title: '图册号', fields: ['drawing_code'], visible: true },
  27. { title: '累计完成率(%)', fields: ['percent'], visible: true },
  28. { title: '备注', fields: ['memo'], visible: true },
  29. ];
  30. const settingStr = Cookies.get('stage-col-visible');
  31. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  32. }
  33. /**
  34. * 根据列显示设置,调整setting中的列是否显示
  35. * @param setting
  36. * @param customDisplay
  37. */
  38. function customizeStageTreeSetting(setting, customDisplay) {
  39. for (const cd of customDisplay) {
  40. for (const c of setting.cols) {
  41. if (cd.fields.indexOf(c.field) !== -1) {
  42. c.visible = cd.visible;
  43. }
  44. }
  45. }
  46. }
  47. /**
  48. * 初始化 树结构 列事件
  49. * @param setting
  50. */
  51. function initTreeColSettingEvents(setting) {
  52. const Events = {
  53. readOnly: {
  54. measureData: function (node) {
  55. return node.children && node.children.length > 0;
  56. },
  57. },
  58. };
  59. const getEvent = function (eventName) {
  60. const names = eventName.split('.');
  61. let event = Events;
  62. for (let name of names) {
  63. if (event[name]) {
  64. event = event[name];
  65. } else {
  66. return null;
  67. }
  68. }
  69. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  70. return null;
  71. } else {
  72. return event;
  73. }
  74. };
  75. for (const col of setting.cols) {
  76. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  77. col.readOnly = getEvent(col.readOnly);
  78. }
  79. }
  80. }
  81. $(document).ready(() => {
  82. // 界面布局
  83. autoFlashHeight();
  84. // 初始化 台账树结构 数据结构
  85. const stageTreeSetting = {
  86. id: 'ledger_id',
  87. pid: 'ledger_pid',
  88. order: 'order',
  89. level: 'level',
  90. rootId: -1,
  91. keys: ['id', 'tender_id', 'ledger_id'],
  92. stageId: 'id',
  93. };
  94. // 台账树结构计算相关设置
  95. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'];
  96. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  97. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  98. stageTreeSetting.calcFun = function (node) {
  99. if (node.children && node.children.length === 0) {
  100. node.pre_gather_qty = _.add(node.pre_contract_qty, node.pre_qc_qty);
  101. node.gather_qty = _.add(node.contract_qty, node.qc_qty);
  102. node.end_contract_qty = _.add(node.pre_contract_qty, node.contract_qty);
  103. node.end_qc_qty = _.add(node.pre_qc_qty, node.qc_qty);
  104. node.end_gather_qty = _.add(node.pre_gather_qty, node.gather_qty);
  105. }
  106. node.pre_gather_tp = _.add(node.pre_contract_tp, node.pre_qc_tp);
  107. node.gather_tp = _.add(node.contract_tp, node.qc_tp);
  108. node.end_contract_tp = _.add(node.pre_contract_tp, node.contract_tp);
  109. node.end_qc_tp = _.add(node.pre_qc_tp, node.qc_tp);
  110. node.end_gather_tp = _.add(node.pre_gather_tp, node.gather_tp);
  111. if (checkZero(node.dgn_qty1)) {
  112. node.dgn_price = _.round(node.total_price/node.dgn_qty1, 2);
  113. } else {
  114. node.dgn_price = null;
  115. }
  116. };
  117. const stageTree = createNewPathTree('stage', stageTreeSetting);
  118. // 初始化 部位明细 数据结构
  119. const stagePosSetting = {
  120. id: 'id', ledgerId: 'lid',
  121. updateFields: ['contract_qty', 'qc_qty', 'postil'],
  122. };
  123. stagePosSetting.calcFun = function (pos) {
  124. pos.pre_gather_qty = _.add(pos.pre_contract_qty, pos.pre_qc_qty);
  125. pos.gather_qty = _.add(pos.contract_qty, pos.qc_qty);
  126. pos.end_contract_qty = _.add(pos.pre_contract_qty, pos.contract_qty);
  127. pos.end_qc_qty = _.add(pos.pre_qc_qty, pos.qc_qty);
  128. pos.end_gather_qty = _.add(pos.pre_gather_qty, pos.gather_qty);
  129. };
  130. const stagePos = new StagePosData(stagePosSetting);
  131. class Changes {
  132. constructor(obj) {
  133. const self = this;
  134. this.obj = obj;
  135. // 初始化 清单编号窗口 参数
  136. this.spreadSetting = {
  137. cols: [
  138. {title: '已用', field: 'used', width: 45, formatter: '@', cellType: 'checkbox', readOnly: true, hAlign: 1,},
  139. {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true},
  140. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  141. {title: '总数量', field: 'amount', width: 60, formatter: '@', readOnly: true},
  142. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true},
  143. {title: '本期计量', field: 'uamount', width: 60, formatter: '@'},
  144. ],
  145. emptyRows: 0,
  146. headRows: 1,
  147. headRowHeight: [40],
  148. };
  149. this.curChangeId = '';
  150. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  151. this.firstView = true;
  152. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  153. // 初次显示,需刷新spread界面,保证界面绘制正确
  154. this.obj.bind('shown.bs.modal', function () {
  155. if (self.firstView) {
  156. self.firstView = false;
  157. self.spread.refresh();
  158. }
  159. });
  160. // 切换变更令,加载右侧明细数据
  161. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  162. const change = SpreadJsObj.getSelectObject(info.sheet);
  163. self._loadChangeDetail(change);
  164. });
  165. // 过滤可变更数量为0
  166. $('#customCheckDisabled').click(function () {
  167. self._filterEmptyChange(!this.checked);
  168. });
  169. $('#show-bgl-detail').bind('click', function () {
  170. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  171. if (detail.hasClass('col-4')) {
  172. detail.attr('class', 'col').hide();
  173. bgl.attr('class', 'col-12');
  174. $('a', obj).attr('title', '展开侧栏');
  175. $('i', obj).attr('class', 'fa fa-chevron-left');
  176. self.spread.refresh();
  177. } else {
  178. detail.attr('class', 'col-4').show();
  179. bgl.attr('class', 'col-8');
  180. $('a', obj).attr('title', '收起侧栏');
  181. $('i', obj).attr('class', 'fa fa-chevron-right');
  182. self.spread.refresh();
  183. }
  184. });
  185. }
  186. _loadChangeDetail(change) {
  187. if (change) {
  188. if (change.cid === this.curChangeId) { return; }
  189. this.curChangeId = change.cid;
  190. const inputs = $('input[type!=checkbox]', this.obj);
  191. for (const i of inputs) {
  192. const field = $(i).attr('name');
  193. const text = (field && change[field]) ? change[field] : '';
  194. $(i).val(text);
  195. }
  196. const textareas = $('textarea', this.obj);
  197. for (const ta of textareas) {
  198. const field = $(ta).attr('name');
  199. const text = (field && change[field]) ? change[field] : '';
  200. ta.innerText = text;
  201. }
  202. const html = [];
  203. for (const a of change.attachments) {
  204. html.push('<tr>');
  205. html.push('<td>', a.filename + a.fileext, '</td>');
  206. html.push('<td>', a.u_name, '</td>');
  207. html.push('</tr>');
  208. }
  209. // 变更类型
  210. const cType = change.type.split(',');
  211. $('input[name="type"]').prop("checked", false);
  212. for (const c of cType) {
  213. $('input[name="type"][value='+ c +']').prop("checked", true);
  214. }
  215. // 变更类别
  216. $('select[name=class]').val(change.class);
  217. // 变更性质
  218. $('select[name=quality]').val(change.quality);
  219. // 变更单位
  220. $('select[name=company]').html('<option>' + change.company + '</option>');
  221. // 费用承担方
  222. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  223. // 附件
  224. $('#attachment').html(html.join(''));
  225. } else {
  226. const inputs = $('input', this.obj);
  227. for (const i of inputs) {
  228. $(i).val('');
  229. }
  230. const textareas = $('textarea', this.obj);
  231. for (const ta of textareas) {
  232. ta.innerText = '';
  233. }
  234. $('#attachment').html('');
  235. }
  236. }
  237. _viewChanges() {
  238. const sheet = this.spread.getActiveSheet();
  239. if (this.changes) {
  240. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  241. sheet.setSelection(0, 0, 1, 1);
  242. this._loadChangeDetail(this.changes[0]);
  243. this._filterEmptyChange(!$('#customCheckDisabled')[0].checked);
  244. } else {
  245. toast('查询变更令有误,请刷新页面后重试', 'warning');
  246. }
  247. }
  248. _filterEmptyChange(isFilter) {
  249. for (const c of this.changes) {
  250. c.visible = isFilter ? (c.vamount || c.vamount === 0) : true;
  251. }
  252. SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  253. }
  254. loadChanges(data) {
  255. this.callData = data;
  256. const self = this;
  257. postData(window.location.pathname + '/valid-change', data, function (result) {
  258. self.changes = result;
  259. self._viewChanges();
  260. self.obj.modal('show');
  261. });
  262. }
  263. }
  264. const changesObj = new Changes($('#use-bg'));
  265. // 初始化 台账 spread
  266. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  267. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  268. // 数量变更列,添加按钮
  269. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  270. col.readOnly = true;
  271. col.cellType = 'imageBtn';
  272. col.hoverImg = '#ellipsis-icon';
  273. col.indent = 5;
  274. col.showImage = function (data) {
  275. if (!data || (data.children && data.children.length > 0)) {
  276. return false;
  277. } else {
  278. const nodePos = stagePos.getLedgerPos(data.id);
  279. return !(nodePos && nodePos.length > 0);
  280. }
  281. };
  282. ledgerSpreadSetting.imageClick = function (data) {
  283. changesObj.loadChanges({bills: data});
  284. };
  285. //
  286. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  287. stageTree.loadDatas(ledgerData);
  288. stageTree.loadCurStageData(curStageData);
  289. stageTree.loadPreStageData(preStageData);
  290. // 根据设置 计算 台账树结构
  291. treeCalc.calculateAll(stageTree);
  292. // 绘制界面
  293. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  294. // 初始化 部位明细 Spread
  295. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  296. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  297. spCol.readOnly = true;
  298. spCol.cellType = 'imageBtn';
  299. spCol.hoverImg = '#ellipsis-icon';
  300. spCol.indent = 5;
  301. spCol.showImage = function (data) {
  302. return data;
  303. };
  304. posSpreadSetting.imageClick = function (data) {
  305. changesObj.loadChanges({pos: data});
  306. };
  307. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  308. const stageTreeSpreadObj = {
  309. refreshTreeNodes: function (sheet, nodes) {
  310. const tree = sheet.zh_tree;
  311. if (!tree) { return }
  312. const rows = [];
  313. for (const node of nodes) {
  314. rows.push(tree.nodes.indexOf(node));
  315. }
  316. SpreadJsObj.reLoadRowsData(sheet, rows);
  317. },
  318. editEnded: function (e, info) {
  319. if (info.sheet.zh_setting) {
  320. const col = info.sheet.zh_setting.cols[info.col];
  321. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  322. const node = sortData[info.row];
  323. if (node.children && node.children.length > 0) {
  324. toast('清单父项不可计量', 'error');
  325. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  326. return;
  327. } else {
  328. const nodePos = stagePos.getLedgerPos(node.id);
  329. if (nodePos && nodePos.length > 0) {
  330. toast('该清单有部位明细,请在部位明细处计量', 'error');
  331. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  332. return;
  333. }
  334. }
  335. const billsData = {
  336. lid: node.id
  337. };
  338. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  339. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  340. const nodes = stageTree.loadPostStageData(data.bills);
  341. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  342. });
  343. }
  344. },
  345. selectionChanged: function (e, info) {
  346. stagePosSpreadObj.loadCurPosData();
  347. },
  348. deletePress(sheet) {
  349. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  350. const tree = sheet.zh_tree;
  351. if (!tree) { return; }
  352. const sel = sheet.getSelections()[0];
  353. const validCols = [];
  354. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  355. if (!sheet.zh_setting.cols[iCol].readOnly) {
  356. validCols.push(iCol);
  357. }
  358. }
  359. if (validCols.length === 0) { return; }
  360. const sortData = sheet.zh_tree.nodes;
  361. const datas = [];
  362. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  363. const node = sortData[iRow];
  364. if (node) {
  365. if (node.children && node.children.length > 0) { continue; }
  366. const nodePos = stagePos.getLedgerPos(node.id);
  367. if (nodePos && nodePos.length > 0) { continue; }
  368. const data = { lid: node.id };
  369. for (const iCol of validCols) {
  370. const colSetting = sheet.zh_setting.cols[iCol];
  371. data[colSetting.field] = null;
  372. }
  373. datas.push(data);
  374. }
  375. }
  376. if (datas.length > 0) {
  377. postData(window.location.href + '/update', {bills: datas}, function (result) {
  378. const nodes = stageTree.loadPostStageData(result.bills);
  379. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  380. });
  381. }
  382. }
  383. },
  384. clipboardPasting(e, info) {
  385. if (info.sheet.zh_setting) {
  386. const sortData = info.sheet.zh_data;
  387. const range = info.cellRange;
  388. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  389. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  390. const col = info.sheet.zh_setting.cols[iCol];
  391. if (validField.indexOf(col.field) === -1) {
  392. toast('不可修改此数据', 'error');
  393. info.cancel = true;
  394. return;
  395. }
  396. }
  397. }
  398. },
  399. clipboardPasted(e, info) {
  400. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  401. const sheet = info.sheet;
  402. const filterNodes = [], datas = [];
  403. console.log(info.cellRange);
  404. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  405. const curRow = iRow + info.cellRange.row;
  406. const node = sheet.zh_tree.getItemsByIndex(curRow);
  407. if (node.children && node.children.length > 0) {
  408. filterNodes.push(node);
  409. continue;
  410. }
  411. const nodePos = stagePos.getLedgerPos(node.id);
  412. if (nodePos && nodePos.length > 0) {
  413. filterNodes.push(node);
  414. continue;
  415. }
  416. const data = {lid: node.id};
  417. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  418. const curCol = info.cellRange.col + iCol;
  419. const col = info.sheet.zh_setting.cols[curCol];
  420. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  421. }
  422. datas.push(data);
  423. }
  424. console.log(datas);
  425. if (datas.length > 0) {
  426. postData(window.location.href + '/update', { bills: datas }, function (data) {
  427. const nodes = stageTree.loadPostStageData(data.bills);
  428. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  429. });
  430. } else {
  431. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  432. }
  433. }
  434. }
  435. };
  436. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  437. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  438. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  439. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  440. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  441. const stagePosSpreadObj = {
  442. /**
  443. * 加载部位明细 根据当前台账选择节点
  444. */
  445. loadCurPosData: function () {
  446. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  447. if (node) {
  448. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  449. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  450. } else {
  451. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  452. }
  453. },
  454. editEnded: function (e, info) {
  455. if (info.sheet.zh_setting) {
  456. // 未改变过,则直接跳过
  457. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  458. const col = info.sheet.zh_setting.cols[info.col];
  459. const orgText = posData ? posData[col.field] : null;
  460. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  461. return;
  462. }
  463. // 台账模式下,不可新增
  464. if (checkTzMeasureType() && !posData) {
  465. toast('台账模式不可新增部位明细数据', 'error');
  466. info.cancel = true;
  467. return ;
  468. }
  469. // 不同节点下,部位明细检查输入
  470. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  471. if (!node) {
  472. toast('数据错误, 请刷新页面后再试', 'warning');
  473. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  474. return;
  475. } else if (info.editingText !== '' && node.children && node.children > 0) {
  476. toast('父节点不可插入部位明细', 'error');
  477. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  478. return;
  479. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  480. toast('项目节不可插入部位明细', 'error');
  481. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  482. return;
  483. }
  484. // 生成提交数据
  485. const data = {};
  486. if (col.field === 'name') {
  487. if (info.editingText === '' && pos) {
  488. toast('部位名称不可为空', 'error', 'exclamation-circle');
  489. info.cancel = true;
  490. return;
  491. } else if (!pos) {
  492. if (info.editingText !== '') {
  493. data.updateType = 'add';
  494. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  495. } else {
  496. return;
  497. }
  498. } else {
  499. data.updateType = 'update';
  500. data.updateData = {id: posData.id, name: info.editingText};
  501. }
  502. } else if (!posData) {
  503. toast('新增部位请先输入名称', 'warning');
  504. } else {
  505. data.updateType = 'update';
  506. data.updateData = {pid: posData.id, lid: posData.lid};
  507. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  508. }
  509. // 提交数据到服务器
  510. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  511. if (result.pos) {
  512. stagePos.updateDatas(result.pos.pos);
  513. stagePos.loadCurStageData(result.pos.curStageData);
  514. }
  515. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  516. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  517. stagePosSpreadObj.loadCurPosData();
  518. }, function () {
  519. stagePosSpreadObj.loadCurPosData();
  520. });
  521. }
  522. },
  523. clipboardPasting: function (e, info) {
  524. if (info.sheet.zh_setting) {
  525. const sortData = info.sheet.zh_data;
  526. const range = info.cellRange;
  527. const validField = ['contract_qty', 'qc_qty', 'postil'];
  528. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  529. const col = info.sheet.zh_setting.cols[iCol];
  530. if (validField.indexOf(col.field) === -1) {
  531. if (checkTzMeasureType()) {
  532. toast('不可修改此数据', 'error');
  533. info.cancel = true;
  534. return;
  535. } else {
  536. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  537. const pos = sortData(iRow);
  538. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  539. toast('不可修改此数据', 'error');
  540. info.cancel = true;
  541. return;
  542. }
  543. }
  544. }
  545. }
  546. }
  547. }
  548. },
  549. clipboardPasted: function (e, info) {
  550. const self = this;
  551. if (info.sheet.zh_setting) {
  552. const data = { updateType: '', updateData: [], };
  553. const sortData = info.sheet.zh_data;
  554. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  555. if (sortData && (info.cellRange.row >= sortData.length)) {
  556. data.updateType = 'add';
  557. if (info.cellRange.col !== 0) {
  558. toast('新增部位请先输入名称', 'warning');
  559. self.loadCurPosData();
  560. return;
  561. }
  562. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  563. const curRow = info.cellRange.row + iRow;
  564. const newData = {lid: node.id};
  565. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  566. const curCol = info.cellRange.col + iCol;
  567. const colSetting = info.sheet.zh_setting.cols[curCol];
  568. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  569. if (colSetting.type === 'Number') {
  570. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  571. }
  572. }
  573. data.updateData.push(newData);
  574. }
  575. } else {
  576. data.updateType = 'update';
  577. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  578. const curRow = info.cellRange.row + iRow;
  579. const curPos = sortData[curRow];
  580. if (curPos) {
  581. const newData = {pid: curPos.id, lid: curPos.lid};
  582. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  583. const curCol = info.cellRange.col + iCol;
  584. const colSetting = info.sheet.zh_setting.cols[curCol];
  585. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  586. if (colSetting.type === 'Number') {
  587. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  588. }
  589. }
  590. data.updateData.push(newData);
  591. }
  592. }
  593. }
  594. console.log(data);
  595. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  596. if (result.pos) {
  597. stagePos.updateDatas(result.pos.pos);
  598. stagePos.loadCurStageData(result.pos.curStageData);
  599. }
  600. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  601. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  602. stagePosSpreadObj.loadCurPosData();
  603. }, function () {
  604. stagePosSpreadObj.loadCurPosData();
  605. });
  606. }
  607. },
  608. deletePress: function (sheet) {
  609. if (sheet.zh_setting && sheet.zh_data) {
  610. const sortData = sheet.zh_data;
  611. if (!sortData || sortData.length === 0) { return; }
  612. const sel = sheet.getSelections()[0];
  613. const validCols = [];
  614. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  615. if (!sheet.zh_setting.cols[iCol].readOnly) {
  616. validCols.push(iCol);
  617. }
  618. }
  619. if (validCols.length === 0) { return; }
  620. const datas = [], posSelects = [];
  621. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  622. const node = sortData[iRow];
  623. if (node) {
  624. const data = {pid: node.id, lid: node.lid};
  625. for (const iCol of validCols) {
  626. const colSetting = sheet.zh_setting.cols[iCol];
  627. if (colSetting.field === 'name') {
  628. toast('部位名称不能为空', 'error');
  629. return;
  630. }
  631. data[colSetting.field] = null;
  632. }
  633. datas.push(data);
  634. posSelects.push(node);
  635. }
  636. }
  637. if (datas.length > 0) {
  638. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  639. if (result.pos) {
  640. stagePos.updateDatas(result.pos.pos);
  641. stagePos.loadCurStageData(result.pos.curStageData);
  642. }
  643. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  644. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  645. // todo 只加载改变项
  646. stagePosSpreadObj.loadCurPosData();
  647. });
  648. }
  649. }
  650. },
  651. };
  652. // 加载上下窗口resizer
  653. $.divResizer({
  654. select: '#main-resize',
  655. callback: function () {
  656. slSpread.refresh();
  657. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  658. $(".sp-wrap").height(bcontent-40);
  659. spSpread.refresh();
  660. }
  661. });
  662. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  663. postData(window.location.pathname + '/pos', null, function (result) {
  664. stagePos.loadDatas(result.pos);
  665. if (result.curStageData) {
  666. stagePos.loadCurStageData(result.curStageData);
  667. }
  668. if (result.preStageData) {
  669. stagePos.loadPreStageData(result.preStageData);
  670. }
  671. stagePos.calculateAll();
  672. stagePosSpreadObj.loadCurPosData();
  673. });
  674. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  675. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  676. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  677. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  678. $('#row-view').on('show.bs.modal', function () {
  679. const html = [], customDisplay = customColDisplay();
  680. for (const cd of customDisplay) {
  681. html.push('<tr>');
  682. html.push('<td>', cd.title, '</td>');
  683. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  684. html.push('</tr>');
  685. }
  686. $('#row-view-list').html(html.join(''));
  687. });
  688. $('#row-view-ok').click(function () {
  689. const customDisplay = customColDisplay();
  690. const cvl = $('#row-view-list').children();
  691. for (const cv of cvl) {
  692. const title = $(cv).children()[0].innerHTML;
  693. const check = $('input', cv)[0].checked;
  694. const cd = customDisplay.find(function (c) {
  695. return c.title === title;
  696. });
  697. cd.visible = check;
  698. }
  699. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  700. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  701. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  702. $('#row-view').modal('hide');
  703. });
  704. });