list.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. lifetimes: {
  4. attached: function () {
  5. _Http[this.data.ownerid] = {
  6. changeReply: function (replyid = 0) {
  7. this.setData({
  8. replyid: replyid == this.data.replyid ? 0 : replyid
  9. })
  10. }.bind(this),
  11. updateCommentList: function () {
  12. this.triggerEvent("updateCommentList", {
  13. "ownertable": this.data.ownertable, //数据表
  14. "ownerid": this.data.ownerid,
  15. })
  16. }.bind(this)
  17. }
  18. this.setData({
  19. userid: wx.getStorageSync('userMsg').userid
  20. })
  21. getApp().globalData.Language.getLanguagePackage(this)
  22. },
  23. detached: function () {
  24. delete _Http[this.data.ownerid]
  25. },
  26. },
  27. properties: {
  28. quantity: {
  29. type: [String, Number],
  30. value: 0
  31. },
  32. comments: {
  33. type: Array,
  34. value: []
  35. },
  36. ownertable: {
  37. type: String,
  38. value: 'sys_datafollowup'
  39. },
  40. ownerid: {
  41. type: String
  42. },
  43. updateCommentList: {
  44. type: Function
  45. }
  46. },
  47. data: {
  48. loading: false,
  49. show: false,
  50. comment: '',
  51. replyid: 0
  52. },
  53. methods: {
  54. changeShow() {
  55. this.setData({
  56. show: !this.data.show
  57. })
  58. if (this.data.quantity && this.data.show) {
  59. const query = this.createSelectorQuery()
  60. query.select('#CommentNode' + this.data.ownerid).boundingClientRect()
  61. query.selectViewport().scrollOffset()
  62. query.exec(function (res) {
  63. if (wx.getWindowInfo().windowHeight - res[0].top < 100) return wx.pageScrollTo({
  64. scrollTop: res[1].scrollTop + 200,
  65. success() {
  66. _Http.scrollTop = scrollTop
  67. }
  68. })
  69. })
  70. }
  71. },
  72. onInput(e) {
  73. this.setData({
  74. comment: e.detail.value
  75. })
  76. },
  77. onSend() {
  78. this.setData({
  79. loading: true
  80. })
  81. _Http.basic({
  82. "id": 20240429161601,
  83. "content": {
  84. "ownertable": this.data.ownertable, //数据表
  85. "ownerid": this.data.ownerid,
  86. "content": this.data.comment,
  87. replyid: 0
  88. }
  89. }).then(res => {
  90. console.log("发送评论", res)
  91. this.setData({
  92. loading: false
  93. })
  94. wx.showToast({
  95. title: getApp().globalData.Language.getMapText(res.code == '1' ? '评论成功' : res.msg),
  96. icon: "none"
  97. })
  98. if (res.code == '1') {
  99. this.setData({
  100. comment: ""
  101. })
  102. _Http[this.data.ownerid].updateCommentList();
  103. }
  104. })
  105. },
  106. }
  107. })