moduleManager.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const $ = require('jquery');
  2. // require('./../resource/layui/layui.all.js')
  3. // require('./../resource/layui/css/layui.css')
  4. // const layui = require('layui-src');
  5. // console.log('layui', layui)
  6. // layui.use('table', function(){
  7. // var table = layui.table;
  8. // //第一个实例
  9. // table.render({
  10. // elem: '#demo'
  11. // ,height: 312
  12. // ,url: '/demo/table/user/' //数据接口
  13. // ,page: true //开启分页
  14. // ,cols: [[ //表头
  15. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
  16. // ,{field: 'username', title: '用户名', width:80}
  17. // ,{field: 'sex', title: '性别', width:80, sort: true}
  18. // ,{field: 'city', title: '城市', width:80}
  19. // ,{field: 'sign', title: '签名', width: 177}
  20. // ,{field: 'experience', title: '积分', width: 80, sort: true}
  21. // ,{field: 'score', title: '评分', width: 80, sort: true}
  22. // ,{field: 'classify', title: '职业', width: 80}
  23. // ,{field: 'wealth', title: '财富', width: 135, sort: true}
  24. // ]]
  25. // });
  26. // });
  27. const data = [
  28. {
  29. name: '入院记录',
  30. score: 10
  31. },
  32. {
  33. name: '入院记录',
  34. score: 10
  35. },
  36. {
  37. name: '入院记录',
  38. score: 10
  39. },{
  40. name: '入院记录',
  41. score: 10
  42. }
  43. ,{
  44. name: '入院记录',
  45. score: 10
  46. }
  47. ,{
  48. name: '入院记录',
  49. score: 10
  50. },
  51. {
  52. name: '入院记录',
  53. score: 10
  54. }
  55. ]
  56. function renderTab(){
  57. let str = ``, sum = 0
  58. for(let i = 0; i < data.length; i++){
  59. str += `
  60. <tr>
  61. <td>${data[i].name}</td>
  62. <td> <input data-index=${i} value=${data[i].score} /></td>
  63. </tr>
  64. `
  65. if(data[i].score){
  66. sum += Number(data[i].score)
  67. }
  68. }
  69. str += `
  70. <tr>
  71. <td>总分</td>
  72. <td>${sum}</td>
  73. </tr>
  74. `
  75. $('table tbody').html(str)
  76. bindInput()
  77. }
  78. renderTab()
  79. function bindInput(){
  80. $('input').on('input', function(e){
  81. const val = $(this).val()
  82. const index = $(this).attr('data-index')
  83. data[index].score = val
  84. renderTab()
  85. })
  86. }