selectword.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. var that = this;
  15. let words=app.globalData.OCRWords;
  16. that.data.Words=[];
  17. for(let i=0;i<words.length;i++){
  18. let obj={};
  19. obj.Name=words[i];
  20. obj.CSS="";
  21. that.data.Words.push(obj);
  22. }
  23. let list=app.globalData.SelectedWords;
  24. that.setData({
  25. Containnerheight: main.getWindowHeight(),
  26. Words:that.data.Words,
  27. CountMax:COUNT_MAX-list.length,
  28. });
  29. },
  30. selectWord:function(e){
  31. let word=e.currentTarget.dataset.word;
  32. let list=this.data.Words;
  33. let count=0;
  34. for(let i=0;i<list.length;i++){
  35. if(word==list[i].Name){
  36. if (list[i].CSS)
  37. list[i].CSS="";
  38. else if(count<this.data.CountMax && this.data.Count<this.data.CountMax)
  39. list[i].CSS="Selected";
  40. }
  41. if(list[i].CSS=="Selected"){
  42. count++;
  43. }
  44. }
  45. if (count>0){
  46. this.setData({
  47. IsShowAlert:false,
  48. });
  49. }
  50. else{
  51. this.setData({
  52. IsShowAlert:true,
  53. });
  54. }
  55. this.setData({
  56. Words:list,
  57. Count:count,
  58. });
  59. },
  60. goto: function (e) {
  61. let that=this;
  62. var url=e.currentTarget.dataset.url;
  63. wx.navigateTo({
  64. url: url,
  65. });
  66. },
  67. close:function(n){
  68. if (!n)
  69. n=1;
  70. wx.navigateBack({
  71. delta: n
  72. })
  73. },
  74. submit:function(){
  75. if (this.data.Count==0){
  76. this.setData({
  77. IsShowAlert:true,
  78. });
  79. }
  80. else{
  81. let list=this.data.Words;
  82. for(let i=0;i<list.length;i++){
  83. if(list[i].CSS=="Selected"){
  84. app.globalData.SelectedWords.push(list[i].Name);
  85. }
  86. }
  87. this.close(2);
  88. }
  89. },
  90. showExample:function(){
  91. this.setData({
  92. IsShowExample:!this.data.IsShowExample,
  93. });
  94. },
  95. onShareAppMessage: function () {
  96. return {
  97. title: app.globalData.ShareTitle,
  98. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  99. imageUrl: app.globalData.ShareImage,
  100. }
  101. },
  102. })