sp_data.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. $(document).ready(() => {
  2. autoFlashHeight();
  3. class QtyObj {
  4. constructor(setting) {
  5. this.spread = SpreadJsObj.createNewSpread(setting.obj);
  6. this.sheet = this.spread.getActiveSheet();
  7. SpreadJsObj.initSheet(this.sheet, setting.spreadSetting);
  8. if (setting.treeSetting) {
  9. this.tree = createNewPathTree('base', setting.treeSetting);
  10. this.tree.loadDatas(setting.data);
  11. } else {
  12. this.data = setting.data;
  13. }
  14. this.type = setting.type;
  15. if (setting.treeSetting) {
  16. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
  17. } else {
  18. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.data);
  19. }
  20. const self = this;
  21. this.sheet.bind(spreadNS.Events.EditEnded, function(e, info) {
  22. if (!info.sheet.zh_setting) {
  23. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  24. return;
  25. }
  26. const node = SpreadJsObj.getRowObject(info.sheet, info.row);
  27. if (!node || (self.tree && node.children && node.children.length > 0)) {
  28. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  29. return;
  30. }
  31. const col = info.sheet.zh_setting.cols[info.col];
  32. const data = {};
  33. data.id = node.id;
  34. const oldValue = node ? node[col.field] : null;
  35. const newValue = trimInvalidChar(info.editingText);
  36. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  37. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  38. return;
  39. }
  40. if (col.type === 'Number') {
  41. const num = _.toNumber(newValue);
  42. data[col.field] = num || 0;
  43. } else {
  44. data[col.field] = newValue;
  45. }
  46. postData('info/save', { type: self.type, updateData: [data]}, function (result) {
  47. self.loadUpdateData(result);
  48. SpreadJsObj.reLoadSheetData(info.sheet);
  49. }, function () {
  50. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  51. });
  52. });
  53. this.sheet.bind(spreadNS.Events.ClipboardPasting, function(e, info) {
  54. info.cancel = true;
  55. const setting = info.sheet.zh_setting;
  56. if (!setting) return;
  57. const pasteData = info.pasteData.html
  58. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  59. : (info.pasteData.text === ''
  60. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  61. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  62. const uDatas = [];
  63. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  64. const curRow = info.cellRange.row + iRow;
  65. const node = SpreadJsObj.getRowObject(info.sheet, curRow);
  66. if (self.tree && node.children && node.children.length > 0) continue;
  67. let bPaste = false;
  68. const data = {};
  69. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  70. const curCol = info.cellRange.col + iCol;
  71. const colSetting = setting.cols[curCol];
  72. const value = trimInvalidChar(pasteData[iRow][iCol]);
  73. if (colSetting.type === 'Number') {
  74. const num = _.toNumber(value);
  75. if (num) {
  76. data[colSetting.field] = num;
  77. bPaste = true;
  78. }
  79. } else {
  80. data[colSetting.field] = value;
  81. bPaste = true;
  82. }
  83. }
  84. if (bPaste) {
  85. if (node) {
  86. data.id = node.id;
  87. uDatas.push(data);
  88. }
  89. }
  90. }
  91. if (uDatas.length > 0) {
  92. postData('info/save', { type: self.type, updateData: uDatas}, function (result) {
  93. self.loadUpdateData(result);
  94. SpreadJsObj.reLoadSheetData(info.sheet);
  95. });
  96. } else {
  97. SpreadJsObj.reLoadSheetData(info.sheet);
  98. }
  99. });
  100. SpreadJsObj.addDeleteBind(this.spread, function(sheet) {
  101. if (!sheet.zh_setting) return;
  102. const datas = [];
  103. const sels = sheet.getSelections();
  104. if (!sels || !sels[0]) return;
  105. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  106. let bDel = false;
  107. const node = SpreadJsObj.getRowObject(sheet, iRow);
  108. if (node) {
  109. const data = { id: node.id };
  110. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  111. const style = sheet.getStyle(iRow, iCol);
  112. if (!style.locked) {
  113. const colSetting = sheet.zh_setting.cols[iCol];
  114. data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
  115. bDel = true;
  116. }
  117. }
  118. if (bDel) {
  119. datas.push(data);
  120. }
  121. }
  122. }
  123. if (datas.length === 0) return;
  124. postData('info/save', { type: self.type, updateData: datas}, function (result) {
  125. self.loadUpdateData(result);
  126. SpreadJsObj.reLoadSheetData(sheet);
  127. }, function () {
  128. SpreadJsObj.reLoadSheetData(sheet);
  129. });
  130. });
  131. }
  132. loadUpdateData(data) {
  133. for (const d of data) {
  134. const source = this.tree
  135. ? this.tree.getItems(d.id)
  136. : this.data.find(x => { return x.id === d.id });
  137. if (!source) continue;
  138. source.dgn_qty = d.dgn_qty;
  139. source.final_qty = d.final_qty;
  140. }
  141. }
  142. }
  143. const mainQtyObj = new QtyObj({
  144. obj: $('#main_qty_spread')[0],
  145. spreadSetting: {
  146. cols: [
  147. {title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true},
  148. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  149. {title: '设计', colSpan: '1', rowSpan: '1', field: 'dgn_qty', hAlign: 2, width: 100, type: 'Number'},
  150. {title: '竣工', colSpan: '1', rowSpan: '1', field: 'final_qty', hAlign: 2, width: 100, type: 'Number'},
  151. ],
  152. emptyRows: 0,
  153. headRows: 1,
  154. headRowHeight: [32],
  155. defaultRowHeight: 21,
  156. headerFont: '12px 微软雅黑',
  157. font: '12px 微软雅黑',
  158. readOnly: readOnly,
  159. },
  160. data: mainQty,
  161. isTree: false,
  162. type: 'main_quantity',
  163. readOnly: readOnly,
  164. });
  165. const gclQtyObj = new QtyObj({
  166. obj: $('#gcl_qty_spread')[0],
  167. spreadSetting: {
  168. cols: [
  169. {title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true, cellType: 'tree'},
  170. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  171. {title: '设计', colSpan: '1', rowSpan: '1', field: 'dgn_qty', hAlign: 2, width: 100, type: 'Number'},
  172. {title: '竣工', colSpan: '1', rowSpan: '1', field: 'final_qty', hAlign: 2, width: 100, type: 'Number'},
  173. ],
  174. emptyRows: 0,
  175. headRows: 1,
  176. headRowHeight: [32],
  177. defaultRowHeight: 21,
  178. headerFont: '12px 微软雅黑',
  179. font: '12px 微软雅黑',
  180. readOnly: readOnly,
  181. },
  182. data: gclQty,
  183. type: 'gcl_quantity',
  184. isTree: true,
  185. treeSetting: {
  186. id: 'id',
  187. pid: 'pid',
  188. order: 'order',
  189. level: 'level',
  190. fullPath: 'full_path',
  191. rootId: -1,
  192. },
  193. readOnly: readOnly,
  194. })
  195. });