index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 : 0
  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. },
  100. onSearch() {
  101. let list = this.data.foods;
  102. // 给你一个数组 里面包含a这个字的元素 将这些元素抛入新数组
  103. let inputData = this.data.info
  104. let showList = [];
  105. for (let i = 0; i < list.length; i++) {
  106. let name = list[i].foodsName
  107. if (name.indexOf(inputData) >= 0) {
  108. showList.push(list[i]);
  109. }
  110. }
  111. console.log(showList);
  112. // showList
  113. if (showList.length == 0) {
  114. this.setData({
  115. show: true,
  116. })
  117. } else {
  118. this.setData({
  119. show: false,
  120. })
  121. }
  122. this.setData({
  123. showList,
  124. })
  125. },
  126. /**
  127. * 生命周期函数--监听页面加载
  128. */
  129. onLoad(options) {
  130. this.setData({
  131. showList: this.data.foods
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide() {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload() {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh() {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom() {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage() {
  168. }
  169. })