particulars.js 5.2 KB

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