discuss.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. */
  9. properties: {
  10. discussData: {
  11. type: Array,
  12. value: []
  13. },
  14. uid: {
  15. type: String,
  16. value: ''
  17. },
  18. type: {
  19. type: String,
  20. value: ''
  21. },
  22. postsId: {
  23. type: String,
  24. value: ''
  25. }
  26. },
  27. /**
  28. * 组件的初始数据
  29. */
  30. data: {
  31. flag: false,
  32. text: '',
  33. discussDatas: [],
  34. animationData: {},
  35. messageLength: '',
  36. downUp: '展开'
  37. },
  38. /**
  39. * 组件的方法列表
  40. */
  41. methods: {
  42. onTap (e) {
  43. let flage = e.target.dataset.flag;
  44. if(flage){
  45. this.util(flage, '0rpx');
  46. this.setData({
  47. 'flag': false,
  48. 'downUp': '展开'
  49. })
  50. } else {
  51. this.util(flage, '800rpx');
  52. this.setData({
  53. 'flag': true,
  54. 'downUp': '收起'
  55. })
  56. }
  57. },
  58. /* 创建动画并执行 */
  59. util (flag, height) {
  60. // 创建动画实例
  61. var animation = wx.createAnimation({
  62. duration: 200, //动画时长
  63. timingFunction: "linear", //线性
  64. delay: 0 //0则不延迟
  65. });
  66. this.animation = animation;
  67. animation.height(height).step();
  68. this.setData({
  69. animationData: animation.export()
  70. })
  71. },
  72. /* 获取输入内容 */
  73. bindKeyInput (e) {
  74. this.setData({
  75. text: e.detail.value
  76. })
  77. },
  78. /* 发送评论 */
  79. sendText () {
  80. //console.log(this.data.text.trim())
  81. let text = this.data.text.trim();
  82. let postsId = this.properties.postsId;
  83. let _this = this;
  84. if(text == ''){
  85. wx.showModal({
  86. title: '提示',
  87. content: '请输入评论内容',
  88. success: function(res) {
  89. if (res.confirm) {
  90. console.log('用户点击确定')
  91. } else if (res.cancel) {
  92. console.log('用户点击取消')
  93. }
  94. }
  95. })
  96. return false;
  97. }
  98. this.data.text = "";
  99. let data = {
  100. "postsId": postsId,
  101. "content": text
  102. };
  103. login.getOpenidSessionKey(function(res) {
  104. //console.log(res.data.data.uid);
  105. APIClient.getDiscussSchedule({
  106. uid: res.data.data.uid
  107. }, data).success(function (res) {
  108. console.log(res.data)
  109. if(res.data.success) {
  110. _this.properties.discussData.push(res.data.data);
  111. _this.setData({
  112. discussDatas: _this.properties.discussData,
  113. messageLength: _this.properties.discussData.length
  114. });
  115. };
  116. });
  117. }, function() {
  118. wx.showModal({
  119. title: '提示',
  120. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除勋章战士后再次扫码进入,允许授权后可正常使用',
  121. showCancel: false,
  122. success: function (res) {
  123. if (res.confirm) {
  124. console.log('用户点击确定')
  125. } else if (res.cancel) {
  126. console.log('用户点击取消')
  127. }
  128. }
  129. })
  130. });
  131. this.setData({
  132. text: ''
  133. })
  134. }
  135. },
  136. ready () {
  137. this.setData({
  138. discussDatas: this.properties.discussData
  139. })
  140. }
  141. })