particulars.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // pages/particulars/particulars.js
  2. const app = getApp()
  3. const util = require('../../utils/util.js');
  4. const APIClient = require('../../utils/APIClient.js');
  5. const login = require('../../utils/loginSchedule.js');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. productionData: {},
  12. text: '',
  13. discussDatas: [],
  14. messageLength: '',
  15. type: '',
  16. favors: '',
  17. like: false,
  18. hike: false
  19. },
  20. /* 获取输入内容 */
  21. bindKeyInput (e) {
  22. this.setData({
  23. text: e.detail.value
  24. })
  25. },
  26. /*拉起键盘*/
  27. discuss() {
  28. this.setData({
  29. hike: true
  30. })
  31. },
  32. /* 发送评论 */
  33. sendText (e) {
  34. let text = this.data.text.trim();
  35. let postsId = e.currentTarget.dataset.id;
  36. let _this = this;
  37. if(text == ''){
  38. wx.showModal({
  39. title: '提示',
  40. content: '请输入评论内容',
  41. success: function(res) {
  42. if (res.confirm) {
  43. console.log('用户点击确定')
  44. } else if (res.cancel) {
  45. console.log('用户点击取消')
  46. }
  47. }
  48. })
  49. return false;
  50. }
  51. this.data.text = "";
  52. let data = {
  53. "postsId": postsId,
  54. "content": text
  55. };
  56. login.getOpenidSessionKey((res) => {
  57. //console.log(res.data.data.uid);
  58. APIClient.getDiscussSchedule({
  59. uid: res.data.data.uid
  60. }, data).success((res) => {
  61. if(res.data.success) {
  62. this.data.discussDatas.push(res.data.data);
  63. this.setData({
  64. discussDatas: this.data.discussDatas,
  65. messageLength: this.data.discussDatas.length
  66. });
  67. };
  68. });
  69. }, function() {
  70. wx.showModal({
  71. title: '提示',
  72. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  73. showCancel: false,
  74. success: function (res) {
  75. if (res.confirm) {
  76. console.log('用户点击确定')
  77. } else if (res.cancel) {
  78. console.log('用户点击取消')
  79. }
  80. }
  81. })
  82. });
  83. this.setData({
  84. text: ''
  85. })
  86. },
  87. /*预览图片*/
  88. listenerButtonPreviewImage: function(e) {
  89. let imgUrl = [];
  90. imgUrl.push(e.target.dataset.img);
  91. wx.previewImage({
  92. current: '', // 当前显示图片的http链接
  93. urls: imgUrl, // 需要预览的图片http链接列表
  94. //这根本就不走
  95. success: function(res) {
  96. //console.log(res);
  97. },
  98. //也根本不走
  99. fail: function() {
  100. //console.log('fail')
  101. }
  102. })
  103. },
  104. /*点赞接口*/
  105. like: function () {
  106. const postsId = util.getUrl().postId;
  107. //判断分享过来的参数是否有postId查询单挑显示
  108. if(postsId) {
  109. login.getOpenidSessionKey(res => {
  110. APIClient.getLikeSchedule({
  111. uid: res.data.data.uid
  112. }, {
  113. postsId,
  114. }).success(res => {
  115. console.log(res.data)
  116. if(res.data.success) {
  117. this.setData({
  118. favors: res.data.data.favors,
  119. like: true
  120. })
  121. }
  122. })
  123. }, function() {
  124. wx.showModal({
  125. title: '提示',
  126. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  127. showCancel: false,
  128. success: function (res) {
  129. if (res.confirm) {
  130. console.log('用户点击确定')
  131. } else if (res.cancel) {
  132. console.log('用户点击取消')
  133. }
  134. }
  135. })
  136. });
  137. };
  138. },
  139. /**
  140. * 生命周期函数--监听页面加载
  141. */
  142. onLoad: function (options) {
  143. const type = options.type;
  144. this.setData({
  145. type: type
  146. })
  147. if(type == 2) {
  148. wx.setNavigationBarTitle({
  149. title: '作品展示'
  150. })
  151. }
  152. if(type == 1) {
  153. wx.setNavigationBarTitle({
  154. title: '答疑讨论'
  155. })
  156. }
  157. const postsId = options.postId || '';
  158. //判断分享过来的参数是否有postId查询单挑显示
  159. if(postsId) {
  160. login.getOpenidSessionKey(res => {
  161. APIClient.getOneSchedule({
  162. uid: res.data.data.uid
  163. }, {
  164. postsId,
  165. }).success(res => {
  166. console.log(res.data)
  167. if(res.data.success) {
  168. this.setData({
  169. productionData: res.data.data,
  170. discussDatas: res.data.data.replyList,
  171. messageLength: res.data.data.replyList.length,
  172. favors:res.data.data.postsAttributeInfo.favors
  173. })
  174. }
  175. })
  176. }, function() {
  177. wx.showModal({
  178. title: '提示',
  179. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  180. showCancel: false,
  181. success: function (res) {
  182. if (res.confirm) {
  183. console.log('用户点击确定')
  184. } else if (res.cancel) {
  185. console.log('用户点击取消')
  186. }
  187. }
  188. })
  189. });
  190. };
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady: function () {
  196. },
  197. })