index.js 3.3 KB

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