index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // pages/login/login.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. searchForm: {},
  13. // 商品信息
  14. list: [],
  15. // 弹框
  16. dialog: { title: '详细信息', show: false, type: '1' },
  17. // 详细信息
  18. info: {
  19. id: '2', name: '测试商品2', number: '2',
  20. bnrUrl: [
  21. { "url": "/image/background.jpg" },
  22. { "url": "/image/background.jpg" },
  23. ]
  24. },
  25. },
  26. back: function () {
  27. wx.navigateBack({ url: '/pages/home/index' })
  28. },
  29. // 详细信息
  30. toView: function (e) {
  31. const { id } = e.currentTarget.dataset;
  32. console.log(id);
  33. // this.setData({ info: {} })
  34. this.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  35. },
  36. // 名称查询
  37. toSearch: function (e) {
  38. const { title } = e.currentTarget.dataset;
  39. wx.showModal({
  40. title: title == 'name' ? '名称查询' : '编号查询',
  41. content: '',
  42. editable: true,
  43. success: (res) => {
  44. if (res.confirm) {
  45. var key = `searchForm.${title}`
  46. this.setData({ [key]: res.content })
  47. this.search();
  48. }
  49. else if (res.cancel) {
  50. console.log('2');
  51. }
  52. }
  53. })
  54. },
  55. // 重置查询
  56. resetSearch: function () {
  57. this.setData({ searchForm: {} })
  58. this.search()
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad: function (options) {
  64. // 计算高度
  65. this.searchHeight();
  66. // 查询数据
  67. this.search();
  68. },
  69. // 查询数据
  70. search: function () {
  71. // 查询条件
  72. console.log(this.data.searchForm);
  73. let data = [
  74. { id: '1', name: '测试商品1', number: '1', },
  75. { id: '2', name: '测试商品2', number: '2', },
  76. ]
  77. this.setData({ list: data })
  78. },
  79. // 计算高度
  80. searchHeight: function () {
  81. let frameStyle = this.data.frameStyle;
  82. let client = app.globalData.client;
  83. // 减去状态栏
  84. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  85. // 是否减去底部菜单
  86. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  87. if (infoHeight) this.setData({ infoHeight: infoHeight })
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. }
  124. })