alert.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. const app = getApp()
  2. const util = require("../../utils/util.js")
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. isShow: { // 弹窗显示-隐藏
  9. type: Boolean,
  10. value: true
  11. },
  12. c_code: { // 课题编号
  13. type: String,
  14. value: ''
  15. },
  16. type: { // 课程类型
  17. type: String,
  18. value: ''
  19. },
  20. info: Object // 课程预约信息
  21. },
  22. /**
  23. * 组件的初始数据
  24. */
  25. data: {
  26. success: false, // 报名成功
  27. // duedate: '', // 选择的日期
  28. b_count: 1, //参与人数
  29. name: '',
  30. phone: '',
  31. addOn: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/addOn.png',
  32. addOff: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/addOff.png',
  33. minusOn: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/minusOn.png',
  34. minusOff: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/minusOff.png',
  35. successImg: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/chenggong.png',
  36. b_time: 1,
  37. yxsj: [{ i: 1, t: '平日上午' }, { i: 2, t: '平日下午' }, { i: 3, t: '周末上午' }, { i: 4, t: '周末下午' }]
  38. },
  39. observers: {
  40. 'isShow': function (isShow) {
  41. if (!isShow) {
  42. if (this.properties.info && this.properties.info.name) {
  43. this.setData({
  44. name: this.properties.info.name,
  45. phone: this.properties.info.phone,
  46. duedate: this.properties.info.duedate,
  47. b_count: this.properties.info.b_count
  48. })
  49. }
  50. }
  51. }
  52. },
  53. attached: function() {
  54. if (!this.data.phone) {
  55. this.setData({
  56. phone: app.globalData.userphone
  57. })
  58. }
  59. },
  60. methods: {
  61. // 选择日期
  62. // bindDateChange: function(e) {
  63. // this.setData({
  64. // duedate: e.detail.value
  65. // })
  66. // },
  67. // 减参与人数
  68. minusBtn: function() {
  69. if (this.data.b_count < 2) return
  70. this.setData({
  71. b_count: this.data.b_count - 1
  72. })
  73. },
  74. // 加参与人数
  75. addBtn: function() {
  76. this.setData({
  77. b_count: this.data.b_count + 1
  78. })
  79. },
  80. // 选择意向时间
  81. cliYxsj: function(event) {
  82. this.setData({
  83. b_time: event.currentTarget.dataset.i
  84. })
  85. },
  86. // 提交
  87. submitForm: function(data) {
  88. let obj = {
  89. ...data.detail.value,
  90. openid: app.globalData.openid,
  91. college_code: this.properties.c_code,
  92. b_count: this.data.b_count
  93. }
  94. if (this.properties.type == 'tiyan') {
  95. delete obj.b_count
  96. obj.b_time = this.data.b_time
  97. }
  98. if (obj.phone.length < 11) {
  99. wx.showToast({
  100. title: '手机号填写不完整',
  101. icon: 'none',
  102. duration: 2000
  103. })
  104. return
  105. }
  106. if (!obj.name) {
  107. wx.showToast({
  108. title: '姓名不能为空',
  109. icon: 'none',
  110. duration: 2000
  111. })
  112. return
  113. }
  114. util.postData('/college/addCollegeBooking', obj)
  115. .then(res => {
  116. if (res == 1) {
  117. this.setData({
  118. success: true
  119. })
  120. }
  121. })
  122. },
  123. // 取消-or-点击遮罩层
  124. resetForm: function(data) {
  125. let isOver = this.data.success
  126. this.setData({ success: false })
  127. let mask = data.currentTarget.dataset.mask
  128. if (mask == 'mask') {
  129. // 这时候是点击的遮罩层
  130. this.triggerEvent('cancel', { cliType: 'mask', success: isOver }, {})
  131. } else {
  132. // 这个是点的取消预约-取消报名,开始执行取消
  133. util.postData('/college/bookingCancel', {
  134. openid: app.globalData.openid,
  135. college_code: this.properties.c_code,
  136. phone: app.globalData.userphone
  137. })
  138. .then(res => {
  139. if (res == 1) {
  140. this.setData({
  141. phone: app.globalData.userphone,
  142. b_count: 1,
  143. duedate: ''
  144. })
  145. this.triggerEvent('cancel', { cliType: 'cancel' }, {})
  146. }
  147. })
  148. }
  149. }
  150. }
  151. })