LIEBE餐盘机自带微信订餐程序源代码

成都捷德LIEBE餐盘机可提供"一人一盘“精准统计就餐人数解决方案,订餐验证自动出餐盘.餐盘机可提供一个 JSON 数据库,数据库中的每条记录都是一个 JSON 格式的对象。一个数据库可以有多个集合(相当于关系型数据中的表),集合可看做一个 JSON 数组,数组中的每个对象就是一条记录,记录的格式是 JSON 对象。下面是历史记录的处理方法,菜品收藏与其类似。

  1. <view class='search'>

  2. <image src='/images/search.png'></image>

  3. <input placeholder='今天吃什么' focus bindinput="bindKeyInput" bindconfirm='goSearch' ></input>

  4. <text bindtap='goSearch'>搜索</text>

  5. </view>

  6. // pages/search/search.js

  7. Page({

  8. data: {

  9. inputValue: '',

  10. openid: '',

  11. showHistory: true,

  12. historyList: []

  13. },

  14.  
  15. // 进入搜索结果页 -> list

  16. goSearch() {

  17. let content = this.data.inputValue

  18. if (!content) {

  19. return

  20. }

  21.  
  22. this.onHistory(content)

  23.  
  24. wx.navigateTo({

  25. url: `/pages/list/list?content=${content}`,

  26. })

  27. },

  28.  
  29. // 添加历史记录

  30. onHistory (content) {

  31. const db = wx.cloud.database() // 获取数据库引用

  32. let that = this

  33.  
  34. // 查看是否有历史记录

  35. db.collection('food').where({

  36. _openid: this.data.openid,

  37. _id: 'history' + this.data.openid

  38. }).get({

  39. success: res => {

  40. console.log('数据库查询成功: ', res)

  41. if (!res.data.length) {

  42. console.log(' 历史记录为空')

  43. let historyArray = []

  44. historyArray.unshift(content)

  45. db.collection('food').add({

  46. data: {

  47. _id: 'history' + that.data.openid,

  48. description: 'history',

  49. historyList: historyArray

  50. }

  51. }).then(res => {

  52. console.log(res)

  53. })

  54. } else {

  55. console.log('已有历史记录')

  56. let historyArray = res.data[0].historyList

  57. historyArray.unshift(content)

  58. console.log([...new Set(historyArray)])

  59. db.collection('food').doc('history' + that.data.openid).update({

  60. data: {

  61. historyList: [...new Set(historyArray)]

  62. }

  63. }).then((res) => {

  64. console.log(res)

  65. })

  66. }

  67. },

  68. fail: err => {

  69. wx.showToast({

  70. icon: 'none',

  71. title: '查询记录失败'

  72. })

  73. console.error('数据库查询失败:', err)

  74. }

  75. })

  76. },

  77.  
  78. // 读取历史记录

  79. getHistory() {

  80. let that = this

  81. const db = wx.cloud.database()

  82. db.collection('food').doc('history' + that.data.openid).get({

  83. success(res) {

  84. console.log(res.data)

  85. that.setData({

  86. historyList: res.data.historyList

  87. })

  88. }

  89. })

  90. },

  91.  
  92. // 清空历史记录

  93. bindClearHistory() {

  94. const db = wx.cloud.database()

  95. db.collection('food').doc('history' + this.data.openid).update({

  96. data: {

  97. historyList: []

  98. }

  99. }).then((res) => {

  100. console.log(res)

  101. wx.showToast({

  102. icon: '删除',

  103. title: '清空历史',

  104. })

  105. })

  106.  
  107. this.setData({

  108. historyList: []

  109. })

  110. }

  111. })

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值