stage.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. }
  170. _loadChangeDetail(change) {
  171. if (change) {
  172. if (change.cid === this.curChangeId) { return; }
  173. this.curChangeId = change.cid;
  174. const inputs = $('input[type!=checkbox]', this.obj);
  175. for (const i of inputs) {
  176. const field = $(i).attr('name');
  177. const text = (field && change[field]) ? change[field] : '';
  178. $(i).val(text);
  179. }
  180. const textareas = $('textarea', this.obj);
  181. for (const ta of textareas) {
  182. const field = $(ta).attr('name');
  183. const text = (field && change[field]) ? change[field] : '';
  184. ta.innerText = text;
  185. }
  186. const html = [];
  187. for (const a of change.attachments) {
  188. html.push('<tr>');
  189. html.push('<td>', a.filename + a.fileext, '</td>');
  190. html.push('<td>', a.u_name, '</td>');
  191. html.push('</tr>');
  192. }
  193. // 变更类型
  194. const cType = change.type.split(',');
  195. $('input[name="type"]').prop("checked", false);
  196. for (const c of cType) {
  197. $('input[name="type"][value='+ c +']').prop("checked", true);
  198. }
  199. // 变更类别
  200. $('select[name=class]').val(change.class);
  201. // 变更性质
  202. $('select[name=quality]').val(change.quality);
  203. // 变更单位
  204. $('select[name=company]').html('<option>' + change.company + '</option>');
  205. // 费用承担方
  206. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  207. // 附件
  208. $('#attachment').html(html.join(''));
  209. } else {
  210. const inputs = $('input', this.obj);
  211. for (const i of inputs) {
  212. $(i).val('');
  213. }
  214. const textareas = $('textarea', this.obj);
  215. for (const ta of textareas) {
  216. ta.innerText = '';
  217. }
  218. $('#attachment').html('');
  219. }
  220. }
  221. _viewChanges() {
  222. const sheet = this.spread.getActiveSheet();
  223. if (this.changes) {
  224. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
  225. sheet.setSelection(0, 0, 1, 1);
  226. this._loadChangeDetail(this.changes[0]);
  227. this._filterEmptyChange(!$('#customCheckDisabled')[0].checked);
  228. } else {
  229. toast('查询变更令有误,请刷新页面后重试', 'warning');
  230. }
  231. }
  232. _filterEmptyChange(isFilter) {
  233. for (const c of this.changes) {
  234. c.visible = isFilter ? (c.vamount || c.vamount === 0) : true;
  235. }
  236. SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
  237. }
  238. loadChanges(data) {
  239. this.callData = data;
  240. const self = this;
  241. postData(window.location.pathname + '/valid-change', data, function (result) {
  242. self.changes = result;
  243. self._viewChanges();
  244. self.obj.modal('show');
  245. });
  246. }
  247. }
  248. const changesObj = new Changes($('#use-bg'));
  249. // 初始化 台账 spread
  250. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  251. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  252. // 数量变更列,添加按钮
  253. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  254. col.readOnly = true;
  255. col.cellType = 'imageBtn';
  256. col.hoverImg = '#ellipsis-icon';
  257. col.indent = 5;
  258. col.showImage = function (data) {
  259. if (!data || (data.children && data.children.length > 0)) {
  260. return false;
  261. } else {
  262. const nodePos = stagePos.getLedgerPos(data.id);
  263. return !(nodePos && nodePos.length > 0);
  264. }
  265. };
  266. ledgerSpreadSetting.imageClick = function (data) {
  267. changesObj.loadChanges({bills: data});
  268. };
  269. //
  270. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  271. stageTree.loadDatas(ledgerData);
  272. stageTree.loadCurStageData(curStageData);
  273. stageTree.loadPreStageData(preStageData);
  274. // 根据设置 计算 台账树结构
  275. treeCalc.calculateAll(stageTree);
  276. // 绘制界面
  277. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  278. // 初始化 部位明细 Spread
  279. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  280. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  281. spCol.readOnly = true;
  282. spCol.cellType = 'imageBtn';
  283. spCol.hoverImg = '#ellipsis-icon';
  284. spCol.indent = 5;
  285. spCol.showImage = function (data) {
  286. return data;
  287. };
  288. posSpreadSetting.imageClick = function (data) {
  289. changesObj.loadChanges({pos: data});
  290. };
  291. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  292. const stageTreeSpreadObj = {
  293. refreshTreeNodes: function (sheet, nodes) {
  294. const tree = sheet.zh_tree;
  295. if (!tree) { return }
  296. const rows = [];
  297. for (const node of nodes) {
  298. rows.push(tree.nodes.indexOf(node));
  299. }
  300. SpreadJsObj.reLoadRowsData(sheet, rows);
  301. },
  302. editEnded: function (e, info) {
  303. if (info.sheet.zh_setting) {
  304. const col = info.sheet.zh_setting.cols[info.col];
  305. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  306. const node = sortData[info.row];
  307. if (node.children && node.children.length > 0) {
  308. toast('清单父项不可计量', 'error');
  309. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  310. return;
  311. } else {
  312. const nodePos = stagePos.getLedgerPos(node.id);
  313. if (nodePos && nodePos.length > 0) {
  314. toast('该清单有部位明细,请在部位明细处计量', 'error');
  315. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  316. return;
  317. }
  318. }
  319. const billsData = {
  320. lid: node.id
  321. };
  322. billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  323. postData(window.location.href + '/update', { bills: billsData }, function (data) {
  324. const nodes = stageTree.loadPostStageData(data.bills);
  325. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  326. });
  327. }
  328. },
  329. selectionChanged: function (e, info) {
  330. stagePosSpreadObj.loadCurPosData();
  331. },
  332. deletePress(sheet) {
  333. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  334. const tree = sheet.zh_tree;
  335. if (!tree) { return; }
  336. const sel = sheet.getSelections()[0];
  337. const validCols = [];
  338. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  339. if (!sheet.zh_setting.cols[iCol].readOnly) {
  340. validCols.push(iCol);
  341. }
  342. }
  343. if (validCols.length === 0) { return; }
  344. const sortData = sheet.zh_tree.nodes;
  345. const datas = [];
  346. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  347. const node = sortData[iRow];
  348. if (node) {
  349. if (node.children && node.children.length > 0) { continue; }
  350. const nodePos = stagePos.getLedgerPos(node.id);
  351. if (nodePos && nodePos.length > 0) { continue; }
  352. const data = { lid: node.id };
  353. for (const iCol of validCols) {
  354. const colSetting = sheet.zh_setting.cols[iCol];
  355. data[colSetting.field] = null;
  356. }
  357. datas.push(data);
  358. }
  359. }
  360. if (datas.length > 0) {
  361. postData(window.location.href + '/update', {bills: datas}, function (result) {
  362. const nodes = stageTree.loadPostStageData(result.bills);
  363. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  364. });
  365. }
  366. }
  367. },
  368. clipboardPasting(e, info) {
  369. if (info.sheet.zh_setting) {
  370. const sortData = info.sheet.zh_data;
  371. const range = info.cellRange;
  372. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  373. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  374. const col = info.sheet.zh_setting.cols[iCol];
  375. if (validField.indexOf(col.field) === -1) {
  376. toast('不可修改此数据', 'error');
  377. info.cancel = true;
  378. return;
  379. }
  380. }
  381. }
  382. },
  383. clipboardPasted(e, info) {
  384. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  385. const sheet = info.sheet;
  386. const filterNodes = [], datas = [];
  387. console.log(info.cellRange);
  388. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  389. const curRow = iRow + info.cellRange.row;
  390. const node = sheet.zh_tree.getItemsByIndex(curRow);
  391. if (node.children && node.children.length > 0) {
  392. filterNodes.push(node);
  393. continue;
  394. }
  395. const nodePos = stagePos.getLedgerPos(node.id);
  396. if (nodePos && nodePos.length > 0) {
  397. filterNodes.push(node);
  398. continue;
  399. }
  400. const data = {lid: node.id};
  401. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  402. const curCol = info.cellRange.col + iCol;
  403. const col = info.sheet.zh_setting.cols[curCol];
  404. data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  405. }
  406. datas.push(data);
  407. }
  408. console.log(datas);
  409. if (datas.length > 0) {
  410. postData(window.location.href + '/update', { bills: datas }, function (data) {
  411. const nodes = stageTree.loadPostStageData(data.bills);
  412. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  413. });
  414. } else {
  415. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  416. }
  417. }
  418. }
  419. };
  420. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  421. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  422. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  423. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  424. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  425. const stagePosSpreadObj = {
  426. /**
  427. * 加载部位明细 根据当前台账选择节点
  428. */
  429. loadCurPosData: function () {
  430. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  431. if (node) {
  432. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  433. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  434. } else {
  435. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  436. }
  437. },
  438. editEnded: function (e, info) {
  439. if (info.sheet.zh_setting) {
  440. // 未改变过,则直接跳过
  441. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  442. const col = info.sheet.zh_setting.cols[info.col];
  443. const orgText = posData ? posData[col.field] : null;
  444. if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
  445. return;
  446. }
  447. // 台账模式下,不可新增
  448. if (checkTzMeasureType() && !posData) {
  449. toast('台账模式不可新增部位明细数据', 'error');
  450. info.cancel = true;
  451. return ;
  452. }
  453. // 不同节点下,部位明细检查输入
  454. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  455. if (!node) {
  456. toast('数据错误, 请刷新页面后再试', 'warning');
  457. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  458. return;
  459. } else if (info.editingText !== '' && node.children && node.children > 0) {
  460. toast('父节点不可插入部位明细', 'error');
  461. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  462. return;
  463. } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
  464. toast('项目节不可插入部位明细', 'error');
  465. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  466. return;
  467. }
  468. // 生成提交数据
  469. const data = {};
  470. if (col.field === 'name') {
  471. if (info.editingText === '' && pos) {
  472. toast('部位名称不可为空', 'error', 'exclamation-circle');
  473. info.cancel = true;
  474. return;
  475. } else if (!pos) {
  476. if (info.editingText !== '') {
  477. data.updateType = 'add';
  478. data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
  479. } else {
  480. return;
  481. }
  482. } else {
  483. data.updateType = 'update';
  484. data.updateData = {id: posData.id, name: info.editingText};
  485. }
  486. } else if (!posData) {
  487. toast('新增部位请先输入名称', 'warning');
  488. } else {
  489. data.updateType = 'update';
  490. data.updateData = {pid: posData.id, lid: posData.lid};
  491. data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  492. }
  493. // 提交数据到服务器
  494. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  495. if (result.pos) {
  496. stagePos.updateDatas(result.pos.pos);
  497. stagePos.loadCurStageData(result.pos.curStageData);
  498. }
  499. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  500. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  501. stagePosSpreadObj.loadCurPosData();
  502. }, function () {
  503. stagePosSpreadObj.loadCurPosData();
  504. });
  505. }
  506. },
  507. clipboardPasting: function (e, info) {
  508. if (info.sheet.zh_setting) {
  509. const sortData = info.sheet.zh_data;
  510. const range = info.cellRange;
  511. const validField = ['contract_qty', 'qc_qty', 'postil'];
  512. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  513. const col = info.sheet.zh_setting.cols[iCol];
  514. if (validField.indexOf(col.field) === -1) {
  515. if (checkTzMeasureType()) {
  516. toast('不可修改此数据', 'error');
  517. info.cancel = true;
  518. return;
  519. } else {
  520. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  521. const pos = sortData(iRow);
  522. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  523. toast('不可修改此数据', 'error');
  524. info.cancel = true;
  525. return;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. },
  533. clipboardPasted: function (e, info) {
  534. const self = this;
  535. if (info.sheet.zh_setting) {
  536. const data = { updateType: '', updateData: [], };
  537. const sortData = info.sheet.zh_data;
  538. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  539. if (sortData && (info.cellRange.row >= sortData.length)) {
  540. data.updateType = 'add';
  541. if (info.cellRange.col !== 0) {
  542. toast('新增部位请先输入名称', 'warning');
  543. self.loadCurPosData();
  544. return;
  545. }
  546. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  547. const curRow = info.cellRange.row + iRow;
  548. const newData = {lid: node.id};
  549. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  550. const curCol = info.cellRange.col + iCol;
  551. const colSetting = info.sheet.zh_setting.cols[curCol];
  552. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  553. if (colSetting.type === 'Number') {
  554. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  555. }
  556. }
  557. data.updateData.push(newData);
  558. }
  559. } else {
  560. data.updateType = 'update';
  561. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  562. const curRow = info.cellRange.row + iRow;
  563. const curPos = sortData[curRow];
  564. if (curPos) {
  565. const newData = {pid: curPos.id, lid: curPos.lid};
  566. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  567. const curCol = info.cellRange.col + iCol;
  568. const colSetting = info.sheet.zh_setting.cols[curCol];
  569. newData[colSetting.field] = info.sheet.getText(curRow, curCol);
  570. if (colSetting.type === 'Number') {
  571. newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
  572. }
  573. }
  574. data.updateData.push(newData);
  575. }
  576. }
  577. }
  578. console.log(data);
  579. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  580. if (result.pos) {
  581. stagePos.updateDatas(result.pos.pos);
  582. stagePos.loadCurStageData(result.pos.curStageData);
  583. }
  584. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  585. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  586. stagePosSpreadObj.loadCurPosData();
  587. }, function () {
  588. stagePosSpreadObj.loadCurPosData();
  589. });
  590. }
  591. },
  592. deletePress: function (sheet) {
  593. if (sheet.zh_setting && sheet.zh_data) {
  594. const sortData = sheet.zh_data;
  595. if (!sortData || sortData.length === 0) { return; }
  596. const sel = sheet.getSelections()[0];
  597. const validCols = [];
  598. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  599. if (!sheet.zh_setting.cols[iCol].readOnly) {
  600. validCols.push(iCol);
  601. }
  602. }
  603. if (validCols.length === 0) { return; }
  604. const datas = [], posSelects = [];
  605. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  606. const node = sortData[iRow];
  607. if (node) {
  608. const data = {pid: node.id, lid: node.lid};
  609. for (const iCol of validCols) {
  610. const colSetting = sheet.zh_setting.cols[iCol];
  611. if (colSetting.field === 'name') {
  612. toast('部位名称不能为空', 'error');
  613. return;
  614. }
  615. data[colSetting.field] = null;
  616. }
  617. datas.push(data);
  618. posSelects.push(node);
  619. }
  620. }
  621. if (datas.length > 0) {
  622. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  623. if (result.pos) {
  624. stagePos.updateDatas(result.pos.pos);
  625. stagePos.loadCurStageData(result.pos.curStageData);
  626. }
  627. const nodes = stageTree.loadPostStageData(result.ledger.curStageData);
  628. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  629. // todo 只加载改变项
  630. stagePosSpreadObj.loadCurPosData();
  631. });
  632. }
  633. }
  634. },
  635. };
  636. // 加载上下窗口resizer
  637. $.divResizer({
  638. select: '#main-resize',
  639. callback: function () {
  640. slSpread.refresh();
  641. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  642. $(".sp-wrap").height(bcontent-40);
  643. spSpread.refresh();
  644. }
  645. });
  646. // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  647. postData(window.location.pathname + '/pos', null, function (result) {
  648. stagePos.loadDatas(result.pos);
  649. if (result.curStageData) {
  650. stagePos.loadCurStageData(result.curStageData);
  651. }
  652. if (result.preStageData) {
  653. stagePos.loadPreStageData(result.preStageData);
  654. }
  655. stagePos.calculateAll();
  656. stagePosSpreadObj.loadCurPosData();
  657. });
  658. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  659. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  660. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  661. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  662. $('#row-view').on('show.bs.modal', function () {
  663. const html = [], customDisplay = customColDisplay();
  664. for (const cd of customDisplay) {
  665. html.push('<tr>');
  666. html.push('<td>', cd.title, '</td>');
  667. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  668. html.push('</tr>');
  669. }
  670. $('#row-view-list').html(html.join(''));
  671. });
  672. $('#row-view-ok').click(function () {
  673. const customDisplay = customColDisplay();
  674. const cvl = $('#row-view-list').children();
  675. for (const cv of cvl) {
  676. const title = $(cv).children()[0].innerHTML;
  677. const check = $('input', cv)[0].checked;
  678. const cd = customDisplay.find(function (c) {
  679. return c.title === title;
  680. });
  681. cd.visible = check;
  682. }
  683. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  684. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  685. Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
  686. $('#row-view').modal('hide');
  687. });
  688. });