index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // nova-lesson/pages/lesson-detail/write-comment/index.js
  2. let Parse = getApp().Parse;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. rate: 0,
  9. content: '',
  10. uploadURL: "",
  11. domain: "",
  12. uptokenURL: "",
  13. fileList: [],
  14. activeColor: getApp().globalData.activeColor,
  15. titleColor: getApp().globalData.titleColor,
  16. },
  17. onChange(e) {
  18. let rate = this.data.rate
  19. this.setData({
  20. rate: e.detail
  21. })
  22. },
  23. blur(e) {
  24. let content = e.currentTarget.dataset.name
  25. this.setData({
  26. content: e.detail.value
  27. })
  28. },
  29. changeFile(e) {
  30. console.log(e)
  31. if (e.detail && e.detail.length > 0) {
  32. let fileList = []
  33. let filearr = e.detail
  34. filearr.forEach(file => {
  35. fileList.push(file.url)
  36. })
  37. this.setData({
  38. image: fileList
  39. })
  40. } else {
  41. this.setData({
  42. image: []
  43. })
  44. }
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: async function(options) {
  50. let activeColor = getApp().globalData.activeColor
  51. let titleColor = getApp().globalData.titleColor
  52. let {
  53. id
  54. } = options
  55. this.setData({
  56. id: id,
  57. activeColor: activeColor,
  58. titleColor: titleColor
  59. })
  60. console.log(id);
  61. },
  62. async confirm(e) {
  63. let type = e.currentTarget.dataset.type
  64. console.log(this.data.rate, this.data.content, this.data.fileList);
  65. switch (type) {
  66. case "cencle":
  67. wx.navigateBack();
  68. break;
  69. case "submit":
  70. if (this.data.rate < 0 || !this.data.content) {
  71. wx.showToast({
  72. title: '请填写内容',
  73. icon: 'none',
  74. duration: 1500,
  75. });
  76. return
  77. } else {
  78. wx.showModal({
  79. title: '提交评价',
  80. content: '是否确认提交评价',
  81. showCancel: true,
  82. cancelText: '取消',
  83. cancelColor: '#000000',
  84. confirmText: '确定',
  85. confirmColor: '#3CC51F',
  86. success: async(result) => {
  87. let dis = await this.setDiscuss()
  88. if (result.confirm) {
  89. if (dis) {
  90. wx.showToast({
  91. title: '提交成功',
  92. icon: 'success',
  93. });
  94. wx.redirectTo({
  95. url: '/nova-lesson/pages/lesson-detail/lesson-detail?id=' + this.data.id
  96. });
  97. } else {
  98. wx.showToast({
  99. title: '提交失败',
  100. icon: 'none',
  101. });
  102. }
  103. } else {
  104. wx.showToast({
  105. title: '取消提交',
  106. icon: 'none',
  107. });
  108. }
  109. },
  110. fail: () => {},
  111. complete: () => {}
  112. });
  113. }
  114. break;
  115. }
  116. },
  117. async setDiscuss() {
  118. let LessonComment = Parse.Object.extend("LessonComment")
  119. let lessonComment = new LessonComment()
  120. lessonComment.set("score", this.data.rate)
  121. lessonComment.set("content", this.data.content)
  122. lessonComment.set("images", this.data.images)
  123. lessonComment.set("user", {
  124. __type: "Pointer",
  125. className: "_User",
  126. objectId: Parse.User.current().id
  127. });
  128. lessonComment.set("company", {
  129. __type: "Pointer",
  130. className: "Company",
  131. objectId: getApp().globalData.company
  132. })
  133. lessonComment.set("lesson", {
  134. __type: "Pointer",
  135. className: "Lesson",
  136. objectId: this.data.id
  137. })
  138. let result = await lessonComment.save();
  139. if (result && result.id) {
  140. return result
  141. } else {
  142. return false
  143. }
  144. },
  145. /**
  146. * 生命周期函数--监听页面初次渲染完成
  147. */
  148. onReady: function() {
  149. },
  150. /**
  151. * 生命周期函数--监听页面显示
  152. */
  153. onShow: function() {
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide: function() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload: function() {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh: function() {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom: function() {
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage: function() {
  179. }
  180. })