experience.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // pages/my/experience/experience.js
  2. const App = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. expertId: null,
  9. meetId: null,
  10. memberId: null,
  11. topicId: null,
  12. content: null,
  13. user: wx.getStorageSync('USER'),
  14. isAnonymous: false,
  15. checked: false,
  16. list: [],
  17. picture: '',
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. console.log(options)
  24. this.setData({
  25. meetId: options.meetId,
  26. expertId: options.expertId,
  27. topicId: options.topicId,
  28. memberId: options.memberId
  29. })
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow() {
  40. },
  41. change(e) {
  42. if (e.detail.value.length > 0) {
  43. this.setData({
  44. isAnonymous: true
  45. })
  46. } else {
  47. this.setData({
  48. isAnonymous: false
  49. })
  50. }
  51. },
  52. submit() {
  53. if (!this.data.content) {
  54. wx.showToast({
  55. icon: 'none',
  56. title: '心得感受不能为空',
  57. })
  58. return false
  59. }
  60. App._post_form('meetevaluation/shareExperience', '', {
  61. content: this.data.content,
  62. expertId: this.data.expertId,
  63. id: this.data.user.id,
  64. meetId: this.data.meetId,
  65. isAnonymous: this.data.isAnonymous == true ? 1 : 0,
  66. memberId: this.data.user.id,
  67. picture: this.data.list.join(','),
  68. topicId: this.data.topicId
  69. }, res => {
  70. if (res.code === 0) {
  71. wx.showToast({
  72. title: '分享心得成功',
  73. })
  74. setTimeout(() =>{
  75. wx.switchTab({
  76. url: '/pages/home/index/index',
  77. })
  78. },2000)
  79. }
  80. })
  81. },
  82. uploadHandle() {
  83. if (this.data.list.length == 6) {
  84. return false
  85. }
  86. let _this = this;
  87. var tempFile;
  88. wx.showActionSheet({
  89. itemList: ['拍照上传', '从相册中选择'],
  90. success(res) {
  91. if (res.tapIndex === 0) {
  92. wx.chooseImage({
  93. count: 1,
  94. sizeType: ['original', 'compressed'],
  95. sourceType: ['camera'],
  96. success(res) {
  97. const tempFilePaths = res.tempFilePaths
  98. wx.uploadFile({
  99. url: App.apiRoot + 'file/upload',
  100. filePath: tempFilePaths[0],
  101. name: 'file',
  102. success: function (res) {
  103. if (res.errMsg === "uploadFile:ok") {
  104. wx.showToast({
  105. title: '上传成功',
  106. image: '',
  107. duration: 1500,
  108. mask: false
  109. });
  110. let data = JSON.parse(res.data)
  111. let imglist = _this.data.list
  112. imglist.push(data.data)
  113. _this.setData({
  114. list: imglist
  115. })
  116. }
  117. },
  118. function () {
  119. wx.showToast({
  120. title: '上传失败',
  121. icon: 'none',
  122. image: '',
  123. duration: 1500,
  124. mask: false,
  125. });
  126. }
  127. })
  128. }
  129. })
  130. } else if (res.tapIndex === 1) {
  131. wx.chooseImage({
  132. count: 1,
  133. sizeType: ['original', 'compressed'],
  134. sourceType: ['album'],
  135. success(res) {
  136. const tempFilePaths = res.tempFilePaths
  137. wx.uploadFile({
  138. url: App.apiRoot + 'file/upload',
  139. filePath: tempFilePaths[0],
  140. name: 'file',
  141. success: function (res) {
  142. if (res.errMsg === "uploadFile:ok") {
  143. wx.showToast({
  144. title: '上传成功',
  145. image: '',
  146. duration: 1500,
  147. mask: false
  148. });
  149. let data = JSON.parse(res.data)
  150. let imglist = _this.data.list
  151. imglist.push(data.data)
  152. _this.setData({
  153. list: imglist
  154. })
  155. }
  156. },
  157. function () {
  158. wx.showToast({
  159. title: '上传失败',
  160. icon: 'none',
  161. image: '',
  162. duration: 1500,
  163. mask: false,
  164. success: (result) => {},
  165. fail: () => {},
  166. complete: () => {}
  167. });
  168. }
  169. })
  170. }
  171. })
  172. }
  173. },
  174. fail(res) {}
  175. })
  176. },
  177. /**
  178. * 生命周期函数--监听页面隐藏
  179. */
  180. onHide() {
  181. },
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload() {
  186. },
  187. /**
  188. * 页面相关事件处理函数--监听用户下拉动作
  189. */
  190. onPullDownRefresh() {
  191. },
  192. /**
  193. * 页面上拉触底事件的处理函数
  194. */
  195. onReachBottom() {
  196. },
  197. /**
  198. * 用户点击右上角分享
  199. */
  200. onShareAppMessage() {
  201. }
  202. })