selectword.js 3.0 KB

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