comment-con.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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: '',
  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. delImages:function(e){
  86. var that = this;
  87. var dataimg = that.data.dataimg;
  88. var index = e.currentTarget.dataset.id;
  89. dataimg.splice(index,1);
  90. that.setData({
  91. dataimg: dataimg
  92. })
  93. },
  94. uploadpic:function(e){
  95. var that = this;
  96. wx.chooseImage({
  97. count: 1, //最多可以选择的图片总数
  98. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  99. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  100. success: function (res) {
  101. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  102. var tempFilePaths = res.tempFilePaths;
  103. //启动上传等待中...
  104. wx.showLoading({
  105. title: '图片上传中',
  106. })
  107. var len = tempFilePaths.length;
  108. for (var i = 0; i < len; i++) {
  109. wx.uploadFile({
  110. url: app.globalData.url + '/routine/auth_api/upload?uid=' + app.globalData.uid,
  111. filePath: tempFilePaths[i],
  112. name: 'pics',
  113. formData: {
  114. 'filename': 'pics'
  115. },
  116. header: {
  117. "Content-Type": "multipart/form-data"
  118. },
  119. success: function (res) {
  120. wx.hideLoading();
  121. if(res.statusCode == 403){
  122. wx.showToast({
  123. title: res.data,
  124. icon: 'none',
  125. duration: 1500,
  126. })
  127. } else {
  128. var data = JSON.parse(res.data);
  129. data.data.url = app.globalData.url + data.data.url;
  130. that.data.dataimg.push(data);
  131. that.setData({
  132. dataimg: that.data.dataimg
  133. });
  134. var len2 = that.data.dataimg.length;
  135. if (len2 >= 8) {
  136. that.setData({
  137. hidden: true
  138. });
  139. }
  140. }
  141. },
  142. fail: function (res) {
  143. wx.showToast({
  144. title: '上传图片失败',
  145. icon: 'none',
  146. duration: 2000
  147. })
  148. }
  149. });
  150. }
  151. }
  152. });
  153. },
  154. formSubmit:function(e){
  155. var header = {
  156. 'content-type': 'application/x-www-form-urlencoded'
  157. };
  158. var that = this;
  159. var unique = that.data.unique;
  160. var comment = e.detail.value.comment;
  161. var product_score = that.data.xing;
  162. var service_score = that.data.xing2;
  163. var pics = [];
  164. var dataimg = that.data.dataimg;
  165. for (var i = 0; i < dataimg.length;i++){
  166. pics.push(that.data.url+dataimg[i].data.url)
  167. };
  168. if (comment==""){
  169. wx.showToast({
  170. title: '请填写你对宝贝的心得!',
  171. icon: 'none',
  172. duration: 2000
  173. })
  174. return false;
  175. }
  176. wx.showLoading({ title: "正在发布评论……" });
  177. wx.request({
  178. url: app.globalData.url + '/routine/auth_api/user_comment_product?uid=' + app.globalData.uid+'&unique=' + unique,
  179. data: {comment: comment, product_score: product_score, service_score: service_score, pics: pics},
  180. method: 'post',
  181. header: header,
  182. success: function (res) {
  183. wx.hideLoading();
  184. if (res.data.code==200){
  185. wx.showToast({
  186. title: '评价成功',
  187. icon: 'success',
  188. duration: 1000
  189. })
  190. setTimeout(function(){
  191. wx.navigateTo({
  192. url: '/pages/orders-con/orders-con?order_id='+that.data.uni,
  193. })
  194. },1200)
  195. }else{
  196. wx.showToast({
  197. title: res.data.msg,
  198. icon: 'none',
  199. duration: 2000
  200. })
  201. }
  202. },
  203. fail: function (res) {
  204. console.log('submit fail');
  205. },
  206. complete: function (res) {
  207. console.log('submit complete');
  208. }
  209. });
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面隐藏
  218. */
  219. onHide: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面卸载
  223. */
  224. onUnload: function () {
  225. },
  226. /**
  227. * 页面相关事件处理函数--监听用户下拉动作
  228. */
  229. onPullDownRefresh: function () {
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. onReachBottom: function () {
  235. },
  236. /**
  237. * 用户点击右上角分享
  238. */
  239. onShareAppMessage: function () {
  240. }
  241. })