sp_data.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. if (num) {
  43. data[col.field] = num;
  44. }
  45. } else {
  46. data[col.field] = newValue;
  47. }
  48. postData('info/save', { type: self.type, updateData: [data]}, function (result) {
  49. self.loadUpdateData(result);
  50. SpreadJsObj.reLoadSheetData(info.sheet);
  51. }, function () {
  52. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  53. });
  54. });
  55. this.sheet.bind(spreadNS.Events.ClipboardPasting, function(e, info) {
  56. info.cancel = true;
  57. const setting = info.sheet.zh_setting;
  58. if (!setting) return;
  59. const pasteData = info.pasteData.html
  60. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  61. : (info.pasteData.text === ''
  62. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  63. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  64. const uDatas = [];
  65. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  66. const curRow = info.cellRange.row + iRow;
  67. const node = SpreadJsObj.getRowObject(info.sheet, curRow);
  68. if (self.tree && node.children && node.children.length > 0) continue;
  69. let bPaste = false;
  70. const data = {};
  71. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  72. const curCol = info.cellRange.col + iCol;
  73. const colSetting = setting.cols[curCol];
  74. const value = trimInvalidChar(pasteData[iRow][iCol]);
  75. if (colSetting.type === 'Number') {
  76. const num = _.toNumber(value);
  77. if (num) {
  78. data[colSetting.field] = num;
  79. bPaste = true;
  80. }
  81. } else {
  82. data[colSetting.field] = value;
  83. bPaste = true;
  84. }
  85. }
  86. if (bPaste) {
  87. if (node) {
  88. data.id = node.id;
  89. uDatas.push(data);
  90. }
  91. }
  92. }
  93. if (uDatas.length > 0) {
  94. postData('info/save', { type: self.type, updateData: uDatas}, function (result) {
  95. self.loadUpdateData(result);
  96. SpreadJsObj.reLoadSheetData(info.sheet);
  97. });
  98. } else {
  99. SpreadJsObj.reLoadSheetData(info.sheet);
  100. }
  101. });
  102. SpreadJsObj.addDeleteBind(this.spread, function(sheet) {
  103. if (!sheet.zh_setting) return;
  104. const datas = [];
  105. const sels = sheet.getSelections();
  106. if (!sels || !sels[0]) return;
  107. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  108. let bDel = false;
  109. const node = SpreadJsObj.getRowObject(info.sheet, iRow);
  110. if (node) {
  111. const data = { id: node.id };
  112. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  113. const style = sheet.getStyle(iRow, iCol);
  114. if (!style.locked) {
  115. const colSetting = sheet.zh_setting.cols[iCol];
  116. data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
  117. bDel = true;
  118. }
  119. }
  120. if (bDel) {
  121. datas.push(data);
  122. }
  123. }
  124. }
  125. if (datas.length === 0) return;
  126. postData('info/save', { type: self.type, updateData: datas}, function (result) {
  127. self.loadUpdateData(result);
  128. SpreadJsObj.reLoadSheetData(sheet);
  129. }, function () {
  130. SpreadJsObj.reLoadSheetData(sheet);
  131. });
  132. });
  133. }
  134. loadUpdateData(data) {
  135. for (const d of data) {
  136. const source = this.tree
  137. ? this.tree.getItems(d.id)
  138. : this.data.find(x => { return x.id === d.id });
  139. if (!source) continue;
  140. source.dgn_qty = d.dgn_qty;
  141. source.final_qty = d.final_qty;
  142. }
  143. }
  144. }
  145. const mainQtyObj = new QtyObj({
  146. obj: $('#main_qty_spread')[0],
  147. spreadSetting: {
  148. cols: [
  149. {title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true},
  150. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  151. {title: '设计', colSpan: '1', rowSpan: '1', field: 'dgn_qty', hAlign: 2, width: 100, type: 'Number'},
  152. {title: '竣工', colSpan: '1', rowSpan: '1', field: 'final_qty', hAlign: 2, width: 100, type: 'Number'},
  153. ],
  154. emptyRows: 0,
  155. headRows: 1,
  156. headRowHeight: [32],
  157. defaultRowHeight: 21,
  158. headerFont: '12px 微软雅黑',
  159. font: '12px 微软雅黑',
  160. },
  161. data: mainQty,
  162. isTree: false,
  163. type: 'main_quantity',
  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. },
  181. data: gclQty,
  182. type: 'gcl_quantity',
  183. isTree: true,
  184. treeSetting: {
  185. id: 'id',
  186. pid: 'pid',
  187. order: 'order',
  188. level: 'level',
  189. fullPath: 'full_path',
  190. rootId: -1,
  191. }
  192. })
  193. });