selectword.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. IsShowAlert:false,
  10. Count:0,
  11. CountMax:COUNT_MAX,
  12. Words:[],
  13. IsShowExample:false,
  14. },
  15. onLoad: function (options) {
  16. let that = this;
  17. that.setData({
  18. Containnerheight: main.getWindowHeight(),
  19. });
  20. main.checkGenerating();
  21. },
  22. onShow:function(e){
  23. let that = this;
  24. let words=app.globalData.OCRWords;
  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. IsShowAlert:false,
  76. });
  77. }
  78. },
  79. goto: function (e) {
  80. let that=this;
  81. var url=e.currentTarget.dataset.url;
  82. wx.navigateTo({
  83. url: url,
  84. });
  85. },
  86. clearInput: function (e) {
  87. let that=this;
  88. let list=this.data.Words;
  89. for(let i=0;i<list.length;i++){
  90. list[i].CSS="";
  91. }
  92. this.setData({
  93. Words:list,
  94. Count:0,
  95. });
  96. },
  97. gotoRedirectTo:function(e){
  98. let that=this;
  99. var url=e.currentTarget.dataset.url;
  100. wx.redirectTo({
  101. url: url,
  102. })
  103. },
  104. submit:function(){
  105. if (this.data.Count==0){
  106. this.setData({
  107. IsShowAlert:true,
  108. });
  109. }
  110. else{
  111. let list=this.data.Words;
  112. for(let i=0;i<list.length;i++){
  113. if(list[i].CSS=="Selected"){
  114. app.globalData.SelectedWords.push(list[i].Name);
  115. }
  116. }
  117. wx.navigateBack({
  118. delta: 1,
  119. });
  120. }
  121. },
  122. catchTouchMove: main.catchTouchMove,
  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. })