selectword.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. debugger;
  26. that.data.Words=[];
  27. let list=app.globalData.SelectedWords;
  28. let count=0;
  29. for(let i=0;i<words.length;i++){
  30. let obj={};
  31. obj.Name=words[i];
  32. obj.CSS="";
  33. for(let j=0;j<list.length;j++){
  34. if (list[j]==obj.Name){
  35. obj.CSS="Selected";
  36. count++;
  37. break;
  38. }
  39. }
  40. that.data.Words.push(obj);
  41. }
  42. that.setData({
  43. Words:that.data.Words,
  44. CountMax:COUNT_MAX-list.length+count,
  45. Count:count,
  46. });
  47. },
  48. selectWord:function(e){
  49. let word=e.currentTarget.dataset.word;
  50. let list=this.data.Words;
  51. let count=0,index=-1;
  52. for(let i=0;i<list.length;i++){
  53. if(word==list[i].Name){
  54. if (list[i].CSS)
  55. list[i].CSS="";
  56. else
  57. list[i].CSS="Selected";
  58. index=i;
  59. }
  60. if(list[i].CSS=="Selected"){
  61. count++;
  62. }
  63. }
  64. //debugger;
  65. if (this.data.Count==this.data.CountMax && count>this.data.CountMax){
  66. wx.showToast({
  67. title: '本次最多'+this.data.CountMax+"个",
  68. icon:"none"
  69. });
  70. list[index].CSS="";
  71. }
  72. else{
  73. this.setData({
  74. Words:list,
  75. Count:count,
  76. IsShowAlert:false,
  77. });
  78. }
  79. },
  80. goto: function (e) {
  81. let that=this;
  82. var url=e.currentTarget.dataset.url;
  83. wx.navigateTo({
  84. url: url,
  85. });
  86. },
  87. clearInput: function (e) {
  88. let that=this;
  89. let list=this.data.Words;
  90. for(let i=0;i<list.length;i++){
  91. list[i].CSS="";
  92. }
  93. this.setData({
  94. Words:list,
  95. Count:0,
  96. });
  97. },
  98. gotoRedirectTo:function(e){
  99. let that=this;
  100. var url=e.currentTarget.dataset.url;
  101. wx.redirectTo({
  102. url: url,
  103. })
  104. },
  105. submit:function(){
  106. if (this.data.Count==0){
  107. this.setData({
  108. IsShowAlert:true,
  109. });
  110. }
  111. else{
  112. let list=this.data.Words;
  113. for(let i=0;i<list.length;i++){
  114. if(list[i].CSS=="Selected"){
  115. app.globalData.SelectedWords.push(list[i].Name);
  116. }
  117. }
  118. wx.navigateBack({
  119. delta: 1,
  120. });
  121. }
  122. },
  123. catchTouchMove: main.catchTouchMove,
  124. onShareAppMessage: function () {
  125. return {
  126. title: app.globalData.ShareTitle,
  127. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  128. imageUrl: app.globalData.ShareImage,
  129. }
  130. },
  131. })