index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import HTTP from "../../../../../requestFn/Api"
  2. const app = getApp();
  3. Page({
  4. data: {
  5. detail: [],
  6. dialog: false,
  7. garden_id: null,
  8. event_id: null,
  9. autoplay: true,
  10. interval: 5000,
  11. duration: 3000,
  12. wrap: false,
  13. height: 0,
  14. },
  15. onLoad(options) {
  16. const that = this;
  17. const {
  18. garden_id
  19. } = app.globalData;
  20. that.setData({
  21. garden_id
  22. })
  23. const eventChannel = that.getOpenerEventChannel()
  24. eventChannel.on('acceptDataFromOpenerPage', function (data) {
  25. const {content} = data.data[0];
  26. const event_id = data.data[0].id
  27. that.setData({
  28. detail: data.data,
  29. event_id,
  30. content
  31. })
  32. })
  33. },
  34. onShow() {
  35. if (this.data.dialog) {
  36. const promise3 = new Promise((resolve, reject) => {
  37. wx.createSelectorQuery().select('#js_btn2_1')
  38. .boundingClientRect((rect) => {
  39. console.log(rect);
  40. resolve(rect.height);
  41. })
  42. .exec();
  43. });
  44. const promise4 = new Promise((resolve, reject) => {
  45. wx.createSelectorQuery().select('#js_btn2_2')
  46. .boundingClientRect((rect) => {
  47. resolve(rect.height);
  48. })
  49. .exec();
  50. });
  51. Promise.all([promise3, promise4]).then((values) => {
  52. if (values[0] != values[1]) {
  53. this.setData({
  54. wrap: true
  55. });
  56. }
  57. });
  58. }
  59. },
  60. eventSign() {
  61. this.setData({
  62. dialog: true,
  63. });
  64. },
  65. close() {
  66. this.setData({
  67. dialog: false,
  68. });
  69. },
  70. formSubmit(e) {
  71. const that = this;
  72. const {
  73. garden_id,
  74. event_id
  75. } = that.data
  76. const {
  77. name,
  78. phone,
  79. count,
  80. comment
  81. } = e.detail.value
  82. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  83. if (name == "") {
  84. wx.showToast({
  85. title: '请输入姓名',
  86. icon: "error",
  87. })
  88. return false
  89. }
  90. if (phone == "") {
  91. wx.showToast({
  92. title: '请输入手机号码',
  93. icon: "error",
  94. })
  95. return false
  96. }
  97. if (!/^1[345789]\d{9}$/.test(phone)) {
  98. wx.showToast({
  99. title: "手机号码有误",
  100. duration: 2000,
  101. icon: "error",
  102. });
  103. return false;
  104. }
  105. if (count == "") {
  106. wx.showToast({
  107. title: '请输入报名人数',
  108. icon: "error",
  109. })
  110. return false
  111. }
  112. HTTP.EventSign({
  113. garden_id,
  114. event_id,
  115. name,
  116. phone,
  117. count: count - 0,
  118. comment
  119. }).then(res => {
  120. if (res.code == 0) {
  121. wx.showToast({
  122. title: '报名成功',
  123. icon: "success",
  124. success() {
  125. that.close()
  126. wx.navigateBack({
  127. delta: 1,
  128. })
  129. }
  130. })
  131. }
  132. })
  133. },
  134. changeHeight(e) {
  135. const {
  136. height
  137. } = e.detail;
  138. console.log(height);
  139. this.setData({
  140. height
  141. })
  142. }
  143. })