sub_view.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /**
  2. * Created by CSL on 2017-07-04.
  3. */
  4. //modified by zhong on 2017-08-30
  5. // Tab panes 下有多个Spread时,相互之间不能正确显示。改成一个Spread下多个Sheet。
  6. //特征及内容spread,解决不能正确显示spread
  7. //zhang 5-31 删除附注条件、辅助定额tab,增加子目换算tab
  8. contentOprObj.buildSheet($("#jobSpread")[0]);
  9. characterOprObj.buildSheet($("#itemSpread")[0]);
  10. $("#tzjnrCon").hide();
  11. $("#subSpread").show();
  12. var subSpread = sheetCommonObj.createSpread($("#subSpread")[0], 4);
  13. subSpread.options.allowUserDragDrop = false;
  14. subSpread.options.allowUserDragFill = false;
  15. subSpread.getSheet(2).name('JSCX');
  16. pageCCOprObj.active = false;
  17. // 工料机
  18. gljOprObj.initSheet(subSpread.getSheet(0));
  19. //sheetCommonObj.shieldAllCells(subSpread.getSheet(0), gljOprObj.setting);
  20. SheetDataHelper.protectdSheet(subSpread.getSheet(0));
  21. // assistOprObj.initSheet(subSpread.getSheet(1));
  22. // sheetCommonObj.shieldAllCells(subSpread.getSheet(1), assistOprObj.setting);
  23. //工程量明细
  24. gljOprObj.initDetailSheet(subSpread.getSheet(1));
  25. SheetDataHelper.protectdSheet(subSpread.getSheet(1));
  26. //安装增加费
  27. installationFeeObj.initRationInstallSheet(subSpread.getSheet(3));
  28. SheetDataHelper.protectdSheet(subSpread.getSheet(3));
  29. if(!projectReadOnly){
  30. gljContextMenu.loadGLJSpreadContextMenu();
  31. }
  32. $("#linkGLJ").click(function(){
  33. $("#subItems").children().hide();//控制显示subSpread,隐藏特征及内容spread
  34. $("#subSpread").show();
  35. pageCCOprObj.active = false;
  36. subSpread.options.allowUserDragFill = false;
  37. refreshSubSpread();
  38. subSpread.setActiveSheetIndex(0);
  39. gljOprObj.activeTab='#linkGLJ';
  40. // for test
  41. //subSpread.getActiveSheet().setValue(0, 0, "工料机");
  42. });
  43. $("#linkAZZJF").click(function(){
  44. $("#subItems").children().hide();
  45. $("#subSpread").show();
  46. pageCCOprObj.active = false;
  47. refreshSubSpread();
  48. subSpread.setActiveSheetIndex(3);
  49. gljOprObj.activeTab='#linkAZZJF';
  50. });
  51. $("#linkGCLMX").click(function(){
  52. $("#subItems").children().hide();
  53. $("#subSpread").show();
  54. subSpread.options.allowUserDragFill = true;
  55. pageCCOprObj.active = false;
  56. refreshSubSpread();
  57. subSpread.setActiveSheetIndex(1);
  58. gljOprObj.activeTab='#linkGCLMX';
  59. });
  60. $("#linkJSCX").click(function(){ // 计算程序
  61. $("#subItems").children().hide();
  62. $("#subSpread").show();
  63. pageCCOprObj.active = false;
  64. refreshSubSpread();
  65. subSpread.setActiveSheetIndex(2);
  66. calcProgramObj.initSheet(subSpread.getSheet(2));
  67. if (!projectObj.mainController.tree.selected)
  68. projectObj.mainController.tree.selected = projectObj.mainController.tree.firstNode();
  69. let sel = projectObj.mainController.tree.selected;
  70. calcProgramObj.showData(sel);
  71. gljOprObj.activeTab='#linkJSCX';
  72. });
  73. $("#linkZMHS").click(function(){ // 子目换算
  74. $("#subItems").children().hide();
  75. $("#tabZMHS").show();
  76. pageCCOprObj.active = false;
  77. refreshSubSpread();
  78. gljOprObj.activeTab='#linkZMHS';
  79. });
  80. tabZMHS
  81. //特征及内容
  82. $("#linkTZJNR").click(function () {
  83. $("#subItems").children().hide();
  84. $("#tzjnrCon").show();
  85. $("#add-rule").show();
  86. $("#add-rule p").not(":first").css('margin-bottom', 4);
  87. pageCCOprObj.active = true;
  88. refreshSubSpread();
  89. let selectedNode = projectObj.mainController.tree.selected;
  90. if (projectObj.project.property.addRule !== undefined) {
  91. setRule(projectObj.project.property.addRule);
  92. }
  93. pageCCOprObj.mainActiveCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  94. pageCCOprObj.setCacheAndShow(selectedNode);
  95. /* if(selectedNode && selectedNode.sourceType === projectObj.project.Bills.getSourceType()){
  96. pageCCOprObj.setCacheAndShow(selectedNode);
  97. }
  98. else{
  99. pageCCOprObj.clearData();
  100. }*/
  101. gljOprObj.activeTab='#linkTZJNR';
  102. });
  103. // 应用到选中清单
  104. let isSaving = false;
  105. $("#use-to-current").click(function() {
  106. if(projectReadOnly){
  107. return false;
  108. }
  109. if (isSaving) {
  110. return false;
  111. }
  112. const setting = getAddRuleSetting();
  113. isSaving = true;
  114. const self = $(this);
  115. self.attr('disabled', 'disabled');
  116. let selectedNode = projectObj.mainController.tree.selected;
  117. function findBill(node){
  118. while(node && node.sourceType !== projectObj.project.Bills.getSourceType()){
  119. node = node.parent;
  120. }
  121. return node;
  122. }
  123. let billsNode = findBill(selectedNode);
  124. // 操作内容
  125. pageCCOprObj.setCharacterBySetting(billsNode, setting);
  126. // 防止连续点击1秒后才能再次发起请求
  127. setTimeout(function() {
  128. isSaving = false;
  129. self.removeAttr('disabled');
  130. }, 1000);
  131. });
  132. // 应用到所有的清单
  133. $("#use-to-all").click(function() {
  134. if(projectReadOnly){
  135. return false;
  136. }
  137. let treeNode = projectObj.mainController.tree;
  138. const setting = getAddRuleSetting();
  139. if (treeNode.items === undefined || treeNode.items.length <= 0) {
  140. return false;
  141. }
  142. // 处理结果
  143. for (const item of treeNode.items) {
  144. if (item.data.jobContent === undefined || item.data.jobContent.length <= 0 ||
  145. item.data.itemCharacter === undefined || item.data.itemCharacter.length <= 0 || item.data.code === undefined) {
  146. continue;
  147. }
  148. pageCCOprObj.setCharacterBySetting(item, setting);
  149. }
  150. });
  151. // 添加位置选择
  152. $("#add-position").change(function() {
  153. const selected = $(this).children(":selected").val();
  154. const addContentEle = $("#add-content");
  155. const displayFormatEle = $("#display-format");
  156. const characterFormatEle = $("#character-format");
  157. const serialTypeEle = $("#serial-type");
  158. switch (selected) {
  159. case '4':
  160. // 分别添加到对应列
  161. // 当“添加位置”是“分别添加到对应列”,则“添加内容”恢复默认“无”,且灰显;“显示格式”恢复默认“换行分隔”,且灰显。
  162. addContentEle.val('');
  163. addContentEle.attr('disabled', 'disabled');
  164. displayFormatEle.val(1);
  165. characterFormatEle.val(2);
  166. serialTypeEle.val(1);
  167. break;
  168. default:
  169. addContentEle.removeAttr('disabled');
  170. displayFormatEle.removeAttr('disabled');
  171. characterFormatEle.removeAttr('disabled');
  172. addContentEle.val(1);
  173. break;
  174. }
  175. });
  176. // 添加内容选择
  177. $("#add-content").change(function() {
  178. const selected = $(this).children(":selected").val();
  179. const characterFormatEle = $("#character-format");
  180. const childDisplayFormatEle = $("#child-display-format");
  181. const serialTypeEle = $("#serial-type");
  182. switch (selected) {
  183. case '5':
  184. // 当“添加内容”是“定额子目”或“工作内容”,则“特征生成方式”灰显,不需选择;否则有效可选。
  185. characterFormatEle.attr('disabled', 'disabled');
  186. characterFormatEle.val(2);
  187. // 当“添加内容”是“定额子目”,则“子目生成方式”有效可选;否则灰显,不需选择。
  188. childDisplayFormatEle.removeAttr('disabled');
  189. serialTypeEle.val('');
  190. serialTypeEle.attr('disabled', 'disabled');
  191. break;
  192. case '1':
  193. case '2':
  194. case '3':
  195. characterFormatEle.removeAttr('disabled');
  196. if (serialTypeEle.val() === '') {
  197. serialTypeEle.val(1);
  198. }
  199. serialTypeEle.removeAttr('disabled');
  200. childDisplayFormatEle.attr('disabled', 'disabled');
  201. break;
  202. case '4':
  203. // 当“添加内容”是“定额子目”或“工作内容”,则“特征生成方式”灰显,不需选择;否则有效可选。
  204. characterFormatEle.attr('disabled', 'disabled');
  205. characterFormatEle.val(2);
  206. default:
  207. serialTypeEle.removeAttr('disabled');
  208. if (serialTypeEle.val() === '') {
  209. serialTypeEle.val(1);
  210. }
  211. childDisplayFormatEle.attr('disabled', 'disabled');
  212. break;
  213. }
  214. });
  215. // 子目生成方式选择事件
  216. $("#child-display-format").change(function() {
  217. const selected = $(this).children(":selected").val();
  218. const serialTypeEle = $("#serial-type");
  219. // 如果是编号+定额名称则序号格式不能选择
  220. if (selected === '1') {
  221. // 默认选中数字显示模式
  222. serialTypeEle.val("");
  223. serialTypeEle.attr('disabled', 'disabled');
  224. } else {
  225. serialTypeEle.val(1);
  226. serialTypeEle.removeAttr('disabled');
  227. }
  228. });
  229. /**
  230. * 获取添加规则的设置
  231. *
  232. * @return {Object} - 返回设置内容
  233. */
  234. function getAddRuleSetting() {
  235. // 添加位置
  236. const position = $("#add-position").val();
  237. // 添加内容
  238. const addContent = $("#add-content").val();
  239. // 显示格式
  240. const displayFormat = $("#display-format").val();
  241. // 特征生成方式
  242. const characterFormat = $("#character-format").val();
  243. // 子目生成方式
  244. const childDisplayFormat = $("#child-display-format").val();
  245. // 序号格式
  246. const serialType = $("#serial-type").val();
  247. const setting = {
  248. serialType,
  249. characterFormat,
  250. addContent,
  251. position,
  252. displayFormat,
  253. childDisplayFormat,
  254. };
  255. return setting;
  256. }
  257. /**
  258. * 根据配置设置规则
  259. *
  260. * @param {Object} setting - 数据库中读取的数据
  261. * @return {void}
  262. */
  263. function setRule(setting) {
  264. if (Object.keys(setting).length <= 0) {
  265. return;
  266. }
  267. $("#add-position").val(setting.position);
  268. $("#add-position").change();
  269. $("#add-content").val(setting.addContent);
  270. $("#add-content").change();
  271. $("#display-format").val(setting.displayFormat);
  272. $("#character-format").val(setting.characterFormat);
  273. $("#child-display-format").val(setting.childDisplayFormat);
  274. $("#child-display-format").change();
  275. $("#serial-type").val(setting.serialType);
  276. if(projectReadOnly){
  277. disableTools();
  278. }
  279. }
  280. function activeSubSheetIs(idx){
  281. let rst = subSpread.getActiveSheetIndex() == idx;
  282. return rst;
  283. }
  284. //弹出清单规则或定额库后导致subSpread和特征及内容spread显示出问题
  285. function refreshSubSpread(){
  286. if(pageCCOprObj.active){
  287. contentOprObj.workBook.refresh();
  288. characterOprObj.workBook.refresh();
  289. }
  290. else{
  291. subSpread.refresh();
  292. }
  293. }
  294. let subViewObj = {
  295. linkTabClick: function () {
  296. $("#subItems").children().hide();
  297. $($(this).attr('href')).show();
  298. },
  299. loadComments: function (node) {
  300. let comments = [];
  301. let commentText = '';
  302. if (node) {
  303. if (node.sourceType === projectObj.project.Bills.getSourceType() &&
  304. (node.data.type === billType.FX || node.data.type === billType.BX || node.data.type === billType.BILL)) {
  305. if(node.data.comments && node.data.comments !== ''){
  306. comments.push('清单注释:');
  307. comments.push(node.data.comments);
  308. }
  309. if(node.data.ruleText && node.data.ruleText !== ''){
  310. comments.push('工程量计算规则:');
  311. comments.push(node.data.ruleText);
  312. }
  313. } else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
  314. if(node.data.content && node.data.content !== ''){
  315. comments.push('工作内容:');
  316. comments.push(node.data.content);
  317. }
  318. if(node.data.annotation && node.data.annotation !== ''){
  319. comments.push('附注:');
  320. comments.push(node.data.annotation);
  321. }
  322. }
  323. commentText = comments.join('\n');
  324. }
  325. $('#comments>textarea').val(commentText);
  326. },
  327. saveComments: function (node) {
  328. let text = $('#comments>textarea').val();
  329. if (node && node.sourceType === projectObj.project.Bills.getSourceType()) {
  330. if (node.data.comments !== text) {
  331. projectObj.project.Bills.updateField(node.source, "comments", text);
  332. }
  333. } else if (node && node.sourceType === projectObj.project.Ration.getSourceType()) {
  334. if (node.data.comments !== text) {
  335. projectObj.project.Ration.updateField(node.source, "comments", text);
  336. }
  337. }
  338. }
  339. }
  340. $("#linkComments").click(subViewObj.linkTabClick);
  341. $('#linkGLJ').on('shown.bs.tab', function () {
  342. gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected, '111111');
  343. });
  344. $('#linkZMHS').on('shown.bs.tab', function (e) {
  345. if(zmhs_obj.coeSpread == null || zmhs_obj.assSpread == null){
  346. zmhs_obj.initSpread();
  347. }
  348. zmhs_obj.refresh();
  349. zmhs_obj.showZMHSData();
  350. });
  351. $('#linkComments').on('shown.bs.tab', function () {
  352. subViewObj.loadComments(projectObj.project.mainTree.selected);
  353. });
  354. $('#linkGCLMX').on('shown.bs.tab', function () {
  355. gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected, '111111');
  356. });
  357. $('#linkAZZJF').on('shown.bs.tab', function () {
  358. gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected, '111111');
  359. });
  360. if(projectReadOnly){
  361. disableSpread(subSpread);
  362. disableSpread(contentOprObj.workBook);
  363. disableSpread(characterOprObj.workBook);
  364. }