discuss.js 5.3 KB

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