bottomTabs.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const net = require("../../utils/net.js");
  2. const utils = require("../../utils/util.js");
  3. const { api_material_like } = require("../../utils/api.js");
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. subId: {
  10. type: Number,
  11. value: 0,
  12. },
  13. isLike: {
  14. type: Number,
  15. value: 0,
  16. observer: function (newVal) {
  17. // 属性值变化时执行
  18. this.setData({
  19. isAttention: newVal || 0,
  20. });
  21. },
  22. },
  23. likeNum: {
  24. type: Number,
  25. value: 0,
  26. },
  27. commentNum: {
  28. type: Number,
  29. value: 0,
  30. },
  31. isAuthor: {
  32. type: Number,
  33. value: 0,
  34. },
  35. placeholder: {
  36. type: String,
  37. value: "说点什么…",
  38. },
  39. },
  40. /**
  41. * 组件的初始数据
  42. */
  43. data: {
  44. isAttention: 0,
  45. },
  46. /**
  47. * 组件的方法列表
  48. */
  49. methods: {
  50. tapLikeAction: function () {
  51. const userinfo = utils.getStorageSync("USERINFO");
  52. if (userinfo && userinfo.token) {
  53. let params = {};
  54. params.url = api_material_like;
  55. params.data = {
  56. id: this.properties.subId,
  57. };
  58. net.req(params, true).then(
  59. (data) => {
  60. this.triggerEvent("like", {
  61. isLike: data.isLike == 1 ? false : true,
  62. likeNum: data.likeNum,
  63. });
  64. this.setData({
  65. isAttention: this.data.isAttention == 1 ? 0 : 1,
  66. });
  67. },
  68. (e) => {
  69. utils.showToast({
  70. title: e.msg,
  71. });
  72. }
  73. );
  74. } else {
  75. wx.navigateTo({ url: `/pages/login/login` });
  76. }
  77. },
  78. tapPostAction: function () {
  79. this.triggerEvent("poster");
  80. },
  81. tapDeleteAction() {},
  82. tapReplyAction() {
  83. this.triggerEvent("reply", { isComment: true });
  84. },
  85. tapCommentAction() {
  86. this.triggerEvent("message");
  87. },
  88. },
  89. });