var template_id, template_info; mui.init(); mui.plusReady(function(){ var self = plus.webview.currentWebview(); template_id = self.template_id; template_info = self.info; getTemplateLabel(); bindEvents(); sqlite.open('MyData2','1.0','My Database', 1024*100); createTemplateTable(); }); function getTemplateLabel(){ var url = "/doctor/questionnaire/getTemplateLabel"; sendGet(url, {}, null, function(res){ if(res.status == 200){ if(res.data.length == 0){ $(".header-link").hide(); }else{ var html = template("label_tmp", {list: res.data}); $("#labels").append(html); } if(template_info){ fillInfo(); } }else{ $(".header-link").hide(); } }, true); } function fillInfo(){ $("#survey_name").val(template_info.title); $("#survey_summary").val(template_info.comment); for(i=0; i< template_info.label.length; i++){ var item = template_info.label[i]; $(".flag[data-text="+item+"]").addClass("active"); } } function bindEvents(){ $("#labels").on('click', '.flag',function(){ var classList = this.classList; if(classList.contains("active")){ classList.remove("active"); }else{ classList.add("active"); } }); $("#next_btn").on('click', function(){ var survey_name = $("#survey_name").val(), survey_summary = $("#survey_summary").val(), $flags = $(".flag"), len = $flags.length, label = []; errMsg = ""; if($.trim(survey_name).length == 0){ errMsg += "请填写问卷名称"; } if($.trim(survey_summary).length == 0){ errMsg += "
请填写问卷说明"; } var selected = 0; for(i=0; i0){ dialog({ content:errMsg, contentType: "tipsbox", skin: "bk-popup", closeTime: 2000 }).showModal(); }else{ sqlite.executeSql( 'insert into template(name, comment, label) VALUES(?,?,?)', [survey_name, survey_summary, JSON.stringify(label)], function(tx, rs){ console.log(rs); var table_tp_id = rs.insertId; if(template_id){ openWebview("preview.html",{ table_tp_id: table_tp_id, code: template_id, info: { name: survey_name, comment: survey_summary, label: label } }); }else{ openWebview("edit_questions.html",{ code: template_id, table_tp_id: table_tp_id, info: { name: survey_name, comment: survey_summary, label: label } }); } }, function(tx, rs){ console.log(rs) }); } }); } function createTemplateTable(){ sqlite.executeSql("create table if not exists template "+ "(id INTEGER PRIMARY KEY, name TEXT, comment TEXT, label TEXT)",[], function(tx, rs){ console.log("tempale 表创建成功"); }, function(tx, rs){ console.error(rs) alert("创建缓存空间失败!"); } ) }