detail.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. async getMeal(id) {
  47. const res = await app.$get(`/order/getMeal/${id}`);
  48. if (res.data.errcode !== 0) return;
  49. let arr = res.data.data;
  50. arr = this.dealImg(arr);
  51. this.setData({ meal: arr });
  52. // wx.request({
  53. // url: `${app.globalData.publicUrl}/api/st/dining/order/getMeal/${id}`,
  54. // method: 'GET',
  55. // success: (res) => {
  56. // if (res.data.errcode !== 0) return;
  57. // let arr = res.data.data;
  58. // arr = this.dealImg(arr);
  59. // this.setData({ meal: arr });
  60. // },
  61. // error: (e) => {
  62. // console.error(e);
  63. // },
  64. // });
  65. },
  66. dealImg(list) {
  67. for (let i of list.list) {
  68. if (i.img && i.img.length > 0 && i.img[0]) i.url = `${app.globalData.fileUrl}${i.img[0].url}`;
  69. else i.url = this.data.logo;
  70. }
  71. return list;
  72. },
  73. searchST: async function () {
  74. const res = await app.$get('/config');
  75. const logo = `${res.data.logo[0].url || ''}`;
  76. this.setData({ logo });
  77. // wx.request({
  78. // url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
  79. // method: 'get',
  80. // data: {},
  81. // success: (res) => {
  82. // const { data } = res.data;
  83. // this.setData({ tenant: data.name });
  84. // this.setData({ logo: `${app.globalData.fileUrl}` + data.img.logo });
  85. // },
  86. // error: (err) => {
  87. // wx.showToast({
  88. // title: err.msg,
  89. // icon: 'error',
  90. // });
  91. // },
  92. // });
  93. },
  94. // 创建二维码
  95. initQrCode(id) {
  96. const url = `${app.globalData.publicUrl}/st/api/order/useMeal/${id}`;
  97. // const url = `${app.globalData.publicUrl}/api/st/dining/order/useMeal/${id}`;
  98. var qrcode = new QRCode(`myQrcode`, {
  99. text: url,
  100. width: 130,
  101. height: 130,
  102. padding: 3,
  103. colorDark: '#000000',
  104. colorLight: '#ffffff',
  105. correctLevel: QRCode.CorrectLevel.L,
  106. });
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function () {},
  112. /**
  113. * 生命周期函数--监听页面显示
  114. */
  115. onShow: function () {},
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide: function () {},
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {},
  124. /**
  125. * 页面相关事件处理函数--监听用户下拉动作
  126. */
  127. onPullDownRefresh: function () {},
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {},
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage: function () {},
  136. });