index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // 100 待付款 200 付款成功代发货, 300 已发货待收货 400 已收货待评价,500 申请退款审核中
  2. // 600 审核通过准备退款 700 退款成功 800 评价完成订单完成
  3. const Parse = getApp().Parse
  4. const company = getApp().globalData.company
  5. Page({
  6. data: {
  7. value: 5,
  8. fileList: [],
  9. checked: true,
  10. task: null,
  11. images: null
  12. },
  13. async getOrder(id) {
  14. console.log(id);
  15. let shopOrder = new Parse.Query("Order")
  16. // shopOrder.include("goods")
  17. let res = await shopOrder.get(id)
  18. if (res && res.id) {
  19. let order = res.toJSON()
  20. this.setData({
  21. order: order
  22. })
  23. if (order.score) {
  24. wx.showToast({
  25. title: '该订单已评价过了',
  26. icon: 'none',
  27. image: '',
  28. duration: 1500,
  29. mask: false,
  30. });
  31. setTimeout(() => {
  32. wx.navigateBack({
  33. delta: 1
  34. });
  35. }, 1500);
  36. return
  37. }
  38. }
  39. },
  40. onChange(e) {
  41. console.log(e);
  42. this.setData({
  43. value: e.detail
  44. })
  45. },
  46. onOpen(e) {
  47. console.log(e.detail);
  48. this.setData({
  49. checked: e.detail,
  50. });
  51. },
  52. //添加图片
  53. changeFile(e) {
  54. console.log(e);
  55. let fileList = e.detail
  56. console.log(fileList);
  57. let images = []
  58. fileList.forEach(file => {
  59. images.push(file.url)
  60. })
  61. this.setData({
  62. fileList: fileList,
  63. images: images
  64. })
  65. console.log(this.data.images);
  66. },
  67. async getUptoken() {
  68. let res = await Parse.Cloud.run('qiniu_uptoken', {
  69. company: company
  70. })
  71. console.log(Object.keys(res));
  72. console.log(res);
  73. this.setData({
  74. uptokenURL: res.uptoken,
  75. domain: res.domain,
  76. uploadURL: res.zoneUrl
  77. })
  78. },
  79. async submit() {
  80. let {
  81. id,
  82. value,
  83. images,
  84. checked,
  85. content
  86. } = this.data
  87. console.log(id,
  88. value,
  89. images,
  90. checked,
  91. content);
  92. try {
  93. let shopOrder = new Parse.Query("Order")
  94. // shopOrder.include("goods")
  95. let res = await shopOrder.get(id)
  96. if (res && res.id) {
  97. res.set("open", checked)
  98. res.set("images", images)
  99. res.set("score", +value)
  100. res.set("content", content)
  101. res.set("status", '800')
  102. await res.save()
  103. await this.createdLog()
  104. wx.showToast({
  105. title: '评价成功',
  106. icon: 'success',
  107. image: '',
  108. duration: 1500,
  109. mask: false,
  110. });
  111. let pages = getCurrentPages();
  112. let prevPage = pages[pages.length - 2]
  113. let e = {
  114. detail: { index: 4, name: 4, title: "待评价" }
  115. }
  116. prevPage.onChange(e)
  117. setTimeout(() => {
  118. wx.navigateBack({
  119. delta: 1
  120. });
  121. }, 1500);
  122. }
  123. } catch (err) {
  124. wx.showToast({
  125. title: '系统异常,请稍后再试',
  126. icon: 'success',
  127. image: '',
  128. duration: 1500,
  129. mask: false,
  130. });
  131. setTimeout(() => {
  132. wx.navigateBack({
  133. delta: 1
  134. });
  135. }, 1500);
  136. console.log(err);
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面加载
  141. */
  142. onLoad: function(options) {
  143. let {
  144. id
  145. } = options
  146. console.log(id);
  147. this.setData({
  148. id
  149. })
  150. this.getOrder(id)
  151. this.getUptoken()
  152. this.getTask()
  153. },
  154. async getTask() {
  155. let Task = new Parse.Query('Task')
  156. Task.equalTo('company', company)
  157. Task.equalTo('isOpen', 'true')
  158. Task.equalTo('taskType', 'product-evaluation')
  159. let task = await Task.first()
  160. if (task && task.id) {
  161. this.setData({
  162. task: task
  163. })
  164. }
  165. },
  166. async createdLog() {
  167. let userid = Parse.User.current().id
  168. if (!this.data.task) {
  169. return
  170. }
  171. let TaskLog = Parse.Object.extend('TaskLog')
  172. let tasklog = new TaskLog()
  173. tasklog.set('user', {
  174. __type: "Pointer",
  175. className: '_User',
  176. objectId: userid
  177. })
  178. tasklog.set('task', {
  179. __type: "Pointer",
  180. className: 'Task',
  181. objectId: this.data.task.id
  182. })
  183. tasklog.set('company', {
  184. __type: "Pointer",
  185. className: 'Company',
  186. objectId: company
  187. })
  188. tasklog.set('isReceive', false)
  189. tasklog.set('credit', this.data.task.credit)
  190. await tasklog.save()
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady: function() {
  196. },
  197. /**
  198. * 生命周期函数--监听页面显示
  199. */
  200. onShow: function() {
  201. },
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide: function() {
  206. },
  207. /**
  208. * 生命周期函数--监听页面卸载
  209. */
  210. onUnload: function() {
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh: function() {
  216. },
  217. /**
  218. * 页面上拉触底事件的处理函数
  219. */
  220. onReachBottom: function() {
  221. },
  222. /**
  223. * 用户点击右上角分享
  224. */
  225. onShareAppMessage: function() {
  226. }
  227. })