createroom.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //index.js
  2. //获取应用实例
  3. var app = getApp()
  4. Page({
  5. data: {
  6. dataList:[
  7. //村民
  8. {
  9. "id":"1",
  10. "pic": "./images/cunmin.png",
  11. "title": "cunmin",
  12. "currentNum":0,
  13. "addclass":"itemroom-add",
  14. "reduceclass":"itemroom-reduce itemroom-no",
  15. "max":6,
  16. "name": "村民",
  17. "intro": "全场最懵的角色"
  18. },
  19. //女巫
  20. {
  21. "id":"2",
  22. "pic": "./images/nvwu.png",
  23. "title": "nvwu",
  24. "currentNum":0,
  25. "addclass":"itemroom-add",
  26. "reduceclass":"itemroom-reduce itemroom-no",
  27. "max":1,
  28. "name": "女巫",
  29. "intro": "可乐的代言人"
  30. },
  31. //猎人
  32. {
  33. "id":"3",
  34. "pic": "./images/lieren.png",
  35. "title": "lieren",
  36. "currentNum":0,
  37. "addclass":"itemroom-add",
  38. "reduceclass":"itemroom-reduce itemroom-no",
  39. "max":1,
  40. "name": "猎人",
  41. "intro": "全场最叼的角色"
  42. },
  43. //预言家
  44. {
  45. "id":"4",
  46. "pic": "./images/yuyanjia.png",
  47. "title": "yuyanjia",
  48. "currentNum":0,
  49. "addclass":"itemroom-add",
  50. "reduceclass":"itemroom-reduce itemroom-no",
  51. "max":1,
  52. "name": "预言家",
  53. "intro": "全场最惨的角色"
  54. },
  55. //盗贼
  56. {
  57. "id":"5",
  58. "pic": "./images/daozei.png",
  59. "title": "daozei",
  60. "currentNum":0,
  61. "addclass":"itemroom-add",
  62. "reduceclass":"itemroom-reduce itemroom-no",
  63. "max":1,
  64. "name": "盗贼",
  65. "intro": "全场最gay的角色"
  66. },
  67. //丘比特
  68. {
  69. "id":"6",
  70. "pic": "./images/qiubite.png",
  71. "title": "qiubite",
  72. "currentNum":0,
  73. "addclass":"itemroom-add",
  74. "reduceclass":"itemroom-reduce itemroom-no",
  75. "max":1,
  76. "name": "丘比特",
  77. "intro": "全场最色情的角色"
  78. },
  79. //测试
  80. {
  81. "id":"7",
  82. "pic": "./images/qiubite.png",
  83. "title": "qiubite",
  84. "currentNum":0,
  85. "addclass":"itemroom-add",
  86. "reduceclass":"itemroom-reduce itemroom-no",
  87. "max":2,
  88. "name": "测试甲",
  89. "intro": "全场最色情的角色"
  90. },
  91. //测试
  92. {
  93. "id":"8",
  94. "pic": "./images/qiubite.png",
  95. "title": "qiubite",
  96. "currentNum":0,
  97. "addclass":"itemroom-add",
  98. "reduceclass":"itemroom-reduce itemroom-no",
  99. "max":4,
  100. "name": "测试乙",
  101. "intro": "全场最色情的角色"
  102. },
  103. //测试
  104. {
  105. "id":"9",
  106. "pic": "./images/qiubite.png",
  107. "title": "qiubite",
  108. "currentNum":0,
  109. "addclass":"itemroom-add",
  110. "reduceclass":"itemroom-reduce itemroom-no",
  111. "max":3,
  112. "name": "测试丙",
  113. "intro": "全场最色情的角色"
  114. },
  115. ],
  116. total:0
  117. },
  118. addnum: function(e){
  119. let currId = e.currentTarget.dataset.id;
  120. let max = e.currentTarget.dataset.max;
  121. let array = this.data.dataList;
  122. let totalNum = this.data.total;
  123. for(let i = 0;i<array.length;i++){
  124. if(array[i]['id']==currId){
  125. if(array[i]['currentNum'] >= (max-1)){
  126. array[i]['addclass'] = "itemroom-add itemroom-no";
  127. if(array[i]['currentNum'] == (max-1)){
  128. console.log(1);
  129. totalNum += 1;
  130. }
  131. array[i]['currentNum'] = max;
  132. }else{
  133. array[i]['addclass'] = "itemroom-add";
  134. array[i]['currentNum'] += 1;
  135. totalNum += 1;
  136. }
  137. array[i]['reduceclass'] = "itemroom-reduce";
  138. this.setData({
  139. dataList:array,
  140. total:totalNum
  141. });
  142. break;
  143. }
  144. }
  145. },
  146. reducenum: function(e){
  147. let currId = e.currentTarget.dataset.id;
  148. let array = this.data.dataList;
  149. let totalNum = this.data.total;
  150. for(let i = 0;i<array.length;i++){
  151. if(array[i]['id']==currId){
  152. if(array[i]['currentNum'] <= 1){
  153. array[i]['reduceclass'] = "itemroom-reduce itemroom-no";
  154. if(array[i]['currentNum'] == 1){
  155. totalNum -= 1;
  156. }
  157. array[i]['currentNum'] = 0;
  158. }else{
  159. array[i]['reduceclass'] = "itemroom-reduce";
  160. array[i]['currentNum'] -= 1;
  161. totalNum -= 1;
  162. }
  163. array[i]['addclass'] = "itemroom-add";
  164. this.setData({
  165. dataList:array,
  166. total:totalNum
  167. });
  168. break;
  169. }
  170. }
  171. },
  172. onLoad: function () {
  173. },
  174. goToPlay: function(){
  175. wx.navigateTo({
  176. url: '/pages/room/room',
  177. success: function(res){
  178. },
  179. fail: function() {
  180. },
  181. complete: function() {
  182. }
  183. })
  184. }
  185. })