discuss.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // compontents/discuss/discuss.js
  2. const APIClient = require('../../utils/APIClient.js');
  3. const login = require('../../utils/loginSchedule.js');
  4. Component({
  5. relations: {
  6. '../chat/chat': {
  7. type: 'parent', // 关联的目标节点应为父节点
  8. linked: function(target) {
  9. // 每次被插入到custom-ul时执行,target是custom-ul节点实例对象,触发在attached生命周期之后
  10. console.log(target)
  11. },
  12. linkChanged: function(target) {
  13. // 每次被移动后执行,target是custom-ul节点实例对象,触发在moved生命周期之后
  14. console.log(target)
  15. },
  16. unlinked: function(target) {
  17. // 每次被移除时执行,target是custom-ul节点实例对象,触发在detached生命周期之后
  18. console.log(target)
  19. }
  20. }
  21. },
  22. /**
  23. * 组件的属性列表
  24. */
  25. properties: {
  26. discussData: {
  27. type: Array,
  28. value: []
  29. },
  30. uid: {
  31. type: String,
  32. value: ''
  33. },
  34. type: {
  35. type: String,
  36. value: ''
  37. },
  38. postsId: {
  39. type: String,
  40. value: ''
  41. }
  42. },
  43. /**
  44. * 组件的初始数据
  45. */
  46. data: {
  47. flag: false,
  48. text: '',
  49. discussDatas: [],
  50. animationData: {},
  51. messageLength: ''
  52. },
  53. /**
  54. * 组件的方法列表
  55. */
  56. methods: {
  57. onTap (e) {
  58. let flage = e.target.dataset.flag;
  59. if(flage){
  60. this.util(flage, '0rpx');
  61. this.setData({'flag': false})
  62. } else {
  63. this.util(flage, '800rpx');
  64. this.setData({'flag': true})
  65. }
  66. },
  67. /* 创建动画并执行 */
  68. util (flag, height) {
  69. // 创建动画实例
  70. var animation = wx.createAnimation({
  71. duration: 200, //动画时长
  72. timingFunction: "linear", //线性
  73. delay: 0 //0则不延迟
  74. });
  75. this.animation = animation;
  76. animation.height(height).step();
  77. this.setData({
  78. animationData: animation.export()
  79. })
  80. },
  81. /* 获取输入内容 */
  82. bindKeyInput (e) {
  83. this.setData({
  84. text: e.detail.value
  85. })
  86. },
  87. /* 发送评论 */
  88. sendText () {
  89. //console.log(this.data.text.trim())
  90. let text = this.data.text.trim();
  91. let postsId = this.properties.postsId;
  92. let _this = this;
  93. if(text == ''){
  94. wx.showModal({
  95. title: '提示',
  96. content: '请输入评论内容',
  97. success: function(res) {
  98. if (res.confirm) {
  99. console.log('用户点击确定')
  100. } else if (res.cancel) {
  101. console.log('用户点击取消')
  102. }
  103. }
  104. })
  105. return false;
  106. }
  107. this.data.text = "";
  108. let data = {
  109. "postsId": postsId,
  110. "content": text
  111. };
  112. login.getOpenidSessionKey(function(res) {
  113. //console.log(res.data.data.uid);
  114. APIClient.getDiscussSchedule({
  115. uid: res.data.data.uid
  116. }, data).success(function (res) {
  117. console.log(res.data)
  118. if(res.data.success) {
  119. _this.properties.discussData.push(res.data.data);
  120. _this.setData({
  121. discussDatas: _this.properties.discussData,
  122. messageLength: _this.properties.discussData.length
  123. });
  124. };
  125. });
  126. }, function() {
  127. wx.showModal({
  128. title: '提示',
  129. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  130. showCancel: false,
  131. success: function (res) {
  132. if (res.confirm) {
  133. console.log('用户点击确定')
  134. } else if (res.cancel) {
  135. console.log('用户点击取消')
  136. }
  137. }
  138. })
  139. });
  140. this.setData({
  141. text: ''
  142. })
  143. }
  144. },
  145. ready () {
  146. this.setData({
  147. discussDatas: this.properties.discussData
  148. })
  149. }
  150. })