prodComm.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. var http = require('../../utils/http.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. orderItemInfo: {
  8. images: [],
  9. content: "",
  10. score: 5,
  11. isAnonymous: 1,
  12. evaluate: 0,
  13. }, //订单列表页参数
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. // 获取上页(订单列表)数据
  20. // var orderItemInfo = wx.getStorageSync("orderItemInfo");
  21. // // console.log(orderItemInfo);
  22. // for (var i = 0; i < orderItemInfo.length; i++){
  23. // orderItemInfo[i].images = [];
  24. // orderItemInfo[i].content = "";
  25. // orderItemInfo[i].score = 5;
  26. // orderItemInfo[i].isAnonymous = 1;
  27. // orderItemInfo[i].evaluate = 0;
  28. // }
  29. // this.setData({
  30. // orderItemInfo: orderItemInfo
  31. // })
  32. // console.log(orderItemInfo)
  33. },
  34. /**
  35. * 发表评论
  36. */
  37. submitComm: function (e) {
  38. var orderItemInfo = this.data.orderItemInfo;
  39. if(orderItemInfo.content.trim()==""){
  40. return wx.showToast({
  41. title: '评价不能为空',
  42. icon:"none"
  43. })
  44. }
  45. wx.showLoading();
  46. var pics = '';
  47. orderItemInfo.images.forEach(function(item){
  48. pics += item.path + ',';
  49. });
  50. if(pics!=''){
  51. pics = pics.substring(0,pics.length-1)
  52. }
  53. // 发布评论
  54. var params = {
  55. url: "/p/prodComm",
  56. method: "POST",
  57. data: {
  58. content: orderItemInfo.content,
  59. score: orderItemInfo.score,
  60. evaluate: orderItemInfo.evaluate,
  61. isAnonymous: orderItemInfo.isAnonymous,
  62. orderItemId: orderItemInfo.orderItemId,
  63. prodId: orderItemInfo.prodId,
  64. pics: pics
  65. },
  66. callBack: (res) => {
  67. wx.hideLoading();
  68. wx.navigateTo({
  69. url: '/pages/commResult/commResult',
  70. })
  71. }
  72. };
  73. http.request(params);
  74. },
  75. /**
  76. * 上传图片
  77. */
  78. getUploadImg: function(e) {
  79. var ths = this;
  80. wx.chooseImage({
  81. count: 1, // 默认9
  82. sizeType: ['compressed'],
  83. sourceType: ['album', 'camera'],
  84. success: function (res) {
  85. var tempFilePaths = res.tempFilePaths;
  86. wx.showLoading({
  87. mask: true
  88. })
  89. var params = {
  90. url: "/p/file/upload",
  91. filePath: tempFilePaths[0],
  92. name: 'file',
  93. callBack: function (res2) {
  94. wx.hideLoading();
  95. var img = {};
  96. img.path = JSON.parse(res2).filePath;
  97. img.url = JSON.parse(res2).resourcesUrl + JSON.parse(res2).filePath;
  98. var orderItemInfo = ths.data.orderItemInfo;
  99. orderItemInfo.images.push(img);
  100. ths.setData({
  101. orderItemInfo: orderItemInfo
  102. })
  103. }
  104. };
  105. http.upload(params);
  106. }
  107. })
  108. },
  109. /**
  110. * 删除图片
  111. */
  112. removeImage(e) {
  113. const idx = e.target.dataset.idx
  114. var orderItemInfo = this.data.orderItemInfo;
  115. orderItemInfo.images.splice(idx, 1)
  116. this.setData({
  117. orderItemInfo: orderItemInfo
  118. });
  119. },
  120. onContentInput:function(e){
  121. const index = e.target.dataset.index
  122. var orderItemInfo = this.data.orderItemInfo;
  123. orderItemInfo.content = e.detail.value;
  124. this.setData({
  125. orderItemInfo: orderItemInfo
  126. });
  127. },
  128. /**
  129. * 匿名评价
  130. * 每一项的选择事件
  131. */
  132. onSelectedItem: function (e) {
  133. var orderItemInfo = this.data.orderItemInfo;// 获取评论项
  134. var isAnonymous = orderItemInfo.isAnonymous; // 获取当前评价的选中状态
  135. if (isAnonymous==1){
  136. isAnonymous = 0;
  137. }else{
  138. isAnonymous = 1;
  139. }
  140. orderItemInfo.isAnonymous = isAnonymous; // 改变状态
  141. this.setData({
  142. orderItemInfo: orderItemInfo
  143. });
  144. },
  145. onStarChange:function(e){
  146. var index = e.detail.idx;
  147. var val = e.detail.val;
  148. console.log(e);
  149. var evaluate = 0;
  150. var orderItemInfo = this.data.orderItemInfo;
  151. if(val<3){
  152. evaluate = 2;
  153. }else if(val==3){
  154. evaluate = 1;
  155. }
  156. orderItemInfo.score = val;
  157. orderItemInfo.evaluate = evaluate;
  158. this.setData({
  159. orderItemInfo: orderItemInfo
  160. });
  161. },
  162. /**
  163. * 评价图片预览
  164. */
  165. comPicPreView(e){
  166. var idx = e.currentTarget.dataset.idx
  167. var urls = []
  168. this.data.orderItemInfo.images.forEach(el => {
  169. urls.push(el.url)
  170. })
  171. wx.previewImage({
  172. current: urls[idx],
  173. urls: urls
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady: function () {
  180. },
  181. /**
  182. * 生命周期函数--监听页面显示
  183. */
  184. onShow: function () {
  185. },
  186. /**
  187. * 生命周期函数--监听页面隐藏
  188. */
  189. onHide: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面卸载
  193. */
  194. onUnload: function () {
  195. },
  196. /**
  197. * 页面相关事件处理函数--监听用户下拉动作
  198. */
  199. onPullDownRefresh: function () {
  200. },
  201. /**
  202. * 页面上拉触底事件的处理函数
  203. */
  204. onReachBottom: function () {
  205. },
  206. /**
  207. * 用户点击右上角分享
  208. */
  209. onShareAppMessage: function () {
  210. }
  211. })