index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. const Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. Page({
  4. data: {
  5. content: '',
  6. mobile: '',
  7. fileList: []
  8. },
  9. async getUptoken() {
  10. let res = await Parse.Cloud.run('qiniu_uptoken', {
  11. company: company
  12. })
  13. console.log(Object.keys(res));
  14. console.log(res);
  15. this.setData({
  16. uptokenURL: res.uptoken,
  17. domain: res.domain,
  18. uploadURL: res.zoneUrl
  19. })
  20. },
  21. changeFile(e) {
  22. console.log(e);
  23. let fileList = e.detail
  24. console.log(fileList);
  25. this.setData({
  26. fileList
  27. })
  28. },
  29. //提交
  30. upPost() {
  31. let {
  32. content,
  33. mobile,
  34. fileList
  35. } = this.data
  36. fileList = fileList.map(file => file.url)
  37. console.log(content, mobile, fileList);
  38. let contentLen = content.replace(/(^s*)|(s*$)/g, "").length
  39. if (content == '' || contentLen == 0) {
  40. wx.showToast({
  41. title: '内容不完整',
  42. icon: 'none',
  43. image: '',
  44. duration: 1500,
  45. mask: false,
  46. });
  47. return
  48. }
  49. if (!mobile) {
  50. wx.showToast({
  51. title: '请留下您的联系方式哦!',
  52. icon: 'none',
  53. image: '',
  54. duration: 1500,
  55. mask: false,
  56. });
  57. return
  58. }
  59. wx.showLoading({
  60. title: '提交中',
  61. });
  62. try {
  63. let user = Parse.User.current();
  64. let feedBack = Parse.Object.extend("Feedback");
  65. let fb = new feedBack();
  66. fb.set("company", {
  67. __type: "Pointer",
  68. className: "Company",
  69. objectId: company,
  70. });
  71. fb.set("user", {
  72. __type: "Pointer",
  73. className: "_User",
  74. objectId: user.id,
  75. });
  76. fb.set("name", user.realname);
  77. fb.set("images", fileList);
  78. fb.set("content", content);
  79. fb.set("mobile", mobile)
  80. // fb.set("type","email")
  81. fb.save().then((res) => {
  82. console.log(res);
  83. wx.hideLoading();
  84. wx.showToast({
  85. title: "已提交",
  86. icon: "none",
  87. });
  88. setTimeout(() => {
  89. wx.navigateBack({
  90. delta: 1
  91. });
  92. }, 1000);
  93. });
  94. } catch (error) {
  95. console.log(error);
  96. wx.hideLoading();
  97. }
  98. },
  99. onLoad: function (options) {
  100. this.setData({
  101. activeColor:getApp().globalData.activeColor || '#229293'
  102. })
  103. this.getUptoken()
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })