daily_work.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <div class="ibox-content">
  4. <div class="ibox">
  5. <div class="alert">
  6. <form action="daily" method="GET" id='search_form' class="form-inline">
  7. <span class="input-group-btn">
  8. <button title="导出" class="btn-sm btn-primary" onclick="exportTableToExcel(this)" type="button" ><i class="fa fa-cloud-download"></i></button>
  9. </span>
  10. </form>
  11. </div>
  12. <div class="panel-group">
  13. <div class="panel panel-default">
  14. <div class="panel-heading clearfix">
  15. <div class="btn-group pull-left">
  16. {$meta_title}
  17. </div>
  18. </div>
  19. <div class="panel-body" id="printer">
  20. <table class="table table-bordered" id="table">
  21. <thead>
  22. <tr>
  23. <th>任务地点</th>
  24. <th>总数</th>
  25. <th>本月</th>
  26. <th>本周</th>
  27. <th>今天</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. {foreach $data.list as $k=>$v}
  32. <tr>
  33. <td>{$v['title']}</td>
  34. <td>{$v['count']}</td>
  35. <td>{$v['count1']}</td>
  36. <td>{$v['count2']}</td>
  37. <td>{$v['count3']}</td>
  38. </tr>
  39. {/foreach}
  40. <tr>
  41. <td style="text-align: right;"><strong>合计</strong></td>
  42. <td>{$data['count']}</td>
  43. <td>{$data['count1']}</td>
  44. <td>{$data['count2']}</td>
  45. <td>{$data['count3']}</td>
  46. </tr>
  47. </tbody>
  48. </table>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. {/block}
  55. {block name="script"}
  56. <script src="/static/browser.js"></script>
  57. <script src="/static/xlsx.full.min.js"></script>
  58. <script type="text/javascript">
  59. function empty_search(){
  60. window.location.href = 'duration';
  61. }
  62. $(function () {
  63. laydate.render({
  64. elem: '#dialog-datetime1'
  65. ,type: 'month',
  66. theme:'#284a94'
  67. });
  68. })
  69. function exportTableToExcel() {
  70. // 获取表格元素
  71. const table = document.getElementById('table');
  72. // 将表格转换为工作表
  73. const ws = XLSX.utils.table_to_sheet(table);
  74. const filename = '日常工作量统计'+'.xlsx';
  75. // 设置单元格宽度
  76. // 示例:设置每列的宽度
  77. ws['!cols'] = [
  78. { wch: 20 },
  79. { wch: 10 },
  80. { wch: 10 },
  81. { wch: 10 },
  82. // 根据需要继续添加更多列的宽度设置
  83. ];
  84. // 设置订单编号列的格式为文本
  85. // 假设订单编号在第1列(A列)
  86. const range = XLSX.utils.decode_range(ws['!ref']);
  87. for (let R = range.s.r; R <= range.e.r; ++R) {
  88. for (let C = range.s.c; C <= range.e.c; ++C) {
  89. const cellRef = XLSX.utils.encode_cell({ r: R, c: C });
  90. if (!ws[cellRef]) continue;
  91. // 设置样式
  92. ws[cellRef].s = {
  93. alignment: {
  94. horizontal: 'left',
  95. vertical: 'center' // 可选:垂直居中
  96. }
  97. };
  98. }
  99. }
  100. // 创建工作簿并添加工作表
  101. const wb = XLSX.utils.book_new();
  102. XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
  103. // 导出为 Excel 文件
  104. XLSX.writeFile(wb, filename || 'tableExport.xlsx');
  105. }
  106. </script>
  107. {/block}