stage.js 31 KB

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