priceRecommend.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // 推荐相似材料
  2. const RECOMMEND_BOOK = (() => {
  3. const setting = {
  4. header: [
  5. { headerName: '主从对应码', headerWidth: 100, dataCode: 'code', dataType: 'String', hAlign: 'left', vAlign: 'center', formatter: "@" },
  6. { headerName: '别名编码', headerWidth: 70, dataCode: 'classCode', dataType: 'String', hAlign: 'left', vAlign: 'center', formatter: "@" },
  7. { headerName: '计算式', headerWidth: 100, dataCode: 'expString', dataType: 'String', hAlign: 'left', vAlign: 'center' },
  8. { headerName: '材料名称', headerWidth: 275, dataCode: 'name', dataType: 'String', hAlign: 'left', vAlign: 'center' },
  9. { headerName: '规格型号', headerWidth: 180, dataCode: 'specs', dataType: 'String', hAlign: 'left', vAlign: 'center' },
  10. { headerName: '单位', headerWidth: 80, dataCode: 'unit', dataType: 'String', hAlign: 'center', vAlign: 'center' },
  11. ],
  12. };
  13. // 初始化表格
  14. // 初始化表格
  15. const workBookObj = {
  16. book: null,
  17. sheet: null,
  18. };
  19. const buildWorkBook = () => {
  20. workBookObj.book = initSheet($('.recommend-spread')[0], setting);
  21. workBookObj.book.options.allowUserDragDrop = true;
  22. workBookObj.book.options.allowUserDragFill = true;
  23. workBookObj.book.options.allowExtendPasteRange = false;
  24. lockUtil.lockSpreads([workBookObj.book], true);
  25. workBookObj.sheet = workBookObj.book.getSheet(0);
  26. }
  27. // 表格显示的数据
  28. const cache = [];
  29. // 清空
  30. function clear() {
  31. cache.length = 0;
  32. workBookObj.sheet.setRowCount(0);
  33. }
  34. // 初始化数据
  35. async function loadRecommendData(keyword) {
  36. clear();
  37. $.bootstrapLoading.start();
  38. try {
  39. const items = await ajaxPost('/priceInfo/getRecommendPriceSummaryData', { keyword }, 1000 * 60 * 5);
  40. cache.push(...items);
  41. showData(workBookObj.sheet, cache, setting.header);
  42. } catch (err) {
  43. clear();
  44. alert(err);
  45. } finally {
  46. $.bootstrapLoading.end();
  47. }
  48. }
  49. // 双击更新空表编码和别名编码
  50. const handleDbClick = (sender, args) => {
  51. const item = cache[args.row];
  52. if (item) {
  53. // 只有珠海才更新计算式
  54. //const expString = /珠海/.test(AREA_BOOK.curArea.name || '') ? item.expString : undefined;
  55. EMPTY_BOOK.updateRowCode(item.code || '', item.classCode || '', item.expString || '');
  56. }
  57. }
  58. const bindEvent = () => {
  59. workBookObj.book.bind(GC.Spread.Sheets.Events.CellDoubleClick, handleDbClick)
  60. }
  61. return {
  62. buildWorkBook,
  63. bindEvent,
  64. clear,
  65. loadRecommendData,
  66. workBookObj,
  67. }
  68. })();
  69. $(document).ready(() => {
  70. $('#empty-area').on('shown.bs.modal', function () {
  71. // 生成表格
  72. if (!RECOMMEND_BOOK.workBookObj.book) {
  73. RECOMMEND_BOOK.buildWorkBook();
  74. RECOMMEND_BOOK.bindEvent();
  75. }
  76. });
  77. $('#empty-area').on('hidden.bs.modal', function () {
  78. RECOMMEND_BOOK.clear();
  79. });
  80. // 回车搜索分词
  81. $('#recommend-search').bind('keydown', function (event) {
  82. if (event.keyCode === 13) {
  83. const searchStr = $(this).val();
  84. RECOMMEND_BOOK.loadRecommendData(searchStr);
  85. }
  86. })
  87. });