comment-con.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // pages/comment-con/comment-con.js
  2. var app = getApp();
  3. var wxh = require('../../utils/wxh.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. xinghidden:true,
  10. xinghidden2:true,
  11. xinghidden3: true,
  12. url: app.globalData.urlImages,
  13. hidden:false,
  14. unique:'',
  15. uni:'',
  16. dataimg:[]
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (e) {
  22. app.setBarColor();
  23. var header = {
  24. 'content-type': 'application/x-www-form-urlencoded'
  25. };
  26. var that = this;
  27. console.log(e);
  28. if (e.unique) {
  29. var unique = e.unique;
  30. that.setData({
  31. unique: unique,
  32. });
  33. }
  34. if (e.uni){
  35. that.setData({
  36. uni: e.uni
  37. });
  38. }
  39. wx.showLoading({ title: "正在加载中……" });
  40. wx.request({
  41. url: app.globalData.url + '/routine/auth_api/get_order_product?uid=' + app.globalData.uid,
  42. data: { unique: unique},
  43. method: 'get',
  44. header: header,
  45. success: function (res) {
  46. wx.hideLoading();
  47. that.setData({
  48. ordercon: res.data.data
  49. });
  50. },
  51. fail: function (res) {
  52. console.log('submit fail');
  53. },
  54. complete: function (res) {
  55. console.log('submit complete');
  56. }
  57. });
  58. },
  59. /**
  60. * 生命周期函数--监听页面初次渲染完成
  61. */
  62. onReady: function () {
  63. },
  64. tapxing:function(e){
  65. var index = e.target.dataset.index;
  66. this.setData({
  67. xinghidden: false,
  68. xing: index
  69. })
  70. },
  71. tapxing2: function (e) {
  72. var index = e.target.dataset.index;
  73. this.setData({
  74. xinghidden2: false,
  75. xing2: index
  76. })
  77. },
  78. tapxing3: function (e) {
  79. var index = e.target.dataset.index;
  80. this.setData({
  81. xinghidden3: false,
  82. xing3: index
  83. })
  84. },
  85. uploadpic:function(e){
  86. var that = this;
  87. wx.chooseImage({
  88. count: 1, //最多可以选择的图片总数
  89. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  90. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  91. success: function (res) {
  92. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  93. var tempFilePaths = res.tempFilePaths;
  94. //启动上传等待中...
  95. wx.showLoading({
  96. title: '图片上传中',
  97. })
  98. console.log(tempFilePaths);
  99. var len = tempFilePaths.length;
  100. for (var i = 0; i < len; i++) {
  101. wx.uploadFile({
  102. url: app.globalData.url + '/routine/auth_api/upload?uid=' + app.globalData.uid,
  103. filePath: tempFilePaths[i],
  104. name: 'pics',
  105. formData: {
  106. 'filename': 'pics'
  107. },
  108. header: {
  109. "Content-Type": "multipart/form-data"
  110. },
  111. success: function (res) {
  112. wx.hideLoading();
  113. console.log(res);
  114. if(res.statusCode == 403){
  115. wx.showToast({
  116. title: res.data,
  117. icon: 'none',
  118. duration: 1500,
  119. })
  120. } else {
  121. var data = JSON.parse(res.data);
  122. that.data.dataimg.push(data);
  123. that.setData({
  124. dataimg: that.data.dataimg
  125. });
  126. var len2 = that.data.dataimg.length;
  127. if (len2 >= 8) {
  128. that.setData({
  129. hidden: true
  130. });
  131. }
  132. }
  133. },
  134. fail: function (res) {
  135. wx.showToast({
  136. title: '上传图片失败',
  137. icon: 'none',
  138. duration: 2000
  139. })
  140. }
  141. });
  142. }
  143. }
  144. });
  145. },
  146. formSubmit:function(e){
  147. var header = {
  148. 'content-type': 'application/x-www-form-urlencoded'
  149. };
  150. var that = this;
  151. var unique = that.data.unique;
  152. var comment = e.detail.value.comment;
  153. var product_score = that.data.xing;
  154. var service_score = that.data.xing2;
  155. var pics = [];
  156. var dataimg = that.data.dataimg;
  157. for (var i = 0; i < dataimg.length;i++){
  158. pics.push(that.data.url+dataimg[i].data.url)
  159. };
  160. if (comment==""){
  161. wx.showToast({
  162. title: '请填写你对宝贝的心得!',
  163. icon: 'none',
  164. duration: 2000
  165. })
  166. return false;
  167. }
  168. wx.showLoading({ title: "正在发布评论……" });
  169. wx.request({
  170. url: app.globalData.url + '/routine/auth_api/user_comment_product?uid=' + app.globalData.uid+'&unique=' + unique,
  171. data: {comment: comment, product_score: product_score, service_score: service_score, pics: pics},
  172. method: 'post',
  173. header: header,
  174. success: function (res) {
  175. wx.hideLoading();
  176. if (res.data.code==200){
  177. wx.showToast({
  178. title: '评价成功',
  179. icon: 'success',
  180. duration: 1000
  181. })
  182. setTimeout(function(){
  183. wx.navigateTo({
  184. url: '/pages/orders-con/orders-con?order_id='+that.data.uni,
  185. })
  186. },1200)
  187. }else{
  188. wx.showToast({
  189. title: res.data.msg,
  190. icon: 'none',
  191. duration: 2000
  192. })
  193. }
  194. },
  195. fail: function (res) {
  196. console.log('submit fail');
  197. },
  198. complete: function (res) {
  199. console.log('submit complete');
  200. }
  201. });
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function () {
  207. },
  208. /**
  209. * 生命周期函数--监听页面隐藏
  210. */
  211. onHide: function () {
  212. },
  213. /**
  214. * 生命周期函数--监听页面卸载
  215. */
  216. onUnload: function () {
  217. },
  218. /**
  219. * 页面相关事件处理函数--监听用户下拉动作
  220. */
  221. onPullDownRefresh: function () {
  222. },
  223. /**
  224. * 页面上拉触底事件的处理函数
  225. */
  226. onReachBottom: function () {
  227. },
  228. /**
  229. * 用户点击右上角分享
  230. */
  231. onShareAppMessage: function () {
  232. }
  233. })