commentPost.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var api = require('../../config/api.js');
  4. Page({
  5. data: {
  6. typeId: 0,
  7. valueId: 0,
  8. content: ''
  9. },
  10. onLoad: function (options) {
  11. var that = this;
  12. that.setData({
  13. typeId: parseInt(options.typeId),
  14. valueId: parseInt(options.valueId)
  15. });
  16. },
  17. onClose() {
  18. wx.navigateBack({
  19. delta: 1
  20. });
  21. },
  22. onPost() {
  23. let that = this;
  24. if (!this.data.content) {
  25. util.showErrorToast('请填写评论')
  26. return false;
  27. }
  28. util.request(api.CommentPost, {
  29. typeId: that.data.typeId,
  30. valueId: that.data.valueId,
  31. content: that.data.content
  32. }, 'POST', 'application/json').then(function (res) {
  33. if (res.errno === 0) {
  34. wx.showToast({
  35. title: '评论成功',
  36. complete: function(){
  37. wx.navigateBack({
  38. delta: 1
  39. });
  40. }
  41. })
  42. }
  43. });
  44. },
  45. bindInpuntValue(event){
  46. let value = event.detail.value;
  47. //判断是否超过140个字符
  48. if (value && value.length > 140) {
  49. return false;
  50. }
  51. this.setData({
  52. content: event.detail.value,
  53. })
  54. },
  55. onReady: function () {
  56. },
  57. onShow: function () {
  58. // 页面显示
  59. },
  60. onHide: function () {
  61. // 页面隐藏
  62. },
  63. onUnload: function () {
  64. // 页面关闭
  65. }
  66. })