discuss.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // compontents/discuss/discuss.js
  2. const APIClient = require('../../utils/APIClient.js');
  3. const login = require('../../utils/loginSchedule.js');
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. discussData: {
  10. type: Array,
  11. value: []
  12. },
  13. uid: {
  14. type: String,
  15. value: ''
  16. },
  17. type: {
  18. type: String,
  19. value: ''
  20. },
  21. postsId: {
  22. type: String,
  23. value: ''
  24. }
  25. },
  26. /**
  27. * 组件的初始数据
  28. */
  29. data: {
  30. flag: false,
  31. text: '',
  32. discussDatas: [],
  33. animationData: {},
  34. messageLength: '',
  35. downUp: '展开'
  36. },
  37. /**
  38. * 组件的方法列表
  39. */
  40. methods: {
  41. onTap (e) {
  42. let flage = e.target.dataset.flag;
  43. if(flage){
  44. this.util(flage, '0rpx');
  45. this.setData({
  46. 'flag': false,
  47. 'downUp': '展开'
  48. })
  49. } else {
  50. this.util(flage, '800rpx');
  51. this.setData({
  52. 'flag': true,
  53. 'downUp': '收起'
  54. })
  55. }
  56. },
  57. /* 创建动画并执行 */
  58. util (flag, height) {
  59. // 创建动画实例
  60. var animation = wx.createAnimation({
  61. duration: 200, //动画时长
  62. timingFunction: "linear", //线性
  63. delay: 0 //0则不延迟
  64. });
  65. this.animation = animation;
  66. animation.height(height).step();
  67. this.setData({
  68. animationData: animation.export()
  69. })
  70. },
  71. /* 获取输入内容 */
  72. bindKeyInput (e) {
  73. this.setData({
  74. text: e.detail.value
  75. })
  76. },
  77. /* 发送评论 */
  78. sendText () {
  79. //console.log(this.data.text.trim())
  80. let text = this.data.text.trim();
  81. let postsId = this.properties.postsId;
  82. let _this = this;
  83. if(text == ''){
  84. wx.showModal({
  85. title: '提示',
  86. content: '请输入评论内容',
  87. success: function(res) {
  88. if (res.confirm) {
  89. console.log('用户点击确定')
  90. } else if (res.cancel) {
  91. console.log('用户点击取消')
  92. }
  93. }
  94. })
  95. return false;
  96. }
  97. this.data.text = "";
  98. let data = {
  99. "postsId": postsId,
  100. "content": text
  101. };
  102. login.getOpenidSessionKey(function(res) {
  103. //console.log(res.data.data.uid);
  104. APIClient.getDiscussSchedule({
  105. uid: res.data.data.uid
  106. }, data).success(function (res) {
  107. console.log(res.data)
  108. if(res.data.success) {
  109. _this.properties.discussData.push(res.data.data);
  110. _this.setData({
  111. discussDatas: _this.properties.discussData,
  112. messageLength: _this.properties.discussData.length
  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. this.setData({
  131. text: ''
  132. })
  133. }
  134. },
  135. ready () {
  136. this.setData({
  137. discussDatas: this.properties.discussData
  138. })
  139. }
  140. })