selectword.js 2.9 KB

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