index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { orderProduct, orderComment} from '../../api/order.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. productInfo:{},
  23. cart_num:0,
  24. },
  25. /**
  26. * 授权回调
  27. */
  28. onLoadFun:function(){
  29. this.getOrderProduct();
  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. /**
  39. * 获取某个产品详情
  40. *
  41. */
  42. getOrderProduct:function(){
  43. var that=this;
  44. orderProduct(that.data.unique).then(res=>{
  45. that.setData({ productInfo: res.data.productInfo, cart_num: res.data.cart_num });
  46. });
  47. },
  48. stars: function (e) {
  49. var index = e.target.dataset.index;
  50. var indexw = e.target.dataset.indexw;
  51. this.data.scoreList[indexw].stars = index
  52. this.setData({
  53. scoreList: this.data.scoreList
  54. })
  55. },
  56. /**
  57. * 删除图片
  58. *
  59. */
  60. DelPic: function (e) {
  61. var index = e.target.dataset.index, that = this, pic = this.data.pics[index];
  62. that.data.pics.splice(index, 1);
  63. that.setData({ pics: that.data.pics });
  64. },
  65. /**
  66. * 上传文件
  67. *
  68. */
  69. uploadpic: function () {
  70. var that = this;
  71. util.uploadImageOne('upload/image', function (res) {
  72. that.data.pics.push(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. value.unique = that.data.unique;
  87. wx.showLoading({ title: "正在发布评论……" });
  88. orderComment(value).then(res=>{
  89. wx.hideLoading();
  90. return app.Tips({ title: '感谢您的评价!', icon: 'success' }, '/pages/order_details/index?order_id=' + that.data.orderId);
  91. }).catch(err=>{
  92. wx.hideLoading();
  93. return app.Tips({ title: err });
  94. });
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function () {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function () {
  125. }
  126. })