index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. options: {
  4. addGlobalClass: true
  5. },
  6. properties: {
  7. ownertable: {
  8. type: String
  9. },
  10. ownerid: {
  11. type: String
  12. },
  13. },
  14. data: {
  15. contentText: "",
  16. loading: false,
  17. content: {
  18. nocache: true,
  19. pageNumber: 1,
  20. pageSize: 20,
  21. pageTotal: 1,
  22. total: null
  23. },
  24. list: [],
  25. userid: wx.getStorageSync('userMsg').userid,
  26. replyid: 0,
  27. },
  28. lifetimes: {
  29. attached: function () {
  30. getApp().globalData.Language.getLanguagePackage(this)
  31. }
  32. },
  33. methods: {
  34. getList(id, init = false) {
  35. this.setData({
  36. userid: wx.getStorageSync('userMsg').userid
  37. })
  38. console.log("userid", this.data.userid)
  39. let content = {
  40. ...this.data.content,
  41. "ownertable": this.data.ownertable,
  42. "ownerid": this.data.ownerid,
  43. };
  44. if (init) {
  45. content.pageNumber = 1
  46. content.pageTotal = 1
  47. }
  48. _Http.basic({
  49. "id": 20240429161501,
  50. content
  51. }).then(res => {
  52. console.log("评论", res)
  53. if (res.code != '1') return wx.showToast({
  54. title: res.data,
  55. icon: "none"
  56. });
  57. this.setData({
  58. "content.pageNumber": res.pageNumber + 1,
  59. "content.pageTotal": res.pageTotal,
  60. "content.total": res.total,
  61. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  62. })
  63. })
  64. },
  65. textareaInput(e) {
  66. this.setData({
  67. contentText: e.detail.value
  68. })
  69. },
  70. onSend() {
  71. this.setData({
  72. loading: true
  73. })
  74. _Http.basic({
  75. "id": 20240429161601,
  76. "content": {
  77. "ownertable": this.data.ownertable, //数据表
  78. "ownerid": this.data.ownerid,
  79. "content": this.data.contentText,
  80. "replyid": "0"
  81. }
  82. }).then(res => {
  83. console.log("发送评论", res)
  84. this.setData({
  85. loading: false
  86. })
  87. wx.showToast({
  88. title: res.code == '1' ? getApp().globalData.Language.getMapText('评论成功') : res.msg,
  89. icon: "none"
  90. })
  91. if (res.code == '1') {
  92. this.getList(0, true)
  93. this.setData({
  94. contentText: ""
  95. })
  96. }
  97. })
  98. },
  99. deleteItem(e) {
  100. const {
  101. item
  102. } = e.currentTarget.dataset,
  103. that = this;
  104. wx.showModal({
  105. title: getApp().globalData.Language.getMapText('提示'),
  106. content: getApp().globalData.Language.getMapText('是否确定删除该评论') + '?',
  107. cancelText: getApp().globalData.Language.getMapText('取消'),
  108. confirmText: getApp().globalData.Language.getMapText('确定'),
  109. complete: ({
  110. confirm
  111. }) => {
  112. if (confirm) _Http.basic({
  113. "id": 20240429161701,
  114. "content": {
  115. "sys_datacommentid": item.sys_datacommentid
  116. }
  117. }).then(res => {
  118. console.log("删除评论", res)
  119. wx.showToast({
  120. title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg,
  121. icon: "none"
  122. });
  123. if (res.code == '1') that.setData({
  124. list: that.data.list.filter(v => v.sys_datacommentid != item.sys_datacommentid)
  125. })
  126. })
  127. }
  128. })
  129. },
  130. revert(e) {
  131. const {
  132. id
  133. } = e.currentTarget.dataset;
  134. this.setData({
  135. replyid: this.data.replyid == id ? 0 : id
  136. })
  137. },
  138. itemTextareaInput(e) {
  139. const {
  140. item
  141. } = e.currentTarget.dataset;
  142. let index = this.data.list.findIndex(v => v.sys_datacommentid == item.sys_datacommentid)
  143. this.setData({
  144. [`list[${index}].contentText`]: e.detail.value
  145. })
  146. },
  147. onSendItem() {
  148. let index = this.data.list.findIndex(v => v.sys_datacommentid == this.data.replyid),
  149. item = this.data.list[index];
  150. this.setData({
  151. [`list[${index}].loading`]: true
  152. })
  153. _Http.basic({
  154. "id": 20240429161601,
  155. "content": {
  156. "ownertable": this.data.ownertable, //数据表
  157. "ownerid": this.data.ownerid,
  158. "content": item.contentText,
  159. "replyid": this.data.replyid
  160. }
  161. }).then(res => {
  162. console.log("回复评论", res)
  163. this.setData({
  164. [`list[${index}].loading`]: false
  165. })
  166. wx.showToast({
  167. title: res.code == '1' ? getApp().globalData.Language.getMapText('回复成功') : res.msg,
  168. icon: "none"
  169. })
  170. if (res.code == '1') {
  171. this.getList(0, true);
  172. this.setData({
  173. replyid: 0
  174. })
  175. }
  176. })
  177. }
  178. }
  179. })