prodComm.js 4.7 KB

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