survey_result.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. var code;
  2. mui.init();
  3. mui.plusReady(function(){
  4. var self = plus.webview.currentWebview();
  5. code = self.code;
  6. getResult();
  7. bindEvents();
  8. });
  9. function getResult(){
  10. var url = "/doctor/questionnaire/getAnswers",
  11. params = {id: code};
  12. sendGet(url, params, null, function(res){
  13. if(res.status == 200){
  14. var list = _.map(res.data.questions, function(o){
  15. o.op_jsonStr = JSON.stringify(o.options);
  16. return o;
  17. });
  18. var html = template("result_tmp", {list: list});
  19. $("#result_panel").append(html);
  20. }else{
  21. mui.toast(res.msg);
  22. }
  23. }, true);
  24. }
  25. function sort($obj,sortType){
  26. var data = $obj.attr("data-val"),
  27. amount = $obj.attr("data-count");
  28. options = JSON.parse(data);
  29. var result = _.sortBy(options, function(o){
  30. if(sortType == "DESC"){
  31. return -o.count;
  32. }else{
  33. return o.count;
  34. }
  35. });
  36. //获得数据后,重新填充表格数据
  37. var html = template("tr_tmp", {list: result});
  38. html += '<tr class="c-f16"><td colspan="3" class="t-left">本题有效填写人数:'+amount+'人</td></tr>';
  39. $obj.find("tbody").empty().append(html);
  40. }
  41. template.helper('setType', function(str){
  42. if(str == 0){
  43. return "单选";
  44. }
  45. if(str == 1){
  46. return "多选";
  47. }
  48. if(str == 2){
  49. return "填空"
  50. }
  51. return "";
  52. });
  53. function bindEvents(){
  54. $("body").on('click', '.arrow-div', function(){
  55. var $this = $(this),
  56. $parent = $this.closest(".result"),
  57. $active = $this.find(".active");
  58. if($active.length == 0){
  59. //优先降序
  60. $this.find(".ui-arrow-b").addClass("active");
  61. sort($parent, "DESC");
  62. }else{
  63. var $siblings = $active.siblings();
  64. $active.removeClass("active");
  65. $siblings.addClass("active");
  66. sort($parent, $siblings.attr("data-val"));
  67. }
  68. });
  69. $("body").on('click', '.op_detail', function(){
  70. var $this = $(this),
  71. $parent = $this.closest(".result"),
  72. option_id = $this.attr("data-id"),
  73. question_id = $parent.attr("data-id");
  74. openWebview("question_result.html", {
  75. type: "option",
  76. survey_id: code,
  77. option_id: option_id,
  78. question_id: question_id
  79. });
  80. });
  81. $("body").on('click', '.q_detail', function(){
  82. var question_id = $(this).attr("data-id");
  83. openWebview("question_result.html", {
  84. type: "question",
  85. survey_id: code,
  86. question_id : question_id
  87. });
  88. });
  89. }