material_exponent.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. const is_numeric = (value) => {
  2. if (typeof(value) === 'object') {
  3. return false;
  4. } else {
  5. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  6. }
  7. };
  8. function getPasteHint (str, row = '') {
  9. let returnObj = str;
  10. if (row) {
  11. returnObj.msg = '指数清单第' + (row+1) + '行' + str.msg;
  12. }
  13. return returnObj;
  14. }
  15. function resetExTpTable() {
  16. const rate = $('#changeRate').val();
  17. const bqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), 2);
  18. const jzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, bqhs), 2);
  19. $('#tp_set').find('td').eq(3).text(ZhCalc.round(ex_tp, 2));
  20. $('#tp_set').find('td').eq(4).text(ZhCalc.round(ZhCalc.add(ex_pre_tp, ex_tp), 2));
  21. $('#rate_set').find('td').eq(3).text(bqhs !== 0 ? bqhs : '');
  22. $('#rate_set').find('td').eq(4).text(jzbqhs !== 0 ? jzbqhs : '');
  23. $('#ex_expr').html(ex_expr);
  24. }
  25. $(document).ready(() => {
  26. autoFlashHeight();
  27. const materialExponentSpread = SpreadJsObj.createNewSpread($('#material-exponent-spread')[0]);
  28. const materialExponentSpreadSetting = {
  29. cols: [
  30. {title: '类型', colSpan: '1', rowSpan: '2', field: 'type', hAlign: 1, width: 60, formatter: '@', readOnly: true,cellType: 'customizeCombo', comboItems: materialType.ex_type, cellTypeKey: 1},
  31. {title: '符号', colSpan: '1', rowSpan: '2', field: 'symbol', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
  32. {title: '符号说明', colSpan: '1', rowSpan: '2', field: 'symbol_desc', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.isEdit'},
  33. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
  34. {title: '加权系数', colSpan: '1', rowSpan: '2', field: 'weight_num', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isConstant'},
  35. {title: '基本价格指数', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 120, readOnly: 'readOnly.isEdit'},
  36. {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
  37. {title: '现行价格指数', colSpan: '1', rowSpan: '2', field: 'm_price', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.remark'},
  38. {title: '计算值', colSpan: '1', rowSpan: '2', field: 'calc_num', hAlign: 2, width: 80, formatter: '@', readOnly: true},
  39. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.remark'},
  40. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'},
  41. ],
  42. emptyRows: 0,
  43. headRows: 2,
  44. headRowHeight: [25, 25],
  45. defaultRowHeight: 21,
  46. headerFont: '12px 微软雅黑',
  47. font: '12px 微软雅黑',
  48. readOnly: readOnly,
  49. };
  50. const materialExponentBase = {
  51. isUsed: function (data) {
  52. if (data.type === 2) {
  53. return data.mid === materialID || data.basic_price === null;
  54. } else {
  55. return false;
  56. }
  57. },
  58. isEdit: function (data) {
  59. return data.mid === materialID && data.type === 2;
  60. },
  61. isConstant: function (data) {
  62. return (materialOrder === 1 && data.type === 1) || (data.mid === materialID && data.type === 2);
  63. }
  64. };
  65. const materialExponentCol = {
  66. getValue: {
  67. calc_num : function (data) {
  68. const calc_num = data.basic_price > 0 ? ZhCalc.mul(data.weight_num, ZhCalc.div(data.m_price, data.basic_price)) : 0;
  69. return calc_num > 0 ? ZhCalc.round(calc_num, 3) : 0;
  70. },
  71. },
  72. readOnly: {
  73. isEdit: function (data) {
  74. return !(!readOnly && materialExponentBase.isEdit(data));
  75. },
  76. isUsed: function (data) {
  77. return !(!readOnly && materialExponentBase.isUsed(data));
  78. },
  79. remark: function (data) {
  80. return !(!readOnly && data.type === 2);
  81. },
  82. isConstant: function (data) {
  83. // return !(!readOnly && materialExponentBase.isConstant(data));
  84. return readOnly;
  85. }
  86. },
  87. };
  88. SpreadJsObj.initSpreadSettingEvents(materialExponentSpreadSetting, materialExponentCol);
  89. SpreadJsObj.initSheet(materialExponentSpread.getActiveSheet(), materialExponentSpreadSetting);
  90. SpreadJsObj.loadSheetData(materialExponentSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialExponentData);
  91. const materialExponentSpreadObj = {
  92. refreshActn: function (rowCount = 1) {
  93. const setObjEnable = function (obj, enable) {
  94. if (enable) {
  95. obj.removeClass('disabled');
  96. } else {
  97. obj.addClass('disabled');
  98. }
  99. };
  100. const sheet = materialExponentSpread.getActiveSheet();
  101. const select = SpreadJsObj.getSelectObject(sheet);
  102. // 还需判断是否已被调差清单调用
  103. setObjEnable($('#del'), !readOnly && select && materialExponentBase.isUsed(select) && rowCount === 1);
  104. },
  105. add: function () {
  106. const sheet = materialExponentSpread.getActiveSheet();
  107. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  108. if (result) {
  109. materialExponentData.push(result);
  110. sheet.addRows(materialExponentData.length - 1, 1);
  111. SpreadJsObj.reLoadRowData(sheet, materialExponentData.length - 1);
  112. sheet.setSelection(materialExponentData.length - 1, 0, 1, 1);
  113. materialExponentSpreadObj.refreshActn();
  114. }
  115. });
  116. },
  117. del: function () {
  118. const sheet = materialExponentSpread.getActiveSheet();
  119. const select = SpreadJsObj.getSelectObject(sheet);
  120. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  121. ex_tp = result.ex_tp;
  122. ex_expr = result.ex_expr;
  123. resetExTpTable();
  124. const index = materialExponentData.indexOf(select);
  125. materialExponentData.splice(index, 1);
  126. sheet.deleteRows(index, 1);
  127. const sel = sheet.getSelections();
  128. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  129. materialExponentSpreadObj.refreshActn();
  130. });
  131. },
  132. selectionChanged: function (e, info) {
  133. const sel = info.sheet.getSelections()[0];
  134. const col = info.sheet.zh_setting.cols[sel.col];
  135. materialExponentSpreadObj.refreshActn(sel.rowCount);
  136. const data = SpreadJsObj.getSelectObject(info.sheet);
  137. materialExponentSpreadObj.setReadOnly(true);
  138. },
  139. editEnded: function (e, info) {
  140. if (info.sheet.zh_setting) {
  141. const select = SpreadJsObj.getSelectObject(info.sheet);
  142. const col = info.sheet.zh_setting.cols[info.col];
  143. if (col.field === 'is_summary') {
  144. return;
  145. }
  146. // 未改变值则不提交
  147. const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  148. const orgValue = select[col.field];
  149. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  150. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  151. return;
  152. }
  153. // 判断部分值是否输入的是数字判断和数据计算
  154. if (col.field === 'basic_price' || col.field === 'm_price') {
  155. if (isNaN(validText)) {
  156. toastr.error('不能输入其它非数字类型字符');
  157. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  158. return;
  159. }
  160. const num = parseFloat(validText);
  161. if (validText !== null && (num < 0 || !/^(\d{1,10}|\d{1,7}\.\d{1,3})?$/.test(num))) {
  162. toastr.error('请输入10位以内有效数字并且小于3位小数的浮点数');
  163. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  164. return;
  165. }
  166. }
  167. if (col.field === 'weight_num') {
  168. if (isNaN(validText)) {
  169. toastr.error('不能输入其它非数字类型字符');
  170. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  171. return;
  172. }
  173. const num = parseFloat(validText);
  174. if (validText !== null && (num < 0 || num >= 1 || !/^\d+(\.\d{1,3})?$/.test(num))) {
  175. toastr.error('请输入0~1范围内并且小于3位小数的浮点数');
  176. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  177. return;
  178. }
  179. const total_weight = ZhCalc.add(ZhCalc.sub(_.sumBy(materialExponentData, 'weight_num'), parseFloat(orgValue)), num);
  180. if (total_weight > 1) {
  181. toastr.error('加权系数总和不能大于1');
  182. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  183. return;
  184. }
  185. }
  186. select[col.field] = validText;
  187. select.calc_num = materialExponentCol.getValue.calc_num(select);
  188. // console.log(select);
  189. // 更新至服务器
  190. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  191. ex_tp = result.ex_tp;
  192. ex_expr = result.ex_expr;
  193. resetExTpTable();
  194. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  195. materialExponentData.splice(info.row, 1, select);
  196. }, function () {
  197. select[col.field] = orgValue;
  198. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  199. });
  200. }
  201. },
  202. buttonClicked: function (e, info) {
  203. if (info.sheet.zh_setting) {
  204. const select = SpreadJsObj.getSelectObject(info.sheet);
  205. const col = info.sheet.zh_setting.cols[info.col];
  206. if (col.field === 'weight_num') {
  207. if(materialExponentCol.readOnly.isConstant(select)) {
  208. return;
  209. }
  210. } else {
  211. if(materialExponentCol.readOnly.isEdit(select)) {
  212. return
  213. }
  214. }
  215. if (col.field === 'is_summary') {
  216. if (info.sheet.isEditing()) {
  217. info.sheet.endEdit(true);
  218. }
  219. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  220. // 更新至服务器
  221. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  222. ex_tp = result.ex_tp;
  223. ex_expr = result.ex_expr;
  224. resetExTpTable();
  225. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  226. }, function () {
  227. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  228. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  229. });
  230. }
  231. }
  232. },
  233. deletePress: function (sheet) {
  234. if (sheet.zh_setting && sheet.zh_data) {
  235. const sel = sheet.getSelections()[0];
  236. if (!sel) return;
  237. const col = sheet.zh_setting.cols[sel.col];
  238. const select = SpreadJsObj.getSelectObject(sheet);
  239. const orgValue = select[col.field];
  240. if (sel.colCount > 1) {
  241. toastr.warning('请勿同时删除多列数据');
  242. }
  243. if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  244. return;
  245. }
  246. if (col.field === 'weight_num') {
  247. if(materialExponentCol.readOnly.isConstant(select)) {
  248. return;
  249. }
  250. } else {
  251. if(materialExponentCol.readOnly.isEdit(select)) {
  252. return
  253. }
  254. }
  255. select[col.field] = null;
  256. select.calc_num = materialExponentCol.getValue.calc_num(select);
  257. // console.log(select);
  258. // 更新至服务器
  259. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  260. ex_tp = result.ex_tp;
  261. ex_expr = result.ex_expr;
  262. resetExTpTable();
  263. SpreadJsObj.reLoadRowData(sheet, sel.row);
  264. materialExponentData.splice(sel.row, 1, select);
  265. }, function () {
  266. select[col.field] = orgValue;
  267. SpreadJsObj.reLoadRowData(sheet, sel.row);
  268. });
  269. }
  270. },
  271. clipboardPasted(e, info) {
  272. const hint = {
  273. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  274. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  275. numberCan: {type: 'error', msg: '请粘贴10位以内有效数字并且小于3位小数的浮点数'},
  276. numberCan2: {type: 'error', msg: '请粘贴0~1范围内并且小于3位小数的浮点数'},
  277. weightNumberCan: {type: 'error', msg: '粘贴的加权系数总和不能大于1'},
  278. };
  279. const range = info.cellRange;
  280. const sortData = info.sheet.zh_data || [];
  281. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  282. toastMessageUniq(hint.cellError);
  283. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  284. SpreadJsObj.reLoadSheetHeader(materialExponentSpread.getActiveSheet());
  285. SpreadJsObj.reLoadSheetData(materialExponentSpread.getActiveSheet());
  286. return;
  287. }
  288. if (sortData.length > 0 && range.col + range.colCount > 10) {
  289. toastMessageUniq(hint.cellError);
  290. SpreadJsObj.reLoadSheetHeader(materialExponentSpread.getActiveSheet());
  291. SpreadJsObj.reLoadSheetData(materialExponentSpread.getActiveSheet());
  292. return;
  293. }
  294. const data = [];
  295. // const rowData = [];
  296. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  297. let bPaste = true;
  298. const curRow = range.row + iRow;
  299. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  300. const materialExData = { id: sortData[curRow].id };
  301. const hintRow = range.rowCount > 1 ? curRow : '';
  302. let sameCol = 0;
  303. for (let iCol = 0; iCol < range.colCount; iCol++) {
  304. const curCol = range.col + iCol;
  305. const colSetting = info.sheet.zh_setting.cols[curCol];
  306. if (!colSetting) continue;
  307. let validText = info.sheet.getText(curRow, curCol);
  308. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  309. const orgValue = sortData[curRow][colSetting.field];
  310. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  311. sameCol++;
  312. if (range.colCount === sameCol) {
  313. bPaste = false;
  314. }
  315. continue;
  316. }
  317. if (colSetting.field === 'basic_price' || colSetting.field === 'm_price') {
  318. if (isNaN(validText)) {
  319. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  320. bPaste = false;
  321. continue;
  322. }
  323. const num = parseFloat(validText);
  324. if (validText !== null && (num < 0 || !/^(\d{1,10}|\d{1,7}\.\d{1,3})?$/.test(num))) {
  325. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  326. bPaste = false;
  327. continue;
  328. }
  329. }
  330. if (colSetting.field === 'weight_num') {
  331. if (isNaN(validText)) {
  332. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  333. bPaste = false;
  334. continue;
  335. }
  336. const num = parseFloat(validText);
  337. if (validText !== null && (num < 0 || num >= 1 || !/^\d+(\.\d{1,3})?$/.test(num))) {
  338. toastMessageUniq(getPasteHint(hint.numberCan2, hintRow));
  339. bPaste = false;
  340. continue;
  341. }
  342. const total_weight = ZhCalc.add(ZhCalc.sub(_.sumBy(materialExponentData, 'weight_num'), parseFloat(orgValue)), num);
  343. console.log(total_weight, _.sumBy(materialExponentData, 'weight_num'), orgValue, num);
  344. if (total_weight > 1) {
  345. toastMessageUniq(getPasteHint(hint.weightNumberCan, hintRow));
  346. bPaste = false;
  347. continue;
  348. }
  349. }
  350. materialExData[colSetting.field] = validText;
  351. sortData[curRow][colSetting.field] = validText;
  352. }
  353. if (bPaste) {
  354. materialExData.calc_num = materialExponentCol.getValue.calc_num(sortData[curRow]);
  355. data.push(materialExData);
  356. // rowData.push(curRow);
  357. } else {
  358. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  359. }
  360. }
  361. if (data.length === 0) {
  362. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  363. return;
  364. }
  365. // console.log(data);
  366. // 更新至服务器
  367. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  368. materialExponentData = result.info;
  369. SpreadJsObj.loadSheetData(materialExponentSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialExponentData);
  370. ex_tp = result.ex_tp;
  371. ex_expr = result.ex_expr;
  372. resetExTpTable();
  373. }, function () {
  374. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  375. return;
  376. });
  377. },
  378. setReadOnly: function(readOnly) {
  379. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  380. }
  381. };
  382. materialExponentSpreadObj.refreshActn();
  383. materialExponentSpread.bind(spreadNS.Events.SelectionChanged, materialExponentSpreadObj.selectionChanged);
  384. materialExponentSpread.bind(spreadNS.Events.ClipboardPasted, materialExponentSpreadObj.clipboardPasted);
  385. SpreadJsObj.addDeleteBind(materialExponentSpread, materialExponentSpreadObj.deletePress);
  386. if (!readOnly) {
  387. $('#add').click(materialExponentSpreadObj.add);
  388. $('#del').click(materialExponentSpreadObj.del);
  389. materialExponentSpread.bind(spreadNS.Events.EditEnded, materialExponentSpreadObj.editEnded);
  390. materialExponentSpread.bind(spreadNS.Events.ButtonClicked, materialExponentSpreadObj.buttonClicked);
  391. // 右键菜单
  392. $.contextMenu({
  393. selector: '#material-exponent-spread',
  394. build: function ($trigger, e) {
  395. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialExponentSpread);
  396. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  397. },
  398. items: {
  399. 'create': {
  400. name: '新增',
  401. icon: 'fa-sign-in',
  402. callback: function (key, opt) {
  403. materialExponentSpreadObj.add(materialExponentSpread.getActiveSheet());
  404. },
  405. },
  406. 'delete': {
  407. name: '删除',
  408. icon: 'fa-remove',
  409. callback: function (key, opt) {
  410. materialExponentSpreadObj.del(materialExponentSpread.getActiveSheet());
  411. },
  412. disabled: function (key, opt) {
  413. const sheet = materialExponentSpread.getActiveSheet();
  414. const select = SpreadJsObj.getSelectObject(sheet);
  415. const sel = sheet.getSelections()[0];
  416. materialExponentSpreadObj.refreshActn(sel.rowCount);
  417. if (!readOnly && select && materialExponentBase.isUsed(select) && sel.rowCount === 1) {
  418. return false;
  419. } else {
  420. return true;
  421. }
  422. }
  423. },
  424. }
  425. });
  426. // 调差基数选中
  427. $('.calc_select').on('click', function () {
  428. // 如果是选中则清除其余2个的选中
  429. const code = $(this).val();
  430. for (const calc of ex_calc) {
  431. calc.select = $(this).is(':checked') && code === calc.code ? true : false;
  432. if (!calc.select) {
  433. $('.calc_select[value="'+ calc.code +'"]').prop('checked', false);
  434. }
  435. }
  436. postData(window.location.pathname + '/save', { type:'ex_calc', updateData: ex_calc }, function (result) {
  437. ex_tp = result.ex_tp;
  438. ex_expr = result.ex_expr;
  439. resetExTpTable();
  440. });
  441. });
  442. $('#changeRate').change(function () {
  443. const rate = parseInt($(this).val());
  444. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  445. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), 2);
  446. const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), 2);
  447. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), 2);
  448. const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), 2);
  449. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  450. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  451. $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  452. $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  453. });
  454. });
  455. }
  456. $.divResizer({
  457. select: '#right-spr',
  458. callback: function () {
  459. materialExponentSpread.refresh();
  460. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  461. setLocalCache('material_exponent_' + materialID, width);
  462. }
  463. });
  464. // 展开收起月信息价并浏览器记住本期展开收起
  465. $('a', '.right-nav').bind('click', function () {
  466. //const main = $('#main-view'), tool = $('#tools-view');
  467. const tab = $(this), tabPanel = $(tab.attr('content'));
  468. if (!tab.hasClass('active')) {
  469. $('a', '.side-menu').removeClass('active');
  470. $('.tab-content .tab-select-show').removeClass('active');
  471. tab.addClass('active');
  472. tabPanel.addClass('active');
  473. showSideTools(tab.hasClass('active'));
  474. if (tab.attr('content') === '#base-tab') {
  475. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  476. setLocalCache('material_exponent_' + materialID, width);
  477. }
  478. } else {
  479. removeLocalCache('material_exponent_' + materialID);
  480. tab.removeClass('active');
  481. tabPanel.removeClass('active');
  482. showSideTools(tab.hasClass('active'));
  483. }
  484. materialExponentSpread.refresh();
  485. });
  486. // 根据浏览器记录展开收起
  487. if (getLocalCache('material_exponent_' + materialID)) {
  488. const tab = $('.right-nav a[content="#base-tab"]'), tabPanel = $(tab.attr('content'));
  489. $('a', '.side-menu').removeClass('active');
  490. $('.tab-content .tab-select-show').removeClass('active');
  491. tab.addClass('active');
  492. tabPanel.addClass('active');
  493. $('#right-view').width(getLocalCache('material_exponent_' + materialID) + '%');
  494. showSideTools(tab.hasClass('active'));
  495. materialExponentSpread.refresh();
  496. }
  497. });