selectword.js 2.9 KB

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