evaluate.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. })
  58. }
  59. }
  60. })
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function() {
  66. },
  67. addImg: function() {
  68. var that = this,
  69. imgGroup = this.data.imgGroup;
  70. wx.chooseImage({
  71. count: this.data.imgMax - imgGroup.length,
  72. success: function(res) {
  73. var tempFilePaths = res.tempFilePaths;
  74. var new_thumb_img = that.data.thumb_img;
  75. for (var i = 0; i < tempFilePaths.length; i++) {
  76. wx.showLoading({
  77. title: '上传中'
  78. })
  79. if (new_thumb_img.length >= 4) {
  80. that.setData({
  81. thumb_img: new_thumb_img
  82. });
  83. return false;
  84. } else {
  85. wx.uploadFile({
  86. url: app.util.url('entry/wxapp/index', {
  87. 'm': 'lionfish_comshop',
  88. 'controller': 'goods.doPageUpload'
  89. }),
  90. filePath: tempFilePaths[i],
  91. name: 'upfile',
  92. formData: {
  93. 'name': tempFilePaths[i]
  94. },
  95. header: {
  96. 'content-type': 'multipart/form-data'
  97. },
  98. success: function(res) {
  99. wx.hideLoading();
  100. var data = JSON.parse(res.data);
  101. var image_thumb = data.image_thumb;
  102. var image_o_full = data.image_o_full;
  103. var orign_image = data.image_o;
  104. var new_img = that.data.image;
  105. var new_thumb_img = that.data.thumb_img;
  106. new_img.push(orign_image);
  107. new_thumb_img.push(image_thumb);
  108. imgGroup.push(image_thumb);
  109. that.setData({
  110. thumb_img: new_thumb_img,
  111. image: new_img,
  112. imgGroup: imgGroup
  113. })
  114. }
  115. })
  116. }
  117. }
  118. }
  119. });
  120. },
  121. textinput: function(event) {
  122. var content = event.detail.value;
  123. //pinjia_text
  124. this.setData({
  125. pinjia_text: content
  126. })
  127. },
  128. /**
  129. * 删除图片
  130. */
  131. choseImg: function(e) {
  132. var idx = e.currentTarget.dataset.idx;
  133. var imgGroup = this.data.imgGroup;
  134. var new_img = this.data.image;
  135. new_img.splice(idx, 1);
  136. imgGroup.splice(idx, 1);
  137. this.setData({
  138. imgGroup: imgGroup,
  139. image: new_img
  140. })
  141. },
  142. sub_comment: function() {
  143. var order_id = this.data.order_id;
  144. var goods_id = this.data.goods_id;
  145. var pinjia_text = this.data.pinjia_text;
  146. var image = this.data.image;
  147. var that = this;
  148. if (pinjia_text == '') {
  149. wx.showToast({
  150. title: '请填写评价内容',
  151. icon: 'success',
  152. duration: 1000
  153. })
  154. return false;
  155. }
  156. wx.showLoading({
  157. title: '评论中',
  158. })
  159. var token = wx.getStorageSync('token');
  160. console.log(image);
  161. app.util.request({
  162. 'url': 'entry/wxapp/user',
  163. 'data': {
  164. controller: 'user.sub_comment',
  165. 'token': token,
  166. order_id: order_id,
  167. goods_id: goods_id,
  168. comment_content: pinjia_text,
  169. imgs: image
  170. },
  171. method: 'POST',
  172. dataType: 'json',
  173. success: function(msg) {
  174. wx.hideLoading();
  175. if (msg.data.code == 3) {
  176. wx.showToast({
  177. title: '未登录',
  178. icon: 'loading',
  179. duration: 1000
  180. })
  181. } else {
  182. wx.showToast({
  183. title: '评价成功',
  184. icon: 'success',
  185. duration: 1000,
  186. success: function(res) {
  187. //是否跳到积分
  188. wx.redirectTo({
  189. url: "/lionfish_comshop/pages/order/order?id=" + order_id
  190. })
  191. }
  192. })
  193. }
  194. }
  195. })
  196. },
  197. /**
  198. * 预览大图
  199. */
  200. bigImg: function(e) {
  201. var t = e.currentTarget.dataset.src,
  202. list = e.currentTarget.dataset.list;
  203. wx.previewImage({
  204. current: t,
  205. urls: list
  206. });
  207. },
  208. /**
  209. * 生命周期函数--监听页面显示
  210. */
  211. onShow: function() {
  212. },
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide: function() {
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload: function() {
  222. }
  223. })