detail.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '需求信息添加', leftArrow: true, useBar: false },
  8. // 主体高度
  9. infoHeight: '',
  10. form: {},
  11. // 商品列表
  12. order: [],
  13. user_id: '12333',
  14. // 弹框
  15. dialog: { title: '添加商品', show: false, type: '1' },
  16. },
  17. back: function () {
  18. wx.navigateBack({ url: '/pages/apply/index' })
  19. },
  20. // 添加商品
  21. addOrder: function () {
  22. this.setData({ dialog: { title: '添加商品', show: true, type: '1' } })
  23. },
  24. // 商品保存
  25. orderSubmit: function (e) {
  26. const params = e.detail.value;
  27. if (!params.name) wx.showToast({ title: `商品名称`, icon: 'error', duration: 2000 });
  28. else if (!params.num) wx.showToast({ title: `商品数量`, icon: 'error', duration: 2000 });
  29. if (params.name && params.num) {
  30. this.setData({ order: [...this.data.order, params] });
  31. this.setData({ orderForm: {} });
  32. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } });
  33. }
  34. },
  35. // 商品取消保存
  36. orderReset: function (e) {
  37. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } })
  38. },
  39. // 取消保存
  40. onReset: function (e) {
  41. this.back()
  42. },
  43. // 提交保存
  44. onSubmit: function (e) {
  45. const params = e.detail.value;
  46. params.order = this.data.order;
  47. params.user_id = this.data.user_id;
  48. console.log(params);
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. // 监听用户是否登录
  55. // this.watchLogin();
  56. // 计算高度
  57. this.searchHeight();
  58. },
  59. // 计算高度
  60. searchHeight: function () {
  61. let frameStyle = this.data.frameStyle;
  62. let client = app.globalData.client;
  63. // 减去状态栏
  64. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  65. // 是否减去底部菜单
  66. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  67. if (infoHeight) this.setData({ infoHeight: infoHeight })
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. },
  99. /**
  100. * 用户点击右上角分享
  101. */
  102. onShareAppMessage: function () {
  103. }
  104. })