evaluate.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // lionfish_comshop/pages/order/evaluate.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. order_id: 0,
  10. goods_id: 0,
  11. miaoshu_no: 0,
  12. price_no: 0,
  13. zhiliang_no: 0,
  14. is_jifen: 0,
  15. pinjia_text: '',
  16. thumb_img: [],
  17. image: [],
  18. placeholder: "亲,您对这个商品满意吗?您的评价会帮助我们选择更好的商品哦~",
  19. evaluate: "",
  20. imgGroup: [],
  21. imgMax: 4,
  22. isIpx: false,
  23. focus: false,
  24. progressList: []
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function(options) {
  30. //id=' + id + '&goods_id' + goods_id
  31. var that = this;
  32. var token = wx.getStorageSync('token');
  33. var order_id = options.id;
  34. var goods_id = options.goods_id;
  35. this.setData({
  36. order_id: order_id,
  37. goods_id: goods_id
  38. })
  39. app.util.request({
  40. 'url': 'entry/wxapp/user',
  41. 'data': {
  42. controller: 'user.order_comment',
  43. 'token': token,
  44. order_id: order_id,
  45. goods_id: goods_id
  46. },
  47. dataType: 'json',
  48. success: function(res) {
  49. if (res.data.code == 3) {
  50. //un login
  51. } else if (res.data.code == 0) {
  52. //code goods_image
  53. that.setData({
  54. goods_id: res.data.goods_id,
  55. order_goods: res.data.order_goods,
  56. goods_image: res.data.goods_image,
  57. open_comment_gift: res.data.open_comment_gift,
  58. comment_gift_publish: res.data.comment_gift_publish
  59. })
  60. }
  61. }
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady: function() {
  68. },
  69. addImg: function() {
  70. var that = this,
  71. imgGroup = this.data.imgGroup;
  72. wx.chooseImage({
  73. count: this.data.imgMax - imgGroup.length,
  74. success: function(res) {
  75. var tempFilePaths = res.tempFilePaths;
  76. var new_thumb_img = that.data.thumb_img;
  77. for (var i = 0; i < tempFilePaths.length; i++) {
  78. wx.showLoading({
  79. title: '上传中'
  80. })
  81. if (new_thumb_img.length >= 4) {
  82. that.setData({
  83. thumb_img: new_thumb_img
  84. });
  85. return false;
  86. } else {
  87. wx.uploadFile({
  88. url: app.util.url('entry/wxapp/index', {
  89. 'm': 'lionfish_comshop',
  90. 'controller': 'goods.doPageUpload'
  91. }),
  92. filePath: tempFilePaths[i],
  93. name: 'upfile',
  94. formData: {
  95. 'name': tempFilePaths[i]
  96. },
  97. header: {
  98. 'content-type': 'multipart/form-data'
  99. },
  100. success: function(res) {
  101. wx.hideLoading();
  102. var data = JSON.parse(res.data);
  103. var image_thumb = data.image_thumb;
  104. var image_o_full = data.image_o_full;
  105. var orign_image = data.image_o;
  106. var new_img = that.data.image;
  107. var new_thumb_img = that.data.thumb_img;
  108. new_img.push(orign_image);
  109. new_thumb_img.push(image_thumb);
  110. imgGroup.push(image_thumb);
  111. that.setData({
  112. thumb_img: new_thumb_img,
  113. image: new_img,
  114. imgGroup: imgGroup
  115. })
  116. }
  117. })
  118. }
  119. }
  120. }
  121. });
  122. },
  123. textinput: function(event) {
  124. var content = event.detail.value;
  125. //pinjia_text
  126. this.setData({
  127. pinjia_text: content
  128. })
  129. },
  130. /**
  131. * 删除图片
  132. */
  133. choseImg: function(e) {
  134. var idx = e.currentTarget.dataset.idx;
  135. var imgGroup = this.data.imgGroup;
  136. var new_img = this.data.image;
  137. new_img.splice(idx, 1);
  138. imgGroup.splice(idx, 1);
  139. this.setData({
  140. imgGroup: imgGroup,
  141. image: new_img
  142. })
  143. },
  144. sub_comment: function() {
  145. var order_id = this.data.order_id;
  146. var goods_id = this.data.goods_id;
  147. var pinjia_text = this.data.pinjia_text;
  148. var image = this.data.image;
  149. var that = this;
  150. if (pinjia_text == '') {
  151. wx.showToast({
  152. title: '请填写评价内容',
  153. icon: 'success',
  154. duration: 1000
  155. })
  156. return false;
  157. }
  158. wx.showLoading({
  159. title: '评论中',
  160. })
  161. var token = wx.getStorageSync('token');
  162. console.log(image);
  163. app.util.request({
  164. 'url': 'entry/wxapp/user',
  165. 'data': {
  166. controller: 'user.sub_comment',
  167. 'token': token,
  168. order_id: order_id,
  169. goods_id: goods_id,
  170. comment_content: pinjia_text,
  171. imgs: image
  172. },
  173. method: 'POST',
  174. dataType: 'json',
  175. success: function(msg) {
  176. wx.hideLoading();
  177. if (msg.data.code == 3) {
  178. wx.showToast({
  179. title: '未登录',
  180. icon: 'loading',
  181. duration: 1000
  182. })
  183. } else {
  184. wx.showToast({
  185. title: '评价成功',
  186. icon: 'success',
  187. duration: 1000,
  188. success: function(res) {
  189. //是否跳到积分
  190. wx.redirectTo({
  191. url: "/lionfish_comshop/pages/order/order?id=" + order_id
  192. })
  193. }
  194. })
  195. }
  196. }
  197. })
  198. },
  199. /**
  200. * 预览大图
  201. */
  202. bigImg: function(e) {
  203. var t = e.currentTarget.dataset.src,
  204. list = e.currentTarget.dataset.list;
  205. wx.previewImage({
  206. current: t,
  207. urls: list
  208. });
  209. },
  210. /**
  211. * 生命周期函数--监听页面显示
  212. */
  213. onShow: function() {
  214. },
  215. /**
  216. * 生命周期函数--监听页面隐藏
  217. */
  218. onHide: function() {
  219. },
  220. /**
  221. * 生命周期函数--监听页面卸载
  222. */
  223. onUnload: function() {
  224. }
  225. })