index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // nova-werun/pages/my/feedback/index.js
  2. const Parse = getApp().Parse
  3. const company = getApp().globalData.company
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. statusBarHeight: 0, // 状态栏高度
  10. screenHeight: 0, // 屏幕高度
  11. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  12. bottomNavHeight: 0, // 底部导航栏高度
  13. contentHeight: 0, // 可用内容高度
  14. contentHeight2: 0,
  15. contentpadding: 0, //顶部padding高度
  16. content: '',
  17. mobile: '',
  18. fileList: []
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. const systemInfo = wx.getSystemInfoSync();
  25. const statusBarHeight = systemInfo.statusBarHeight || 0;
  26. const screenHeight = systemInfo.screenHeight || 0;
  27. const custom = wx.getMenuButtonBoundingClientRect();
  28. const customHeight = custom.height + 10 + 2 || 0;
  29. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  30. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  31. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  32. this.setData({
  33. statusBarHeight,
  34. screenHeight,
  35. customHeight,
  36. bottomNavHeight,
  37. contentpadding,
  38. contentHeight
  39. });
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh: function () {
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. async getUptoken() {
  77. let res = await Parse.Cloud.run('qiniu_uptoken', {
  78. company: company
  79. })
  80. console.log(Object.keys(res));
  81. console.log(res);
  82. this.setData({
  83. uptokenURL: res.uptoken,
  84. domain: res.domain,
  85. uploadURL: res.zoneUrl
  86. })
  87. },
  88. changeFile(e) {
  89. console.log(e);
  90. let fileList = e.detail
  91. console.log(fileList);
  92. this.setData({
  93. fileList
  94. })
  95. },
  96. //提交
  97. upPost() {
  98. let {
  99. content,
  100. mobile,
  101. fileList
  102. } = this.data
  103. fileList = fileList.map(file => file.url)
  104. console.log(content, mobile, fileList);
  105. let contentLen = content.replace(/(^s*)|(s*$)/g, "").length
  106. if (content == '' || contentLen == 0) {
  107. wx.showToast({
  108. title: '内容不完整',
  109. icon: 'none',
  110. image: '',
  111. duration: 1500,
  112. mask: false,
  113. });
  114. return
  115. }
  116. if (!mobile) {
  117. wx.showToast({
  118. title: '请留下您的联系方式哦!',
  119. icon: 'none',
  120. image: '',
  121. duration: 1500,
  122. mask: false,
  123. });
  124. return
  125. }
  126. wx.showLoading({
  127. title: '提交中',
  128. });
  129. try {
  130. let user = Parse.User.current();
  131. let feedBack = Parse.Object.extend("Feedback");
  132. let fb = new feedBack();
  133. fb.set("company", {
  134. __type: "Pointer",
  135. className: "Company",
  136. objectId: company,
  137. });
  138. fb.set("user", {
  139. __type: "Pointer",
  140. className: "_User",
  141. objectId: user.id,
  142. });
  143. fb.set("name", user.realname);
  144. fb.set("images", fileList);
  145. fb.set("content", content);
  146. fb.set("mobile", mobile)
  147. // fb.set("type","email")
  148. fb.save().then((res) => {
  149. console.log(res);
  150. wx.hideLoading();
  151. wx.showToast({
  152. title: "已提交",
  153. icon: "none",
  154. });
  155. setTimeout(() => {
  156. wx.navigateBack({
  157. delta: 1
  158. });
  159. }, 1000);
  160. });
  161. } catch (error) {
  162. console.log(error);
  163. wx.hideLoading();
  164. }
  165. },
  166. onLoad: function (options) {
  167. this.setData({
  168. activeColor:getApp().globalData.activeColor || '#4F9AF7'
  169. })
  170. this.getUptoken()
  171. },
  172. })