| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- const _Http = getApp().globalData.http;
- Component({
- options: {
- addGlobalClass: true
- },
- properties: {
- ownertable: {
- type: String
- },
- ownerid: {
- type: String
- },
- },
- data: {
- contentText: "",
- loading: false,
- content: {
- nocache: true,
- pageNumber: 1,
- pageSize: 20,
- pageTotal: 1,
- total: null
- },
- list: [],
- userid: wx.getStorageSync('userMsg').userid,
- replyid: 0,
- },
- lifetimes: {
- attached: function () {
- getApp().globalData.Language.getLanguagePackage(this)
- }
- },
- methods: {
- getList(id, init = false) {
- this.setData({
- userid: wx.getStorageSync('userMsg').userid
- })
- console.log("userid", this.data.userid)
- let content = {
- ...this.data.content,
- "ownertable": this.data.ownertable,
- "ownerid": this.data.ownerid,
- };
- if (init) {
- content.pageNumber = 1
- content.pageTotal = 1
- }
- _Http.basic({
- "id": 20240429161501,
- content
- }).then(res => {
- console.log("评论", res)
- if (res.code != '1') return wx.showToast({
- title: res.data,
- icon: "none"
- });
- this.setData({
- "content.pageNumber": res.pageNumber + 1,
- "content.pageTotal": res.pageTotal,
- "content.total": res.total,
- list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
- })
- })
- },
- textareaInput(e) {
- this.setData({
- contentText: e.detail.value
- })
- },
- onSend() {
- this.setData({
- loading: true
- })
- _Http.basic({
- "id": 20240429161601,
- "content": {
- "ownertable": this.data.ownertable, //数据表
- "ownerid": this.data.ownerid,
- "content": this.data.contentText,
- "replyid": "0"
- }
- }).then(res => {
- console.log("发送评论", res)
- this.setData({
- loading: false
- })
- wx.showToast({
- title: res.code == '1' ? getApp().globalData.Language.getMapText('评论成功') : res.msg,
- icon: "none"
- })
- if (res.code == '1') {
- this.getList(0, true)
- this.setData({
- contentText: ""
- })
- }
- })
- },
- deleteItem(e) {
- const {
- item
- } = e.currentTarget.dataset,
- that = this;
- wx.showModal({
- title: getApp().globalData.Language.getMapText('提示'),
- content: getApp().globalData.Language.getMapText('是否确定删除该评论') + '?',
- cancelText: getApp().globalData.Language.getMapText('取消'),
- confirmText: getApp().globalData.Language.getMapText('确定'),
- complete: ({
- confirm
- }) => {
- if (confirm) _Http.basic({
- "id": 20240429161701,
- "content": {
- "sys_datacommentid": item.sys_datacommentid
- }
- }).then(res => {
- console.log("删除评论", res)
- wx.showToast({
- title: res.code == '1' ? getApp().globalData.Language.getMapText('删除成功') : res.msg,
- icon: "none"
- });
- if (res.code == '1') that.setData({
- list: that.data.list.filter(v => v.sys_datacommentid != item.sys_datacommentid)
- })
- })
- }
- })
- },
- revert(e) {
- const {
- id
- } = e.currentTarget.dataset;
- this.setData({
- replyid: this.data.replyid == id ? 0 : id
- })
- },
- itemTextareaInput(e) {
- const {
- item
- } = e.currentTarget.dataset;
- let index = this.data.list.findIndex(v => v.sys_datacommentid == item.sys_datacommentid)
- this.setData({
- [`list[${index}].contentText`]: e.detail.value
- })
- },
- onSendItem() {
- let index = this.data.list.findIndex(v => v.sys_datacommentid == this.data.replyid),
- item = this.data.list[index];
- this.setData({
- [`list[${index}].loading`]: true
- })
- _Http.basic({
- "id": 20240429161601,
- "content": {
- "ownertable": this.data.ownertable, //数据表
- "ownerid": this.data.ownerid,
- "content": item.contentText,
- "replyid": this.data.replyid
- }
- }).then(res => {
- console.log("回复评论", res)
- this.setData({
- [`list[${index}].loading`]: false
- })
- wx.showToast({
- title: res.code == '1' ? getApp().globalData.Language.getMapText('回复成功') : res.msg,
- icon: "none"
- })
- if (res.code == '1') {
- this.getList(0, true);
- this.setData({
- replyid: 0
- })
- }
- })
- }
- }
- })
|