detail.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // pages/history/detail.js
  2. const app = getApp()
  3. import QRCode from '../../utils/weapp-qrcode'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. height: app.globalData.height * 2 + 25,
  10. windowHeight: app.globalData.windowHeight,
  11. navbarData: {
  12. name: '点餐详情'
  13. },
  14. logo: '',
  15. tenant: '',
  16. meal: {},
  17. info: {},
  18. show: false,
  19. },
  20. showQR() {
  21. this.setData({ show: true });
  22. },
  23. clearQR() {
  24. this.setData({ show: false });
  25. },
  26. noop() { },
  27. // 返回
  28. back: function () {
  29. wx.reLaunch({
  30. url: `/pages/history/index?openid=${app.globalData.wxInfo.openid}`
  31. })
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. this.searchST();
  38. const { id, label, date } = options
  39. // let id = '60d3ed0c55bc8a3b58245b73';
  40. // let label = '午餐';
  41. // let date = '2021-06-25';
  42. this.setData({ info: { label, date } })
  43. this.getMeal(id);
  44. this.initQrCode(id);
  45. },
  46. getMeal(id) {
  47. wx.request({
  48. url: `${app.globalData.publicUrl}/api/st/dining/order/getMeal/${id}`,
  49. method: "GET",
  50. header: { 'x-tenant': app.globalData.tenant },
  51. success: (res) => {
  52. if (res.data.errcode !== 0) return;
  53. let arr = res.data.data;
  54. arr = this.dealImg(arr)
  55. this.setData({ meal: arr })
  56. },
  57. error: (e) => {
  58. console.error(e)
  59. }
  60. })
  61. },
  62. dealImg(list) {
  63. for (let i of list.list) {
  64. if (i.img && i.img.length > 0 && i.img[0]) i.url = `${app.globalData.fileUrl}${i.img[0].url}`;
  65. else i.url = this.data.logo;
  66. }
  67. return list;
  68. },
  69. searchST: function () {
  70. wx.request({
  71. url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
  72. method: "get",
  73. header: { 'x-tenant': app.globalData.tenant },
  74. data: {},
  75. success: res => {
  76. const { data } = res.data;
  77. this.setData({ tenant: data.name });
  78. this.setData({ logo: `${app.globalData.fileUrl}` + data.img.logo })
  79. },
  80. error: err => {
  81. wx.showToast({
  82. title: err.msg,
  83. icon: 'error'
  84. })
  85. }
  86. })
  87. },
  88. // 创建二维码
  89. initQrCode(id) {
  90. const url = `${app.globalData.publicUrl}/api/st/dining/order/useMeal/${id}?_tenant=${this.data.tenant}`;
  91. var qrcode = new QRCode(`myQrcode`, {
  92. text: url,
  93. width: 130,
  94. height: 130,
  95. padding: 3,
  96. colorDark: "#000000",
  97. colorLight: "#ffffff",
  98. correctLevel: QRCode.CorrectLevel.L,
  99. });
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面隐藏
  113. */
  114. onHide: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload: function () {
  120. },
  121. /**
  122. * 页面相关事件处理函数--监听用户下拉动作
  123. */
  124. onPullDownRefresh: function () {
  125. },
  126. /**
  127. * 页面上拉触底事件的处理函数
  128. */
  129. onReachBottom: function () {
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. }
  136. })