index.js 3.4 KB

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