index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // pages/zl_detail/create_evaluation/index.js
  2. const {
  3. request,
  4. serverName
  5. } = require('../../../utils/services');
  6. // const WxParse = require('../../../common/component/wxParse/wxParse.js');
  7. const wxStar = require('../../../common/component/wxStar/wxStar/wxStar.js');
  8. const {
  9. Toast
  10. } = require('../../../utils/util.js');
  11. const {
  12. defaultImg
  13. } = require('../../../utils/images');
  14. const app = getApp();
  15. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. full_star_img: "../../../imgs/icon/full.png",
  21. currentStar: 0,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function(options) {
  27. wxStar.wxStar(this, 0, true);
  28. let currentStar = this.wxStarCont();
  29. this.setData({
  30. defaultImg,
  31. exhibitionId: options.id,
  32. serverName,
  33. currentStar
  34. })
  35. },
  36. starChangeCb: function() {
  37. let currentStar = this.wxStarCont();
  38. this.setData({
  39. currentStar
  40. })
  41. },
  42. clearComment: function() {
  43. this.setData({
  44. content: ""
  45. });
  46. },
  47. getContent: function(e) {
  48. this.setData({
  49. content: e.detail.value || ""
  50. });
  51. console.log('change', e.detail.value);
  52. },
  53. submit: function() {
  54. let {
  55. content,
  56. exhibitionId
  57. } = this.data;
  58. let currentStar = this.wxStarCont() / 2;
  59. let loginSessionKey = wx.getStorageSync('token') || "";
  60. if (content && currentStar) {
  61. request["writtenComments"]({
  62. comment: content,
  63. exhibitionId,
  64. score: currentStar,
  65. loginSessionKey
  66. }, "post", res => {
  67. if (res.data.code > -1) {
  68. Toast.showToast('tip', "评论成功", success => {
  69. wx.navigateBack({
  70. url: `../../../pages/zl_detail/index?id=${exhibitionId}`,
  71. success: function (res) { },
  72. fail: function (res) { },
  73. complete: function (res) { },
  74. })
  75. })
  76. // wx.navigateBack({
  77. // delta: 1,
  78. // })
  79. }
  80. }, err => {
  81. // wx.showToast({
  82. // title: '评论失败',
  83. // icon: 'none',
  84. // duration: 2000
  85. // })
  86. }, complete => {
  87. })
  88. } else if (currentStar){
  89. Toast.showToast('tip', "写几句短评吧", success => {
  90. })
  91. }else{
  92. Toast.showToast('tip', "给看展打个分吧", success => {
  93. })
  94. }
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function() {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function() {
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function() {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function() {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function() {
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function() {
  130. }
  131. })