comment.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // pages/order/comment.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. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. var that = this;
  24. var token = wx.getStorageSync('token');
  25. var order_id = options.id;
  26. var gis_jifen = options.is_jifen;
  27. if (gis_jifen != undefined) {
  28. this.setData({
  29. is_jifen: 1
  30. })
  31. }
  32. this.setData({
  33. order_id: order_id
  34. })
  35. app.util.request({
  36. 'url': 'entry/wxapp/user',
  37. 'data': {
  38. controller: 'user.order_comment',
  39. 'token': token,
  40. order_id: order_id
  41. },
  42. dataType: 'json',
  43. success: function (res) {
  44. if (res.data.code == 3) {
  45. //un login
  46. } else if (res.data.code == 0) {
  47. //
  48. //code goods_image
  49. that.setData({
  50. goods_id: res.data.goods_id,
  51. goods_image: res.data.goods_image
  52. })
  53. }
  54. }
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. textinput: function (event) {
  63. //event.detail = { value, cursor },
  64. var content = event.detail.value;
  65. //pinjia_text
  66. this.setData({
  67. pinjia_text: content
  68. })
  69. },
  70. sub_comment: function () {
  71. var order_id = this.data.order_id;
  72. var goods_id = this.data.goods_id;
  73. var miaoshu_no = this.data.miaoshu_no;
  74. var price_no = this.data.price_no;
  75. var zhiliang_no = this.data.zhiliang_no;
  76. var pinjia_text = this.data.pinjia_text;
  77. var image = this.data.image;
  78. var that = this;
  79. if (pinjia_text == '') {
  80. wx.showToast({
  81. title: '请填写评价内容',
  82. icon: 'success',
  83. duration: 1000
  84. })
  85. return false;
  86. }
  87. wx.showLoading({
  88. title: '评论中',
  89. })
  90. var token = wx.getStorageSync('token');
  91. app.util.request({
  92. 'url': 'entry/wxapp/user',
  93. 'data': {
  94. controller: 'user.sub_comment',
  95. 'token': token,
  96. order_id: order_id,
  97. goods_id: goods_id,
  98. cur_rel: miaoshu_no,
  99. cur2_rel: price_no,
  100. cur3_rel: zhiliang_no,
  101. comment_content: pinjia_text,
  102. imgs: image
  103. },
  104. method: 'POST',
  105. dataType: 'json',
  106. success: function (msg) {
  107. wx.hideLoading();
  108. if (msg.data.code == 3) {
  109. wx.showToast({
  110. title: '未登录',
  111. icon: 'loading',
  112. duration: 1000
  113. })
  114. } else {
  115. wx.showToast({
  116. title: '评价成功',
  117. icon: 'success',
  118. duration: 1000,
  119. success: function (res) {
  120. //是否跳到积分
  121. if (that.data.is_jifen == 1) {
  122. wx.redirectTo({
  123. url: "/Snailfish_shop/pages/dan/me_score_order"
  124. })
  125. } else {
  126. wx.redirectTo({
  127. url: "/Snailfish_shop/pages/order/index?order_status=11"
  128. })
  129. }
  130. }
  131. })
  132. }
  133. }
  134. })
  135. },
  136. choseStar: function (event) {
  137. let stype = event.currentTarget.dataset.stype;
  138. let sval = event.currentTarget.dataset.sval;
  139. if (stype == 'miaoshu_no') {
  140. this.setData({
  141. miaoshu_no: sval
  142. })
  143. } else if (stype == 'price_no') {
  144. this.setData({
  145. price_no: sval
  146. })
  147. } else if (stype == 'zhiliang_no') {
  148. this.setData({
  149. zhiliang_no: sval
  150. })
  151. }
  152. },
  153. choseImg: function () {
  154. var self = this;
  155. wx.chooseImage({
  156. count: 1, // 默认9
  157. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  158. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  159. success: function (res) {
  160. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  161. var tempFilePaths = res.tempFilePaths;
  162. wx.showLoading({
  163. title: '上传中',
  164. })
  165. wx.uploadFile({
  166. url: app.util.url('entry/wxapp/index', { 'm': 'Snailfish_shop', 'controller': 'goods.doPageUpload' }), //仅为示例,非真实的接口地址
  167. filePath: tempFilePaths[0],
  168. name: 'upfile',
  169. formData: {
  170. 'name': tempFilePaths[0]
  171. },
  172. header: {
  173. 'content-type': 'multipart/form-data'
  174. },
  175. success: function (res) {
  176. wx.hideLoading();
  177. var data = JSON.parse(res.data);
  178. var image_thumb = data.image_thumb;
  179. var orign_image = data.image_o;
  180. var new_img = self.data.image;
  181. var new_thumb_img = self.data.thumb_img;
  182. new_img.push(orign_image);
  183. new_thumb_img.push(image_thumb);
  184. self.setData({
  185. thumb_img: new_thumb_img,
  186. image: new_img
  187. })
  188. //https://mall.shiziyu888.com/Uploads/image/cache/goods/2017-11-28/5a1d30ca7c627-300x300.png
  189. // https://mall.shiziyu888.com/Uploads/image/goods/2017-11-28/5a1d30ca7c627.png
  190. //do something
  191. }
  192. })
  193. }
  194. })
  195. },
  196. /**
  197. * 生命周期函数--监听页面显示
  198. */
  199. onShow: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面隐藏
  203. */
  204. onHide: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面卸载
  208. */
  209. onUnload: function () {
  210. },
  211. /**
  212. * 页面相关事件处理函数--监听用户下拉动作
  213. */
  214. onPullDownRefresh: function () {
  215. },
  216. /**
  217. * 页面上拉触底事件的处理函数
  218. */
  219. onReachBottom: function () {
  220. },
  221. /**
  222. * 用户点击右上角分享
  223. */
  224. onShareAppMessage: function () {
  225. }
  226. })