particulars.js 5.7 KB

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