index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // pages/evaluate-con/index.js
  2. const app=getApp();
  3. const util = require('../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. parameter: {
  10. 'navbar': '1',
  11. 'return': '1',
  12. 'title': '商品评价',
  13. 'color': false,
  14. },
  15. scoreList:[
  16. { 'name': '商品质量','stars':0},
  17. { 'name': '服务态度','stars':0},
  18. ],
  19. pics:[],
  20. orderId:'',
  21. unique:'',
  22. is_local:1
  23. },
  24. /**
  25. * 授权回调
  26. */
  27. onLoadFun:function(){
  28. this.getOrderProduct();
  29. this.imageStorage();
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. if (!options.unique || !options.uni) return app.Tips({title:'缺少参数'},{tab:3,url:1});
  36. this.setData({ unique: options.unique, orderId: options.uni});
  37. },
  38. imageStorage: function () {
  39. var that = this;
  40. app.baseGet(app.U({ c: "user_api", a: 'picture_storage_location'}), function (res) {
  41. that.setData({ is_local: res.data });
  42. });
  43. },
  44. /**
  45. * 获取某个产品详情
  46. *
  47. */
  48. getOrderProduct:function(){
  49. var that=this;
  50. app.baseGet(app.U({ c: "store_api", a: 'get_order_product', q: { unique: that.data.unique}}),function(res){
  51. that.setData({ orderCon:res.data});
  52. });
  53. },
  54. stars: function (e) {
  55. var index = e.target.dataset.index;
  56. var indexw = e.target.dataset.indexw;
  57. this.data.scoreList[indexw].stars = index
  58. this.setData({
  59. scoreList: this.data.scoreList
  60. })
  61. },
  62. /**
  63. * 删除图片
  64. *
  65. */
  66. DelPic: function (e) {
  67. var index = e.target.dataset.index, that = this, pic = this.data.pics[index];
  68. app.basePost(app.U({ c: 'public_api', a: 'delete_image' }), { pic: pic.replace(app.globalData.url, '') }, function (res) {
  69. that.data.pics.splice(index, 1);
  70. that.setData({ pics: that.data.pics });
  71. });
  72. },
  73. /**
  74. * 上传文件
  75. *
  76. */
  77. uploadpic: function () {
  78. var that = this;
  79. util.uploadImageOne(app.U({ c: 'public_api', a: 'upload' }), function (res) {
  80. that.data.pics.push(res.data.url);
  81. that.setData({ pics: that.data.pics });
  82. });
  83. },
  84. /**
  85. * 立即评价
  86. */
  87. formSubmit:function(e){
  88. var formId = e.detail.formId, value = e.detail.value, that = this,
  89. product_score = that.data.scoreList[0].stars, service_score = that.data.scoreList[1].stars;
  90. if (!value.comment) return app.Tips({ title:'请填写你对宝贝的心得!'});
  91. value.product_score = product_score;
  92. value.service_score = service_score;
  93. value.pics=that.data.pics;
  94. wx.showLoading({ title: "正在发布评论……" });
  95. app.basePost(app.U({ c: 'user_api', a: 'user_comment_product', q: { unique: that.data.unique}}),value,function(res){
  96. wx.hideLoading();
  97. return app.Tips({ title: '感谢您的评价!', icon: 'success' },'/pages/order_details/index?order_id='+that.data.orderId);
  98. },function(res){
  99. wx.hideLoading();
  100. return app.Tips({title:res.msg});
  101. });
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面显示
  110. */
  111. onShow: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. }
  138. })