qingdan.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <meta http-equiv="x-ua-compatible" content="ie=edge">
  7. <title>清单规则编辑器</title>
  8. <link rel="stylesheet" href="/lib/bootstrap/css/bootstrap.min.css">
  9. <link rel="stylesheet" href="/web/maintain/bills_lib/css/main.css">
  10. <link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
  11. <!--spread-->
  12. <link rel="stylesheet" href="/lib/spreadjs/sheets/css/gc.spread.sheets.excel2013lightGray.10.0.1.css">
  13. </head>
  14. <body>
  15. <div class="header">
  16. <nav class="navbar navbar-toggleable-lg navbar-light bg-faded p-0 ">
  17. <span class="header-logo px-2">清单规则编辑器</span>
  18. <div class="navbar-text"></div>
  19. </nav>
  20. <nav class="navbar navbar-toggleable-lg justify-content-between navbar-light p-0">
  21. <ul class="nav nav-tabs" role="tablist">
  22. <li class="nav-item">
  23. <a class="nav-link active px-3" href="javascript: void(0);">清单</a>
  24. </li>
  25. <li class="nav-item">
  26. <a id="aStdJobs" class="nav-link px-3" href="stdJobs">工作内容</a>
  27. </li>
  28. <li class="nav-item">
  29. <a id="aStdItems" class="nav-link px-3" href="stdItems">项目特征</a>
  30. </li>
  31. </ul>
  32. </nav>
  33. </div>
  34. <div class="main">
  35. <div class="content" >
  36. <div class="container-fluid">
  37. <div class="row">
  38. <div class="main-content col-lg-7 p-0">
  39. <nav class="navbar sticky-top navbar-toggleable-md navbar-light bg-faded tools-bar">
  40. <div class="collapse navbar-collapse" id="navbarNav">
  41. <ul class="navbar-nav">
  42. <li class="nav-item">
  43. <a class="nav-link text-primary" doing="false" fcsOnBills="true" id="insert" href="javascript: void(0);"><i class="fa fa-share" aria-hidden="true"></i>插入</a>
  44. </li>
  45. <li class="nav-item">
  46. <a class="nav-link text-primary" doing="false" fcsOnBills="true" id ="delete" href="javascript:void (0)"><i class="fa fa-remove" aria-hidden="true"></i>删除</a>
  47. </li>
  48. <li class="nav-item">
  49. <a class="nav-link text-primary" doing="false" fcsOnBills="true" id="upLevel" href="javascript: void(0);"><i class="fa fa-arrow-left" aria-hidden="true"></i>升级</a>
  50. </li>
  51. <li class="nav-item">
  52. <a class="nav-link text-primary" doing="false" fcsOnBills="true" id="downLevel" href="javascript: void(0);"><i class="fa fa-arrow-right" aria-hidden="true"></i>降级</a>
  53. </li>
  54. <li class="nav-item">
  55. <a class="nav-link text-primary" doing="false" fcsOnBills="true" canMove="false" id="upMove" href="javascript: void(0);"><i class="fa fa-arrow-up" aria-hidden="true"></i>上移</a>
  56. </li>
  57. <li class="nav-item">
  58. <a class="nav-link text-primary" doing="false" fcsOnBills="true" canMove="false" id="downMove" href="javascript: void(0);"><i class="fa fa-arrow-down" aria-hidden="true"></i>下移</a>
  59. </li>
  60. </ul>
  61. </div>
  62. </nav>
  63. <div class="main-data" id="spreadBills">
  64. </div>
  65. </div>
  66. <div class="main-side col-lg-5 p-0">
  67. <div class="container-fluid">
  68. <div class="row">
  69. <div class="col" style="width:50%; height: 100%">
  70. <h5>工作内容</h5>
  71. <div id="spreadJobs" style="width:97%; height: 300px;"></div>
  72. </div>
  73. <div class="col" style="width:50%; height: 100%">
  74. <h5>项目特征</h5>
  75. <div id="spreadItems" style="width: 97%; height: 300px;"></div>
  76. </div>
  77. <div class="w-100"></div>
  78. <div class="col">
  79. <div class="form-group">
  80. <label for="exampleTextarea"><h5>补注:</h5></label>
  81. <textarea class="form-control" id="exampleTextarea" rows="8"></textarea>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <!--弹出添加-->
  92. <div class="modal fade" id="add" data-backdrop="static" style="display: none;" aria-hidden="true">
  93. <div class="modal-dialog" role="document">
  94. <div class="modal-content">
  95. <div class="modal-header">
  96. <h5 class="modal-title">添加定额</h5>
  97. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  98. <span aria-hidden="true">×</span>
  99. </button>
  100. </div>
  101. <div class="modal-body">
  102. <form>
  103. <div class="form-group">
  104. <label>编码</label>
  105. <input class="form-control" placeholder="输入编码" type="text">
  106. </div>
  107. <div class="form-group">
  108. <label>名称</label>
  109. <input class="form-control" placeholder="输入名称" type="text">
  110. </div>
  111. <div class="form-group">
  112. <label>单位</label>
  113. <select class="form-control"><option>选择单位</option><option>m3</option></select>
  114. </div>
  115. <div class="form-group">
  116. <label>基价</label>
  117. <input class="form-control" placeholder="输入基价" type="number">
  118. </div>
  119. <div class="form-group">
  120. <label>显示名称(以%s表示参数)</label>
  121. <input class="form-control" placeholder="输入显示名称" type="text">
  122. </div>
  123. <div class="form-group">
  124. <label>默认取费专业</label>
  125. <input class="form-control" placeholder="输入取费专业" type="text">
  126. </div>
  127. </form>
  128. </div>
  129. <div class="modal-footer">
  130. <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
  131. <a href="" class="btn btn-primary">添加</a>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <!--弹出编辑-->
  137. <div class="modal fade" id="edit" data-backdrop="static" style="display: none;" aria-hidden="true">
  138. <div class="modal-dialog" role="document">
  139. <div class="modal-content">
  140. <div class="modal-header">
  141. <h5 class="modal-title">编辑定额</h5>
  142. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  143. <span aria-hidden="true">×</span>
  144. </button>
  145. </div>
  146. <div class="modal-body">
  147. <form>
  148. <div class="form-group">
  149. <label>编码</label>
  150. <input class="form-control" placeholder="输入编码" type="text" value="AA0001">
  151. </div>
  152. <div class="form-group">
  153. <label>名称</label>
  154. <input class="form-control" placeholder="输入名称" type="text" value="人工挖土方">
  155. </div>
  156. <div class="form-group">
  157. <label>单位</label>
  158. <select class="form-control"><option>m3</option></select>
  159. </div>
  160. <div class="form-group">
  161. <label>基价</label>
  162. <input class="form-control" placeholder="输入基价" type="number" value="880.84">
  163. </div>
  164. <div class="form-group">
  165. <label>显示名称(以%s表示参数)</label>
  166. <input class="form-control" placeholder="输入显示名称" type="text" value="人工挖土方">
  167. </div>
  168. <div class="form-group">
  169. <label>默认取费专业</label>
  170. <input class="form-control" placeholder="输入取费专业" type="text" value="1">
  171. </div>
  172. </form>
  173. </div>
  174. <div class="modal-footer">
  175. <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
  176. <a href="" class="btn btn-primary">确定</a>
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. <!--弹出删除-->
  182. <div class="modal fade" id="del" data-backdrop="static" style="display: none;" aria-hidden="true">
  183. <div class="modal-dialog" role="document">
  184. <div class="modal-content">
  185. <div class="modal-header">
  186. <h5 class="modal-title">删除确认</h5>
  187. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  188. <span aria-hidden="true">×</span>
  189. </button>
  190. </div>
  191. <div class="modal-body">
  192. <h5 class="text-danger">删除后无法恢复,确认是否删除?</h5>
  193. </div>
  194. <div class="modal-footer">
  195. <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
  196. <a href="" class="btn btn-danger">删除</a>
  197. </div>
  198. </div>
  199. </div>
  200. </div>
  201. <!--弹出提示窗口-->
  202. <button id="alertBtn" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#alertDiv" style="display: none"></button>
  203. <div class="modal fade" id="alertDiv" data-backdrop="static" style="display: none;" aria-hidden="true">
  204. <input type="hidden" value="123">
  205. <div class="modal-dialog" role="document">
  206. <div class="modal-content">
  207. <div class="modal-header">
  208. <h5 class="modal-title">警告</h5>
  209. <button type="button" id="alertCls" class="close" data-dismiss="modal" aria-label="Close">
  210. <span aria-hidden="true">×</span>
  211. </button>
  212. </div>
  213. <div class="modal-body">
  214. <h5 class="text-danger" id="alertTxt">编号不存在,请重新输入!</h5>
  215. </div>
  216. <div class="modal-footer">
  217. <button type="button" class="btn btn-danger" id="alertCof" data-dismiss="modal">确认</button>
  218. </div>
  219. </div>
  220. </div>
  221. </div>
  222. <!-- JS. -->
  223. <script src="/lib/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
  224. <script>GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";</script>
  225. <script src="/lib/jquery/jquery.min.js"></script>
  226. <script src="/lib/tether/tether.min.js"></script>
  227. <script src="/lib/bootstrap/bootstrap.min.js"></script>
  228. <script src="/web/maintain/bills_lib/scripts/global.js"></script>
  229. <script src="/web/maintain/bills_lib/scripts/set_sheets.js"></script>
  230. <script src="/web/maintain/bills_lib/scripts/bills_lib_ajax.js"></script>
  231. <!--idTree-->
  232. <script src="/public/web/id_tree.js"></script>
  233. <script src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
  234. <script src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
  235. <script src="/web/maintain/bills_lib/scripts/bills_lib_setting.js"></script>
  236. <script src="/web/maintain/bills_lib/scripts/bills_lib_tree.js"></script>
  237. <script src="/web/maintain/bills_lib/scripts/db_controller.js"></script>
  238. <script src="/web/maintain/bills_lib/scripts/tools.js"></script>
  239. </body>
  240. <script type="text/javascript">
  241. autoFlashHeight();
  242. let maxJobsNumber;
  243. let maxItemsNumber;
  244. let orgJobData;
  245. let orgItemData;
  246. let billsTree = billsLibTree.createBillsTree();
  247. let billsLibId = getQueryString("billsLibId");
  248. let sheetDatas;
  249. let sheetItemsDatas;
  250. let sheetBillsDatas;
  251. tools.redirect(billsLibId, 'stdBillsmain');
  252. let jobsSpread = new GC.Spread.Sheets.Workbook($("#spreadJobs")[0], {sheetCount: 1});
  253. let itemsSpread = new GC.Spread.Sheets.Workbook($("#spreadItems")[0], {sheetCount: 1});
  254. $(document).ready(function(){
  255. $("#aStdJobs").attr('href', function(){
  256. return 'stdJobs?billsLibId=' + billsLibId;
  257. });
  258. $('#aStdItems').attr('href', function(){
  259. return 'stdItems?billsLibId=' + billsLibId;
  260. });
  261. billsAjax.getStdBillsLibName(billsLibId);
  262. billsAjax.getBills(billsLibId, function(bills){
  263. showBillsSheet(bills, jobsSpread.getActiveSheet(), itemsSpread.getActiveSheet(), billsLibSetting)
  264. });
  265. buildJobs(jobsSpread, jobsSetting);
  266. buildItems(itemsSpread, itemsSetting);
  267. });
  268. function nodeOpration(controller, totalJobs, totalItems){
  269. let btnInsert = $('#insert');
  270. let btnDelete = $('#delete');
  271. let btnUpLevel = $('#upLevel');
  272. let btnDownLevel = $('#downLevel');
  273. let btnUpMove = $('#upMove');
  274. let btnDownMove = $('#downMove');
  275. dbController.editData(controller);
  276. btnInsert.click(function(){
  277. if(btnInsert.attr('doing') === 'false' && btnInsert.attr('fcsOnBills') === 'true'){
  278. dbController.insert(controller, btnInsert);
  279. tools.clearData(jobsSpread.getActiveSheet());
  280. tools.clearData(itemsSpread.getActiveSheet());
  281. }
  282. });
  283. btnDelete.click(function(){
  284. if(btnDelete.attr('doing') === 'false' && btnDelete.attr('fcsOnBills') === 'true'){
  285. dbController.delete(controller, btnDelete, totalJobs, totalItems);
  286. }
  287. });
  288. btnUpLevel.click(function(){
  289. if(btnUpLevel.attr('doing') === 'false' && btnUpLevel.attr('fcsOnBills') === 'true'){
  290. dbController.upLevel(controller, btnUpLevel);
  291. }
  292. });
  293. btnDownLevel.click(function(){
  294. if(btnDownLevel.attr('doing') === 'false' && btnDownLevel.attr('fcsOnBills') === 'true'){
  295. dbController.downLevel(controller, btnDownLevel);
  296. }
  297. });
  298. btnUpMove.click(function(){
  299. if(btnUpMove.attr('doing') === 'false' && btnUpMove.attr('fcsOnBills') === 'true'){
  300. dbController.upMove(controller, btnUpMove);
  301. }
  302. //refSheet
  303. else if(btnUpMove.attr('doing') === 'false' && btnUpMove.attr('fcsOnBills') === 'false' && btnUpMove.attr('canMove') === 'true'){
  304. if(controller.tree.selected.field === 'job'){
  305. jobsController.upMove(controller, jobsSpread.getActiveSheet());
  306. }
  307. else if(controller.tree.selected.field === 'item'){
  308. itemsController.upMove(controller, itemsSpread.getActiveSheet());
  309. }
  310. }
  311. });
  312. btnDownMove.click(function(){
  313. if(btnDownMove.attr('doing') === 'false' && btnDownMove.attr('fcsOnBills') === 'true'){
  314. dbController.downMove(controller, btnDownMove);
  315. }
  316. else if(btnDownMove.attr('doing') === 'false' && btnDownMove.attr('fcsOnBills') === 'false' && btnDownMove.attr('canMove') === 'true'){
  317. if(controller.tree.selected.field === 'job'){
  318. jobsController.downMove(controller, jobsSpread.getActiveSheet());
  319. }
  320. else if(controller.tree.selected.field === 'item'){
  321. itemsController.downMove(controller, itemsSpread.getActiveSheet());
  322. }
  323. }
  324. });
  325. }
  326. function showBillsSheet(datas, jobsSheet, itemsSheet, setting) {
  327. let billsSpread = new GC.Spread.Sheets.Workbook($('#spreadBills')[0], {sheetCount: 1});
  328. setSheet.initSheet(billsSpread, setting, true);
  329. myKey.delKey(billsSpread);
  330. billsTree.loadDatas(datas);
  331. let controller = TREE_SHEET_CONTROLLER.createNew(billsTree.tree, billsSpread.getActiveSheet(), setting);
  332. controller.showTreeData();
  333. setSheet.formatter(billsSpread.getActiveSheet());
  334. //setTagId
  335. setTagID(controller, setting);
  336. if (!controller.tree.selected && controller.tree.findNode(controller.sheet.getTag(0, 0, GC.Spread.Sheets.SheetArea.viewport))) {
  337. controller.setTreeSelected(controller.tree.findNode(controller.sheet.getTag(0, 0, GC.Spread.Sheets.SheetArea.viewport)));
  338. }
  339. //刷新节点可进行操作的按钮
  340. refreshBtn(controller);
  341. controller.setTreeSelected(controller.tree.findNode(controller.sheet.getTag(0, 0)));
  342. //粘贴事件
  343. bindPasteBills(controller, billsSpread.getActiveSheet(), setting);
  344. //补注内容改变
  345. rechargeChange(controller);
  346. //焦点控制
  347. switchFcs(controller, controller.sheet, jobsSheet, itemsSheet);
  348. //jobs
  349. jobOperation(controller, jobsSheet, function(totalJobs){
  350. //------关联表粘贴复制
  351. bindPasteRel(jobsSheet, controller, totalJobs, jobsSetting);
  352. //items
  353. itemOperation(controller, itemsSheet, function(totalItems){
  354. bindPasteItemsRel(itemsSheet, controller, totalItems, itemsSetting);
  355. //节点操作
  356. nodeOpration(controller, totalJobs, totalItems);
  357. });
  358. });
  359. }
  360. function switchFcs(controller, billsSheet, jobsSheet, itemsSheet){
  361. let btnInsert = $('#insert');
  362. let btnDelete = $('#delete');
  363. let btnUpMove = $('#upMove');
  364. let btnDownMove = $('#downMove');
  365. let btnUpLevel = $('#upLevel');
  366. let btnDownLevel = $('#downLevel');
  367. // billsSheet.clearSelection();
  368. // billsSheet.options.isProtected = true;
  369. // controller.setTreeSelected(null);
  370. billsSheet.bind(GC.Spread.Sheets.Events.CellClick, function (sender, args) {
  371. //if(billsSheet.options.isProtected = true){
  372. btnInsert.attr('fcsOnBills', 'true');
  373. btnDelete.attr('fcsOnBills', 'true');
  374. btnUpLevel.attr('fcsOnBills', 'true');
  375. btnDownLevel.attr('fcsOnBills', 'true');
  376. btnUpMove.attr('fcsOnBills', 'true');
  377. btnDownMove.attr('fcsOnBills', 'true');
  378. // jobsSheet.clearSelection();
  379. // itemsSheet.clearSelection();
  380. //billsSheet.options.isProtected = false;
  381. /* jobsSheet.options.isProtected = true;
  382. itemsSheet.options.isProtected = true;
  383. let activeRow = billsSheet.getActiveRowIndex();
  384. let activeCol = billsSheet.getActiveColumnIndex();
  385. billsSheet.setActiveCell(activeRow === 0 ? 1: 0, 0);
  386. billsSheet.setActiveCell(activeRow, activeCol);*/
  387. // controller.setTreeSelected(controller.tree.findNode(billsSheet.getTag(activeRow, activeCol)));
  388. // }
  389. });
  390. jobsSheet.bind(GC.Spread.Sheets.Events.CellClick, function (sender, args) {
  391. // if(jobsSheet.options.isProtected){
  392. /* itemsSheet.clearSelection();
  393. itemsSheet.options.isProtected = true;
  394. jobsSheet.options.isProtected = false;
  395. let activeRow = jobsSheet.getActiveRowIndex();
  396. let activeCol = jobsSheet.getActiveColumnIndex();
  397. jobsSheet.setActiveCell(activeRow === 0 ? 1: 0, 0);
  398. jobsSheet.setActiveCell(activeRow, activeCol);*/
  399. controller.tree.selected.args = args;
  400. controller.tree.selected.field = 'job';
  401. tools.btnClose(btnInsert);
  402. tools.btnClose(btnDelete);
  403. tools.btnClose(btnUpLevel);
  404. tools.btnClose(btnDownLevel);
  405. btnInsert.attr('fcsOnBills', 'false');
  406. btnDelete.attr('fcsOnBills', 'false');
  407. btnUpLevel.attr('fcsOnBills', 'false');
  408. btnDownLevel.attr('fcsOnBills', 'false');
  409. btnUpMove.attr('fcsOnBills', 'false');
  410. btnDownMove.attr('fcsOnBills', 'false');
  411. let selected;
  412. if(controller.tree.selected){
  413. selected = controller.tree.selected.jobs[args.row];
  414. }
  415. if(tools.canUpMove(selected, controller.tree.selected.jobs)){
  416. tools.btnAction(btnUpMove);
  417. btnUpMove.attr('canMove', 'true');
  418. }
  419. else{
  420. tools.btnClose(btnUpMove);
  421. btnUpMove.attr('canMove', 'false');
  422. }
  423. if(tools.canDownMove(selected, controller.tree.selected.jobs)){
  424. tools.btnAction(btnDownMove);
  425. btnDownMove.attr('canMove', 'true');
  426. }
  427. else{
  428. tools.btnClose(btnDownMove);
  429. btnDownMove.attr('canMove', 'false');
  430. }
  431. // }
  432. });
  433. itemsSheet.bind(GC.Spread.Sheets.Events.CellClick, function (sender, args) {
  434. //if(itemsSheet.options.isProtected){
  435. /* jobsSheet.clearSelection();
  436. jobsSheet.options.isProtected = true;
  437. itemsSheet.options.isProtected = false;
  438. let activeRow = itemsSheet.getActiveRowIndex();
  439. let activeCol = itemsSheet.getActiveColumnIndex();
  440. itemsSheet.setActiveCell(activeRow === 0 ? 1: 0, 0);
  441. itemsSheet.setActiveCell(activeRow, activeCol);*/
  442. controller.tree.selected.args = args;
  443. controller.tree.selected.field = 'item';
  444. tools.btnClose(btnInsert);
  445. tools.btnClose(btnDelete);
  446. tools.btnClose(btnUpLevel);
  447. tools.btnClose(btnDownLevel);
  448. btnInsert.attr('fcsOnBills', 'false');
  449. btnDelete.attr('fcsOnBills', 'false');
  450. btnUpLevel.attr('fcsOnBills', 'false');
  451. btnDownLevel.attr('fcsOnBills', 'false');
  452. btnUpMove.attr('fcsOnBills', 'false');
  453. btnDownMove.attr('fcsOnBills', 'false');
  454. let selected;
  455. if(controller.tree.selected){
  456. selected = controller.tree.selected.items[args.row];
  457. }
  458. if(tools.canUpMove(selected, controller.tree.selected.items)){
  459. tools.btnAction(btnUpMove);
  460. btnUpMove.attr('canMove', 'true');
  461. }
  462. else{
  463. tools.btnClose(btnUpMove);
  464. btnUpMove.attr('canMove', 'false');
  465. }
  466. if(tools.canDownMove(selected, controller.tree.selected.items)){
  467. tools.btnAction(btnDownMove);
  468. btnDownMove.attr('canMove', 'true');
  469. }
  470. else{
  471. tools.btnClose(btnDownMove);
  472. btnDownMove.attr('canMove', 'false');
  473. }
  474. // }
  475. });
  476. };
  477. function setTagID(controller, setting){
  478. if(controller.tree.items.length > 0){
  479. let length = controller.tree.items.length;
  480. for(var i=0; i<length; i++){
  481. setting.cols.forEach(function(col, colIdx){
  482. if(controller.tree.items[i].data.ID){
  483. controller.sheet.setTag(i, colIdx, controller.tree.items[i].data.ID);
  484. }
  485. });
  486. }
  487. }
  488. }
  489. function refreshBtn(controller){
  490. controller.bind('refreshBaseActn', function (tree) {
  491. let showButton = function (show, btn) {
  492. tools.btnAction($('#insert'), 'focusOnBills');
  493. if (show) {
  494. //btn.show();
  495. tools.btnAction(btn, 'doing');
  496. /*btn.css("opacity", "");
  497. btn.removeClass("disabled");*/
  498. } else {
  499. //btn.hide();
  500. /*btn.css("opacity", "0.2");
  501. btn.addClass("disabled");*/
  502. tools.btnClose(btn, 'doing');
  503. }
  504. };
  505. showButton(tree.selected && tree.selected.canUpLevel(), $('#upLevel'));
  506. showButton(tree.selected && tree.selected.canDownLevel(), $('#downLevel'));
  507. showButton(tree.selected && tree.selected.canUpMove(), $('#upMove'));
  508. showButton(tree.selected && tree.selected.canDownMove(), $('#downMove'));
  509. showButton(tree.selected ? true : false, $('#delete'));
  510. });
  511. }
  512. function rechargeChange(controller){
  513. $('#exampleTextarea').bind('change', function(){
  514. let newData = $('#exampleTextarea').val();
  515. if(controller.tree.selected){
  516. rechargeController.updateRechar(controller.tree.selected, newData);
  517. }
  518. });
  519. }
  520. function jobOperation(controller, jobsSheet, callback){
  521. mainAjax.getMaxNumber(billsLibId, 'jobs', function(result){
  522. if(result.length === 0){
  523. maxJobsNumber = 0;
  524. }
  525. else {
  526. maxJobsNumber = result[0].code;
  527. }
  528. jobsAjax.getJobContent(billsLibId, function(datas){
  529. let totalJobs = createObj.newJobs();
  530. totalJobs.loadJobs(controller.tree.items, datas);
  531. initData(controller, jobsSheet, jobsSetting, 'jobs');
  532. myKey.delKey(jobsSpread, controller, totalJobs, jobsSetting, 'jobs');
  533. bindSheet(controller, jobsSheet, 'jobs', jobsSetting);
  534. jobsController.editData(controller, jobsSheet, totalJobs, jobsSetting);
  535. if (callback){
  536. callback(totalJobs);
  537. }
  538. });
  539. });
  540. }
  541. function itemOperation(controller, itemsSheet, callback){
  542. mainAjax.getMaxNumber(billsLibId, 'items', function(result){
  543. if(result.length === 0){
  544. maxItemsNumber = 0;
  545. }
  546. else {
  547. maxItemsNumber = result[0].code;
  548. }
  549. itemsAjax.getItemCharacter(billsLibId, function(datas){
  550. let totalItems = createObj.newItems();
  551. totalItems.loadItems(controller.tree.items, datas);
  552. initData(controller, itemsSheet, itemsSetting, 'items');
  553. myKey.delKey(itemsSpread, controller, totalItems, itemsSetting, 'items');
  554. bindSheet(controller, itemsSheet, 'items', itemsSetting);
  555. itemsController.editData(controller, itemsSheet, totalItems, itemsSetting);
  556. if(callback){
  557. callback(totalItems)
  558. }
  559. });
  560. });
  561. }
  562. //初始焦点工作表和项目表绑定数据
  563. function initData(controller, sheet, setting, classify){
  564. if(controller.tree.selected){
  565. let arr = controller.tree.selected[classify];
  566. let recharge = controller.tree.selected.data.recharge;
  567. let prefix = classify === 'jobs' ? 'job' : 'item';
  568. if(arr.length > 0){
  569. tools.orderReshowData(sheet, arr, setting, prefix,true);
  570. }
  571. if(recharge){
  572. $('#exampleTextarea').val(recharge);
  573. }
  574. }
  575. }
  576. function bindSheet(controller, sheet, field, setting){
  577. controller.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function(sender, args){
  578. if(controller.tree.selected && args.oldSelections[0].row !== args.newSelections[0].row|| controller.tree.selected && args.oldSelections[0].row === 0){
  579. //rechargeArea
  580. $('#exampleTextarea').val(controller.tree.selected.data.recharge);
  581. if(field === 'jobs'){
  582. tools.clearData(sheet);
  583. let jobs = controller.tree.selected.jobs;
  584. setSheet.setMaxRowCount(sheet, jobs);
  585. if(jobs.length > 0){
  586. tools.orderReshowData(sheet, jobs, setting, 'job', true);
  587. orgJobData = sheet.getValue(0, 0);
  588. }
  589. sheetDatas = tools.getsheetDatas(sheet, 'jobs');
  590. }
  591. if(field === 'items'){
  592. tools.clearData(sheet);
  593. let items = controller.tree.selected.items;
  594. setSheet.setMaxRowCount(sheet, items);
  595. if(items.length > 0){
  596. tools.orderReshowData(sheet, items, setting, 'item', true);
  597. orgItemData = sheet.getValue(0, 0);
  598. }
  599. sheetItemsDatas = tools.getsheetDatas(sheet, 'items');
  600. }
  601. }
  602. });
  603. }
  604. function bindPasteBills(controller, sheet, setting){
  605. sheetBillsDatas = tools.getsheetDatas(sheet, 'bills', controller);
  606. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, function(sender, args){
  607. let datas = [], field;
  608. let orgRow = args.cellRange.row, orgCol = args.cellRange.col, rowCount = args.cellRange.rowCount, colCount = args.cellRange.colCount;
  609. let maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
  610. let markRow = orgRow, colLen = sheet.getColumnCount(GC.Spread.Sheets.SheetArea.viewport);
  611. let validDatas = tools.getValidDatas(sheet, setting, args);
  612. for(let i =orgRow, j=0; i<= maxRow; i++, j++){
  613. let id = sheet.getTag(i, 0);
  614. if(id && j< validDatas.length){
  615. validDatas[j].ID = id;
  616. for(let k =orgCol; k<= maxCol; k++){
  617. setting.cols.forEach(function(col, colIdx){
  618. if(colIdx === k){
  619. if(validDatas[j][col.data.field]){
  620. sheet.setValue(i, k, validDatas[j][col.data.field]);
  621. sheetBillsDatas.datasIdx['rowIdx'+ i][col.data.field] = validDatas[j][col.data.field];
  622. }
  623. else {
  624. sheet.setValue(i, k, '');
  625. sheetBillsDatas.datasIdx['rowIdx'+ i][col.data.field] = '';
  626. }
  627. }
  628. });
  629. }
  630. }
  631. else if(i < controller.tree.items.length && j>= validDatas.length){
  632. //reshow orgDatas
  633. sheet.setValue(i, 0, sheetBillsDatas.datasIdx['rowIdx'+ i].code + '');
  634. sheet.setValue(i, 1, sheetBillsDatas.datasIdx['rowIdx'+ i].name);
  635. sheet.setValue(i, 2, sheetBillsDatas.datasIdx['rowIdx'+ i].unit);
  636. sheet.setValue(i, 3, sheetBillsDatas.datasIdx['rowIdx'+ i].ruleText);
  637. }
  638. else {
  639. sheet.clear(i, 0, 1, sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);
  640. }
  641. }
  642. billsAjax.pasteBills(billsLibId, validDatas);
  643. setSheet.setMaxRowCount(sheet, sheetBillsDatas);
  644. });
  645. }
  646. function bindPasteRel(sheet, controller, totalJobs, setting){
  647. sheetDatas = tools.getsheetDatas(sheet, 'jobs');
  648. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, function(sender, args){
  649. // sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.viewport);
  650. // sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.colHeader);
  651. if(controller.tree.selected){
  652. let orgRow = args.cellRange.row, orgCol = args.cellRange.col, rowCount = args.cellRange.rowCount, colCount = args.cellRange.colCount;
  653. let maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
  654. let pasteArr = [];
  655. let crossedDatas = [];
  656. let uncrossedDatas = [];
  657. const colIdx = 1;
  658. for(let i=orgRow; i<=maxRow; i++){
  659. if(sheet.getCell(i, colIdx).value()){
  660. pasteArr.push(sheet.getCell(i, colIdx).value());
  661. }
  662. }
  663. let uniqPasteArr = tools.uniqArr(pasteArr);
  664. let serialNoUn = tools.getSerialNo(controller.tree.selected.jobs) - 1;
  665. for(let i =orgRow, j=0; i<=uniqPasteArr.length+orgRow-1; i++, j++ ){
  666. let flag = true;
  667. let crossedData;
  668. sheetDatas.forEach(function(rowData){
  669. if(rowData.rowIdx === i && rowData.data !== uniqPasteArr[j]){
  670. flag = false;
  671. let serialNo = tools.getObj(controller.tree.selected.jobs, rowData.id, 'job');
  672. crossedData = {
  673. orgId: rowData.id,
  674. newData: uniqPasteArr[j],
  675. serialNo: serialNo
  676. };
  677. }
  678. });
  679. if(flag){
  680. serialNoUn++;
  681. uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNoUn});
  682. }
  683. else {
  684. crossedDatas.push(crossedData);
  685. }
  686. }
  687. let pasteDatas = tools.encapData(uncrossedDatas, crossedDatas, controller, totalJobs);
  688. if(pasteDatas.updateDatas.length > 0 || pasteDatas.createDatas.length > 0){
  689. billsAjax.pasteRel(pasteDatas.updateDatas, pasteDatas.createDatas, 'jobs', function(datas){
  690. pasteController.frontOperator(sheet, setting, controller, totalJobs, datas);
  691. });
  692. }
  693. else {
  694. tools.orderReshowData(sheet, controller.tree.selected.jobs, setting, 'job', true);
  695. }
  696. }
  697. else {
  698. tools.clearData(sheet);
  699. }
  700. });
  701. }
  702. function bindPasteItemsRel(sheet, controller, totalItems, setting){
  703. sheetItemsDatas = tools.getsheetDatas(sheet, 'items');
  704. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, function(sender, args){
  705. //sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.viewport);
  706. // sheet.setColumnCount(2, GC.Spread.Sheets.SheetArea.colHeader);
  707. if(controller.tree.selected){
  708. let orgRow = args.cellRange.row, orgCol = args.cellRange.col, rowCount = args.cellRange.rowCount, colCount = args.cellRange.colCount;
  709. let maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
  710. let pasteArr = [];
  711. let crossedDatas = [];
  712. let uncrossedDatas = [];
  713. const colIdx = 1;
  714. for(let i=orgRow; i<=maxRow; i++){
  715. if(sheet.getCell(i, colIdx).value()){
  716. pasteArr.push(sheet.getCell(i, colIdx).value());
  717. }
  718. }
  719. let uniqPasteArr = tools.uniqArr(pasteArr);
  720. let serialNoUn = tools.getSerialNo(controller.tree.selected.items) - 1;
  721. for(let i =orgRow, j=0; i<=uniqPasteArr.length+orgRow-1; i++, j++ ){
  722. let flag = true;
  723. let crossedData;
  724. sheetItemsDatas.forEach(function(rowData){
  725. if(rowData.rowIdx === i && rowData.data !== uniqPasteArr[j]){
  726. flag = false;
  727. let serialNo = tools.getObj(controller.tree.selected.items, rowData.id, 'item');
  728. crossedData = {
  729. orgId: rowData.id,
  730. newData: uniqPasteArr[j],
  731. serialNo: serialNo
  732. };
  733. }
  734. });
  735. if(flag){
  736. //let serialNo = tools.getSerialNo(controller.tree.selected.items);
  737. serialNoUn ++;
  738. console.log(serialNoUn);
  739. uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNoUn});
  740. }
  741. else {
  742. crossedDatas.push(crossedData);
  743. }
  744. }
  745. let pasteDatas = tools.encapItemsData(uncrossedDatas, crossedDatas, controller, totalItems);
  746. if(pasteDatas.updateDatas.length > 0 || pasteDatas.createDatas.length > 0){
  747. billsAjax.pasteRel(pasteDatas.updateDatas, pasteDatas.createDatas, 'items', function(datas){
  748. pasteController.frontItemsRelOperator(sheet, setting, controller, totalItems, datas);
  749. });
  750. }
  751. else{
  752. tools.orderReshowData(sheet, controller.tree.selected.items, setting, 'item', true);
  753. }
  754. }
  755. else {
  756. tools.clearData(sheet);
  757. }
  758. });
  759. }
  760. function buildJobs(jobsSpread, setting){
  761. setSheet.initSheet(jobsSpread, setting, true);
  762. // setSheet.setMaxRowCount(jobsSpread.getActiveSheet(), 10);
  763. //jobsSpread.getActiveSheet().clearSelection();
  764. myKey.downKey(jobsSpread);
  765. myKey.enterKey(jobsSpread);
  766. TREE_SHEET_HELPER.loadSheetHeader(jobsSetting, jobsSpread.getActiveSheet());
  767. }
  768. function buildItems(itemsSpread, setting){
  769. setSheet.initSheet(itemsSpread, setting, true);
  770. // setSheet.setMaxRowCount(itemsSpread.getActiveSheet(), 10);
  771. // itemsSpread.getActiveSheet().clearSelection();
  772. myKey.downKey(itemsSpread);
  773. myKey.enterKey(itemsSpread);
  774. TREE_SHEET_HELPER.loadSheetHeader(itemsSetting, itemsSpread.getActiveSheet());
  775. }
  776. </script>
  777. </html>