detail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var app = getApp();
  2. Page({
  3. data: {
  4. userInfo: null,
  5. archivesInfo: { article: {} },
  6. commentList: [],
  7. loading: false,
  8. nodata: false,
  9. nomore: false,
  10. form: { quotepid: 0, message: '', focus: false }
  11. },
  12. page: 1,
  13. onLoad: function (options) {
  14. var that = this;
  15. that.setData({ userInfo: app.globalData.userInfo });
  16. app.request('/addons/cms/wxapp.archives/detail', { id: options.id }, function (data, ret) {
  17. var content = data.archivesInfo.content;
  18. //图片列表需要拆分为数组
  19. data.archivesInfo.productlist = data.archivesInfo.productdata.split(/\,/);
  20. data.archivesInfo.productlist.forEach(function (item, index) {
  21. data.archivesInfo.productlist[index] = app.cdnurl(item);
  22. });
  23. console.log(data.archivesInfo.productlist);
  24. that.setData({ archivesInfo: data.archivesInfo, commentList: data.commentList });
  25. that.page++;
  26. }, function (data, ret) {
  27. app.error(ret.msg);
  28. });
  29. },
  30. preview:function(event){
  31. var that = this;
  32. wx.previewImage({
  33. current: event.currentTarget.dataset.url,
  34. urls: that.data.archivesInfo.productlist
  35. });
  36. },
  37. reply: function (event) {
  38. var that = this;
  39. var pid = event.currentTarget.dataset.pid;
  40. var nickname = event.currentTarget.dataset.nickname;
  41. that.setData({ form: { quotepid: pid, message: '@' + nickname + ' ', focus: true } });
  42. },
  43. login: function (event) {
  44. var that = this;
  45. app.login(function (data) {
  46. app.info('登录成功');
  47. that.setData({ userInfo: app.globalData.userInfo });
  48. });
  49. },
  50. formSubmit: function (event) {
  51. var that = this;
  52. var pid = event.currentTarget.dataset.pid;
  53. if (!app.globalData.userInfo) {
  54. app.error('请登录后再评论');
  55. return;
  56. }
  57. if (event.detail.value.message == '') {
  58. app.error('内容不能为空');
  59. return;
  60. }
  61. app.request('/addons/cms/wxapp.comment/post', { aid: this.data.archivesInfo.id, pid: this.data.form.quotepid, username: event.detail.value.username, content: event.detail.value.content }, function (data) {
  62. app.success('发表成功!');
  63. that.setData({ form: { quotepid: 0, message: '', focus: false }, commentList: [], nodata: false, nomore: false });
  64. if (that.data.commentList.length < 10) {
  65. that.page = 1;
  66. } else {
  67. that.data.commentList = that.data.commentList.slice(0, 10);
  68. that.page = 2;
  69. }
  70. that.onReachBottom();
  71. }, function (data, ret) {
  72. app.error(ret.msg);
  73. });
  74. },
  75. vote: function (event) {
  76. var that = this;
  77. app.vote(event, function (data) {
  78. that.setData({ ['archivesInfo.likes']: data.likes, ['archivesInfo.dislikes']: data.dislikes, ['archivesInfo.likeratio']: data.likeratio });
  79. });
  80. },
  81. onReachBottom: function () {
  82. var that = this;
  83. this.loadComment(function (data) {
  84. if (data.commentList.length == 0) {
  85. //app.info("暂无更多数据");
  86. }
  87. });
  88. },
  89. loadComment: function (cb) {
  90. var that = this;
  91. if (that.data.nomore == true || that.data.loading == true) {
  92. return;
  93. }
  94. this.setData({ loading: true });
  95. app.request('/addons/cms/wxapp.comment', { aid: this.data.archivesInfo.id, page: this.page }, function (data, ret) {
  96. that.setData({
  97. loading: false,
  98. nodata: that.page == 1 && data.commentList.length == 0 ? true : false,
  99. nomore: that.page > 1 && data.commentList.length == 0 ? true : false,
  100. commentList: that.page > 1 ? that.data.commentList.concat(data.commentList) : data.commentList,
  101. });
  102. that.page++;
  103. typeof cb == 'function' && cb(data);
  104. }, function (data, ret) {
  105. that.setData({
  106. loading: false
  107. });
  108. app.error(ret.msg);
  109. });
  110. },
  111. share: function () {
  112. wx.showShareMenu({});
  113. },
  114. onShareAppMessage: function () {
  115. return {
  116. title: this.data.archivesInfo.title,
  117. desc: this.data.archivesInfo.intro,
  118. path: '/page/product/detail?id=' + this.data.archivesInfo.id
  119. }
  120. },
  121. })