123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- var code;
- mui.init();
- mui.plusReady(function(){
- var self = plus.webview.currentWebview();
- code = self.code;
-
- getResult();
- bindEvents();
- });
- function getResult(){
- var url = "/doctor/questionnaire/getAnswers",
- params = {id: code};
- sendGet(url, params, null, function(res){
- if(res.status == 200){
- var list = _.map(res.data.questions, function(o){
- o.op_jsonStr = JSON.stringify(o.options);
- return o;
- });
- var html = template("result_tmp", {list: list});
- $("#result_panel").append(html);
- }else{
- mui.toast(res.msg);
- }
- }, true);
- }
- function sort($obj,sortType){
- var data = $obj.attr("data-val"),
- amount = $obj.attr("data-count");
- options = JSON.parse(data);
-
- var result = _.sortBy(options, function(o){
- if(sortType == "DESC"){
- return -o.count;
- }else{
- return o.count;
- }
- });
-
- //获得数据后,重新填充表格数据
- var html = template("tr_tmp", {list: result});
- html += '<tr class="c-f16"><td colspan="3" class="t-left">本题有效填写人数:'+amount+'人</td></tr>';
- $obj.find("tbody").empty().append(html);
- }
- template.helper('setType', function(str){
- if(str == 0){
- return "单选";
- }
- if(str == 1){
- return "多选";
- }
- if(str == 2){
- return "填空"
- }
- return "";
- });
- function bindEvents(){
- $("body").on('click', '.arrow-div', function(){
- var $this = $(this),
- $parent = $this.closest(".result"),
- $active = $this.find(".active");
- if($active.length == 0){
- //优先降序
- $this.find(".ui-arrow-b").addClass("active");
- sort($parent, "DESC");
- }else{
- var $siblings = $active.siblings();
- $active.removeClass("active");
- $siblings.addClass("active");
- sort($parent, $siblings.attr("data-val"));
- }
- });
-
- $("body").on('click', '.op_detail', function(){
- var $this = $(this),
- $parent = $this.closest(".result"),
- option_id = $this.attr("data-id"),
- question_id = $parent.attr("data-id");
- openWebview("question_result.html", {
- type: "option",
- survey_id: code,
- option_id: option_id,
- question_id: question_id
- });
- });
- $("body").on('click', '.q_detail', function(){
- var question_id = $(this).attr("data-id");
- openWebview("question_result.html", {
- type: "question",
- survey_id: code,
- question_id : question_id
- });
- });
- }
|