new_summary.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var template_id,
  2. template_info;
  3. mui.init();
  4. mui.plusReady(function(){
  5. var self = plus.webview.currentWebview();
  6. template_id = self.template_id;
  7. template_info = self.info;
  8. getTemplateLabel();
  9. bindEvents();
  10. sqlite.open('MyData2','1.0','My Database', 1024*100);
  11. createTemplateTable();
  12. });
  13. function getTemplateLabel(){
  14. var url = "/doctor/questionnaire/getTemplateLabel";
  15. sendGet(url, {}, null, function(res){
  16. if(res.status == 200){
  17. if(res.data.length == 0){
  18. $(".header-link").hide();
  19. }else{
  20. var html = template("label_tmp", {list: res.data});
  21. $("#labels").append(html);
  22. }
  23. if(template_info){
  24. fillInfo();
  25. }
  26. }else{
  27. $(".header-link").hide();
  28. }
  29. }, true);
  30. }
  31. function fillInfo(){
  32. $("#survey_name").val(template_info.title);
  33. $("#survey_summary").val(template_info.comment);
  34. for(i=0; i< template_info.label.length; i++){
  35. var item = template_info.label[i];
  36. $(".flag[data-text="+item+"]").addClass("active");
  37. }
  38. }
  39. function bindEvents(){
  40. $("#labels").on('click', '.flag',function(){
  41. var classList = this.classList;
  42. if(classList.contains("active")){
  43. classList.remove("active");
  44. }else{
  45. classList.add("active");
  46. }
  47. });
  48. $("#next_btn").on('click', function(){
  49. var survey_name = $("#survey_name").val(),
  50. survey_summary = $("#survey_summary").val(),
  51. $flags = $(".flag"),
  52. len = $flags.length,
  53. label = [];
  54. errMsg = "";
  55. if($.trim(survey_name).length == 0){
  56. errMsg += "请填写问卷名称";
  57. }
  58. if($.trim(survey_summary).length == 0){
  59. errMsg += "<br/>请填写问卷说明";
  60. }
  61. var selected = 0;
  62. for(i=0; i<len; i++){
  63. var item = $flags[i];
  64. if(item.classList.contains("active")){
  65. selected ++;
  66. label.push({id: $(item).attr("data-val"), value: $(item).text()});
  67. }
  68. }
  69. if(selected == 0){
  70. errMsg += "<br/>请选择问卷标签";
  71. }
  72. if(errMsg.length >0){
  73. dialog({
  74. content:errMsg,
  75. contentType: "tipsbox",
  76. skin: "bk-popup",
  77. closeTime: 2000
  78. }).showModal();
  79. }else{
  80. sqlite.executeSql(
  81. 'insert into template(name, comment, label) VALUES(?,?,?)',
  82. [survey_name, survey_summary, JSON.stringify(label)],
  83. function(tx, rs){
  84. console.log(rs);
  85. var table_tp_id = rs.insertId;
  86. if(template_id){
  87. openWebview("preview.html",{
  88. table_tp_id: table_tp_id,
  89. code: template_id,
  90. info: {
  91. name: survey_name,
  92. comment: survey_summary,
  93. label: label
  94. }
  95. });
  96. }else{
  97. openWebview("edit_questions.html",{
  98. code: template_id,
  99. table_tp_id: table_tp_id,
  100. info: {
  101. name: survey_name,
  102. comment: survey_summary,
  103. label: label
  104. }
  105. });
  106. }
  107. }, function(tx, rs){
  108. console.log(rs)
  109. });
  110. }
  111. });
  112. }
  113. function createTemplateTable(){
  114. sqlite.executeSql("create table if not exists template "+
  115. "(id INTEGER PRIMARY KEY, name TEXT, comment TEXT, label TEXT)",[],
  116. function(tx, rs){
  117. console.log("tempale 表创建成功");
  118. },
  119. function(tx, rs){
  120. console.error(rs)
  121. alert("创建缓存空间失败!");
  122. }
  123. )
  124. }