index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // pages/merchant_page/index.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. foods: [{
  8. id: 0,
  9. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  10. foodsName: '麻烫',
  11. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  12. initPrice: 28.80,
  13. nowPrice: 10.98,
  14. num : 0
  15. },
  16. {
  17. id: 1,
  18. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  19. foodsName: '麻辣',
  20. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  21. initPrice: 28.80,
  22. nowPrice: 10.98,
  23. num : 10
  24. },
  25. {
  26. id: 2,
  27. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  28. foodsName: '麻辣烫',
  29. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  30. initPrice: 28.80,
  31. nowPrice: 10.98,
  32. num : 0
  33. },
  34. {
  35. id: 3,
  36. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  37. foodsName: '麻辣烫',
  38. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  39. initPrice: 28.80,
  40. nowPrice: 10.98,
  41. num : 0
  42. },
  43. {
  44. id: 4,
  45. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  46. foodsName: '麻辣烫',
  47. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  48. initPrice: 28.80,
  49. nowPrice: 10.98,
  50. num : 0
  51. },
  52. {
  53. id: 5,
  54. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  55. foodsName: '麻辣烫',
  56. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  57. initPrice: 28.80,
  58. nowPrice: 10.98,
  59. num : 0
  60. },
  61. {
  62. id: 6,
  63. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  64. foodsName: '麻辣烫',
  65. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  66. initPrice: 28.80,
  67. nowPrice: 10.98,
  68. num : 0
  69. },
  70. {
  71. id: 7,
  72. foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
  73. foodsName: '麻辣烫',
  74. foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
  75. initPrice: 28.80,
  76. nowPrice: 10.98,
  77. num : 0
  78. }
  79. ],
  80. show: false,
  81. totalPrice: 0,
  82. info: '',
  83. showList: []
  84. },
  85. onInput(e) {
  86. this.setData({
  87. info: e.detail.value
  88. })
  89. },
  90. onChange(e) {
  91. let id = e.currentTarget.dataset.id;
  92. let num = e.detail;
  93. // console.log(num);
  94. let ans = this.data.foods[0].num
  95. console.log(ans);
  96. this.setData({
  97. [ans ]:'num'
  98. })
  99. // for( let i = 0 ; i < showList.length ;i ++ ) {
  100. // showList[i].num
  101. // }
  102. // for( let i = 0 ; i < showList.length ;i ++ ) {
  103. // showList[i].
  104. // }
  105. // totalPrice
  106. },
  107. onSearch() {
  108. let list = this.data.foods;
  109. // 给你一个数组 里面包含a这个字的元素 将这些元素抛入新数组
  110. let inputData = this.data.info
  111. let showList = [];
  112. for (let i = 0; i < list.length; i++) {
  113. let name = list[i].foodsName
  114. if (name.indexOf(inputData) >= 0) {
  115. showList.push(list[i]);
  116. }
  117. }
  118. console.log(showList);
  119. // showList
  120. if (showList.length != 0) {
  121. this.setData({
  122. show: false,
  123. })
  124. } else {
  125. this.setData({
  126. show: true,
  127. })
  128. }
  129. this.setData({
  130. showList,
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面加载
  135. */
  136. onLoad(options) {
  137. this.setData({
  138. showList: this.data.foods
  139. })
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady() {
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow() {
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide() {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload() {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh() {
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom() {
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage() {
  175. }
  176. })