index.js 3.9 KB

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