diff --git a/pages/components/Comment/Comment.js b/pages/components/Comment/Comment.js index fcd9688..657ecdf 100644 --- a/pages/components/Comment/Comment.js +++ b/pages/components/Comment/Comment.js @@ -7,14 +7,17 @@ Component({ * 组件的属性列表 */ properties: { - comment: Object + comment: Object, + onDelete:{ + type:Function, + value:function(){} + } }, /** * 组件的初始数据 */ - data: { - }, + data: {}, /** * 组件的方法列表 @@ -22,10 +25,45 @@ Component({ methods: { tapComment: function () { wx.navigateTo({ - url:Requests.makeUrl("/pages/idel-comment/idel-comment",{ - _id:this.data.comment._id + url: Requests.makeUrl("/pages/idel-comment/idel-comment", { + _id: this.data.comment._id }) }) }, + + delete: function () { + let that = this + // 超级管理员用户学号 + var su = [ + "17152010921", + "16104050207" + ] + var ask = function () { + wx.showModal({ + content: "确定删除这条留言么?", + success(res) { + if (res.confirm) { + Requests.delete({ + url: "/idel-comment", + data: { + _id: that.data.comment._id + }, + success(data) { + that.data.onDelete() + } + }) + } + } + }) + } + Requests.getWithCache({ + url: '/user', + success(data) { + if (data.openid == that.data.comment.from_openid || su.indexOf(data.sno) != -1) { + ask() + } + } + }) + } } }) \ No newline at end of file diff --git a/pages/components/Comment/Comment.wxml b/pages/components/Comment/Comment.wxml index acc8170..dc4d6a6 100644 --- a/pages/components/Comment/Comment.wxml +++ b/pages/components/Comment/Comment.wxml @@ -1,4 +1,4 @@ - + {{comment.from.nickName}} diff --git a/pages/idel-detail/idel-detail.js b/pages/idel-detail/idel-detail.js index 9dc1771..43e68dc 100644 --- a/pages/idel-detail/idel-detail.js +++ b/pages/idel-detail/idel-detail.js @@ -14,13 +14,30 @@ Page({ }, + onDelete:function(){ + let that = this + // 请求评论数据 + Requests.get({ + url: "/idel-comment/" + that.data._id, + success(data) { + for (var i = 0; i < data.length; i++) { + data[i].create_time = data[i].create_time.split(".")[0] + } + that.setData({ + comments: data + }) + } + }) + }, + /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ _id: options._id, - contentHeight:app.globalData.systemInfo.windowHeight + contentHeight:app.globalData.systemInfo.windowHeight, + onDelete:this.onDelete }) let that = this //请求商品信息 @@ -47,19 +64,7 @@ Page({ }, onShow: function () { - let that = this - // 请求评论数据 - Requests.get({ - url: "/idel-comment/" + that.data._id, - success(data) { - for (var i = 0; i < data.length; i++) { - data[i].create_time = data[i].create_time.split(".")[0] - } - that.setData({ - comments: data - }) - } - }) + this.onDelete() }, tapImg: function (e) { diff --git a/pages/idel-detail/idel-detail.wxml b/pages/idel-detail/idel-detail.wxml index b01b994..a319756 100644 --- a/pages/idel-detail/idel-detail.wxml +++ b/pages/idel-detail/idel-detail.wxml @@ -18,7 +18,7 @@ - + diff --git a/utils/Requests.js b/utils/Requests.js index d51889f..c303df7 100644 --- a/utils/Requests.js +++ b/utils/Requests.js @@ -1,9 +1,9 @@ export class Requests { // static baseUrl = "http://127.0.0.1:8080/v1" // static baseUrl = "https://myncutdev.ncut.edu.cn/v1" - // static baseUrl = "https://myncut.ncut.edu.cn/v1" + static baseUrl = "https://myncut.ncut.edu.cn/v1" // static baseUrl = "http://10.211.55.3:8080/v1" - static baseUrl = "http://192.168.0.101/v1" + // static baseUrl = "http://192.168.0.101/v1" // 请求日志 static console = true