discuss.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // compontents/discuss/discuss.js
  2. const APIClient = require('../../utils/APIClient.js');
  3. Component({
  4. relations: {
  5. './custom-ul': {
  6. type: 'parent', // 关联的目标节点应为父节点
  7. linked: function(target) {
  8. // 每次被插入到custom-ul时执行,target是custom-ul节点实例对象,触发在attached生命周期之后
  9. },
  10. linkChanged: function(target) {
  11. // 每次被移动后执行,target是custom-ul节点实例对象,触发在moved生命周期之后
  12. },
  13. unlinked: function(target) {
  14. // 每次被移除时执行,target是custom-ul节点实例对象,触发在detached生命周期之后
  15. }
  16. }
  17. },
  18. /**
  19. * 组件的属性列表
  20. */
  21. properties: {
  22. discussData: {
  23. type: Array,
  24. value: []
  25. },
  26. uid: {
  27. type: String,
  28. value: ''
  29. }
  30. },
  31. /**
  32. * 组件的初始数据
  33. */
  34. data: {
  35. flag: false,
  36. text: '',
  37. discussDatas: [],
  38. animationData: {},
  39. messageLength: ''
  40. },
  41. /**
  42. * 组件的方法列表
  43. */
  44. methods: {
  45. onTap (e) {
  46. let flage = e.target.dataset.flag;
  47. if(flage){
  48. this.util(flage, '0rpx');
  49. this.setData({'flag': false})
  50. } else {
  51. this.util(flage, '800rpx');
  52. this.setData({'flag': true})
  53. }
  54. },
  55. /* 创建动画并执行 */
  56. util (flag, height) {
  57. // 创建动画实例
  58. var animation = wx.createAnimation({
  59. duration: 200, //动画时长
  60. timingFunction: "linear", //线性
  61. delay: 0 //0则不延迟
  62. });
  63. this.animation = animation;
  64. animation.height(height).step();
  65. this.setData({
  66. animationData: animation.export()
  67. })
  68. },
  69. /* 获取输入内容 */
  70. bindKeyInput (e) {
  71. this.setData({
  72. text: e.detail.value
  73. })
  74. },
  75. /* 发送评论 */
  76. sendText () {
  77. //console.log(this.data.text.trim())
  78. let text = this.data.text.trim();
  79. let postsId = this.properties.postsId;
  80. let _this = this;
  81. let header = {
  82. uid: 'e7e0d43a-36b1-4e71-a3a3-61469c90d0a2'
  83. }
  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. "userId": header.uid,
  101. "postsId": postsId,
  102. "content": text
  103. };
  104. APIClient.getDiscussSchedule(header, data).success(function (res) {
  105. console.log(res.data)
  106. if(res.data.success) {
  107. _this.properties.discussData.push(res.data.data);
  108. _this.setData({
  109. discussDatas: _this.properties.discussData,
  110. messageLength: _this.properties.discussData.length
  111. });
  112. };
  113. });
  114. this.setData({
  115. text: ''
  116. })
  117. }
  118. },
  119. ready () {
  120. this.setData({
  121. discussDatas: this.properties.discussData
  122. })
  123. }
  124. })