index.js 6.0 KB

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