index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/market/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '商品管理', leftArrow: true, useBar: false },
  9. // 主体高度
  10. infoHeight: '',
  11. // 商品列表
  12. list: [],
  13. // 弹框
  14. dialog: { title: '详细信息', show: false, type: '1' },
  15. // 详细信息
  16. info: {},
  17. },
  18. back: function () {
  19. wx.navigateBack({ url: '/pages/home/index' })
  20. },
  21. // 添加采购申请
  22. toAdd: function () {
  23. wx.navigateTo({ url: `/pages/market/detail` })
  24. },
  25. // 详细信息
  26. toView: function (e) {
  27. let item = e.currentTarget.dataset.item;
  28. this.setData({ info: item })
  29. this.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  30. },
  31. // 上架,下架
  32. toCheck: function (e) {
  33. wx.showModal({
  34. title: '操作提示',
  35. content: '您确认上架/下架此产品吗?',
  36. success: (res) => {
  37. if (res.confirm) {
  38. wx.showToast({ title: `操作成功`, icon: 'success', duration: 2000 })
  39. }
  40. }
  41. })
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. this.watchLogin();
  48. // 计算高度
  49. this.searchHeight();
  50. },
  51. // 监听用户是否登录
  52. watchLogin: function () {
  53. let data = [
  54. { name: '喜羊羊', type_name: '羊肉', money: '22', status: '1', brief: '一份' },
  55. { name: '喜羊羊', type_name: '羊肉', money: '22', status: '0', brief: '一份' },
  56. { name: '喜羊羊', type_name: '羊肉', money: '22', status: '1', brief: '一份' },]
  57. this.setData({ list: data })
  58. // wx.getStorage({
  59. // key: 'user',
  60. // success: res => {
  61. // if (res.data) {
  62. // // 查询菜单
  63. // if (res.data) this.searchRouter(res.data);
  64. // res.data.type = type.find((i) => i.value == res.data.type).label;
  65. // if (res.data) this.setData({ userInfo: res.data });
  66. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  67. // } else {
  68. // wx.redirectTo({ url: '/pages/login/index', })
  69. // }
  70. // }
  71. // })
  72. },
  73. // 计算高度
  74. searchHeight: function () {
  75. let frameStyle = this.data.frameStyle;
  76. let client = app.globalData.client;
  77. // 减去状态栏
  78. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  79. // 是否减去底部菜单
  80. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  81. if (infoHeight) this.setData({ infoHeight: infoHeight })
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow: function () {
  92. this.onLoad()
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })