selectword.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import commonBehavior from '../behaviors/commonBehavior';
  4. const COUNT_MAX=10;
  5. const app = getApp();
  6. Page({
  7. behaviors: [commonBehavior],
  8. data: {
  9. Count:0,
  10. CountMax:COUNT_MAX,
  11. Words:[],
  12. IsShowExample:false,
  13. },
  14. onLoad: function (options) {
  15. let that = this;
  16. that.setData({
  17. Containnerheight: main.getWindowHeight(),
  18. });
  19. main.checkGenerating();
  20. },
  21. onShow:function(e){
  22. let that = this;
  23. let words=app.globalData.OCRWords;
  24. //debugger;
  25. that.data.Words=[];
  26. let list=app.globalData.SelectedWords;
  27. let count=0;
  28. for(let i=0;i<words.length;i++){
  29. let obj={};
  30. obj.Name=words[i];
  31. obj.CSS="";
  32. for(let j=0;j<list.length;j++){
  33. if (list[j]==obj.Name){
  34. obj.CSS="Selected";
  35. count++;
  36. break;
  37. }
  38. }
  39. that.data.Words.push(obj);
  40. }
  41. that.setData({
  42. Words:that.data.Words,
  43. CountMax:COUNT_MAX-list.length+count,
  44. Count:count,
  45. });
  46. },
  47. selectWord:function(e){
  48. let word=e.currentTarget.dataset.word;
  49. let list=this.data.Words;
  50. let count=0,index=-1;
  51. for(let i=0;i<list.length;i++){
  52. if(word==list[i].Name){
  53. if (list[i].CSS)
  54. list[i].CSS="";
  55. else
  56. list[i].CSS="Selected";
  57. index=i;
  58. }
  59. if(list[i].CSS=="Selected"){
  60. count++;
  61. }
  62. }
  63. //debugger;
  64. if (this.data.Count==this.data.CountMax && count>this.data.CountMax){
  65. wx.showToast({
  66. title: '本次最多'+this.data.CountMax+"个",
  67. icon:"none"
  68. });
  69. list[index].CSS="";
  70. }
  71. else{
  72. this.setData({
  73. Words:list,
  74. Count:count,
  75. });
  76. }
  77. },
  78. goto: function (e) {
  79. let that=this;
  80. var url=e.currentTarget.dataset.url;
  81. wx.navigateTo({
  82. url: url,
  83. });
  84. },
  85. clearInput: function (e) {
  86. let that=this;
  87. let list=this.data.Words;
  88. for(let i=0;i<list.length;i++){
  89. list[i].CSS="";
  90. }
  91. this.setData({
  92. Words:list,
  93. Count:0,
  94. });
  95. },
  96. gotoRedirectTo:function(e){
  97. let that=this;
  98. var url=e.currentTarget.dataset.url;
  99. wx.redirectTo({
  100. url: url,
  101. })
  102. },
  103. submit:function(){
  104. if (this.data.Count==0){
  105. this.selectComponent('#alertTip').showAlert("请至少选择1个单词");
  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. catchTouchMove: main.catchTouchMove,
  120. onShareAppMessage: function () {
  121. return {
  122. title: app.globalData.ShareTitle,
  123. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  124. imageUrl: app.globalData.ShareImage,
  125. }
  126. },
  127. })