selectword.js 2.1 KB

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