selectword.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const COUNT_MAX=10;
  4. const app = getApp();
  5. Page({
  6. data: {
  7. IsShowAlert:false,
  8. Count:0,
  9. CountMax:COUNT_MAX,
  10. Words:[],
  11. IsShowExample:false,
  12. },
  13. onLoad: function (options) {
  14. let that = this;
  15. that.setData({
  16. Containnerheight: main.getWindowHeight(),
  17. });
  18. main.checkGenerating();
  19. },
  20. onShow:function(e){
  21. let that = this;
  22. let words=app.globalData.OCRWords;
  23. that.data.Words=[];
  24. let list=app.globalData.SelectedWords;
  25. let count=0;
  26. for(let i=0;i<words.length;i++){
  27. let obj={};
  28. obj.Name=words[i];
  29. obj.CSS="";
  30. for(let j=0;j<list.length;j++){
  31. if (list[j]==obj.Name){
  32. obj.CSS="Selected";
  33. count++;
  34. break;
  35. }
  36. }
  37. that.data.Words.push(obj);
  38. }
  39. that.setData({
  40. Words:that.data.Words,
  41. CountMax:COUNT_MAX-list.length+count,
  42. Count:count,
  43. });
  44. },
  45. selectWord:function(e){
  46. let word=e.currentTarget.dataset.word;
  47. let list=this.data.Words;
  48. let count=0,index=-1;
  49. for(let i=0;i<list.length;i++){
  50. if(word==list[i].Name){
  51. if (list[i].CSS)
  52. list[i].CSS="";
  53. else
  54. list[i].CSS="Selected";
  55. index=i;
  56. }
  57. if(list[i].CSS=="Selected"){
  58. count++;
  59. }
  60. }
  61. //debugger;
  62. if (this.data.Count==this.data.CountMax && count>this.data.CountMax){
  63. wx.showToast({
  64. title: '本次最多'+this.data.CountMax+"个",
  65. icon:"none"
  66. });
  67. list[index].CSS="";
  68. }
  69. else{
  70. this.setData({
  71. Words:list,
  72. Count:count,
  73. IsShowAlert:false,
  74. });
  75. }
  76. },
  77. goto: function (e) {
  78. let that=this;
  79. var url=e.currentTarget.dataset.url;
  80. wx.navigateTo({
  81. url: url,
  82. });
  83. },
  84. clearInput: function (e) {
  85. let that=this;
  86. let list=this.data.Words;
  87. for(let i=0;i<list.length;i++){
  88. list[i].CSS="";
  89. }
  90. this.setData({
  91. Words:list,
  92. Count:0,
  93. });
  94. },
  95. gotoRedirectTo:function(e){
  96. let that=this;
  97. var url=e.currentTarget.dataset.url;
  98. wx.redirectTo({
  99. url: url,
  100. })
  101. },
  102. submit:function(){
  103. if (this.data.Count==0){
  104. this.setData({
  105. IsShowAlert:true,
  106. });
  107. }
  108. else{
  109. let list=this.data.Words;
  110. for(let i=0;i<list.length;i++){
  111. if(list[i].CSS=="Selected"){
  112. app.globalData.SelectedWords.push(list[i].Name);
  113. }
  114. }
  115. wx.navigateBack({
  116. delta: 1,
  117. });
  118. }
  119. },
  120. showExample:function(){
  121. this.setData({
  122. IsShowExample:!this.data.IsShowExample,
  123. });
  124. },
  125. // 阻止示例面板的触摸事件传递到底层
  126. catchTouchMove: function(e) {
  127. // 这个函数不需要做任何事情,只需要捕获事件防止冒泡
  128. return false;
  129. },
  130. onShareAppMessage: function () {
  131. return {
  132. title: app.globalData.ShareTitle,
  133. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  134. imageUrl: app.globalData.ShareImage,
  135. }
  136. },
  137. })