commentPost.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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').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. console.log(res)
  44. });
  45. },
  46. bindInpuntValue(event){
  47. let value = event.detail.value;
  48. //判断是否超过140个字符
  49. if (value && value.length > 140) {
  50. return false;
  51. }
  52. this.setData({
  53. content: event.detail.value,
  54. })
  55. console.log(event.detail)
  56. },
  57. onReady: function () {
  58. },
  59. onShow: function () {
  60. // 页面显示
  61. },
  62. onHide: function () {
  63. // 页面隐藏
  64. },
  65. onUnload: function () {
  66. // 页面关闭
  67. }
  68. })