index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // pages/wx_airport/problem_report/index.js
  2. var upload_image = require('../../../utils/upload/upload_image.js');
  3. var upload_video = require('../../../utils/upload/upload_video.js');
  4. var {
  5. addProblemReport
  6. } = require('../../../utils/api/xiaosha');
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. userInfo: null,
  13. adminId: null,
  14. anonymityFlag: true, //状态
  15. desc: '', //问题详情
  16. pictureVOList: [], //图片
  17. video: {}, //视频
  18. },
  19. // 是否匿名
  20. onChange(event) {
  21. this.setData({
  22. anonymityFlag: event.detail,
  23. });
  24. },
  25. //获得问题详情
  26. descFun(e) {
  27. this.setData({
  28. desc: e.detail.value
  29. })
  30. },
  31. //上报
  32. report() {
  33. let {
  34. anonymityFlag,
  35. desc,
  36. pictureVOList,
  37. video
  38. } = this.data
  39. if (!desc) {
  40. wx.showToast({
  41. title: '请填写问题详情',
  42. icon: 'none'
  43. })
  44. return
  45. }
  46. let userInfo = wx.getStorageSync('userInfo')
  47. let form = {
  48. anonymityFlag,
  49. desc,
  50. pictureVOList,
  51. video,
  52. adminId: this.data.adminId || parseInt(userInfo.orgId),
  53. userId: userInfo.userId ? userInfo.userId : null,
  54. }
  55. addProblemReport(form).then(res => {
  56. if (res.code == 200) {
  57. wx.showModal({
  58. title: '提示',
  59. content: '上报成功!',
  60. showCancel: false,
  61. success: res => {
  62. if (userInfo.orgId) {
  63. wx.reLaunch({
  64. url: '/pages/wx_airport/rlxf_pass/rlxf_pass?orgId=' + userInfo.orgId,
  65. })
  66. } else {
  67. wx.reLaunch({
  68. url: '/pages/wx_airport/rlxf_index/rlxf_index',
  69. })
  70. }
  71. }
  72. })
  73. } else {
  74. wx.showToast({
  75. title: res.msg,
  76. icon: 'none'
  77. })
  78. }
  79. })
  80. },
  81. //选择照片
  82. ChooseImage() {
  83. var that = this;
  84. wx.chooseMedia({
  85. count: 4, //默认9
  86. mediaType: ['image'],
  87. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  88. sourceType: ['album'], //从相册选择
  89. success: (res) => {
  90. var image = {
  91. url: res.tempFiles[0].tempFilePath
  92. }
  93. wx.showLoading({
  94. title: '上传中~',
  95. })
  96. upload_image(image).then((img) => {
  97. let data = {
  98. url: img.url
  99. }
  100. that.setData({
  101. pictureVOList: that.data.pictureVOList.concat(data)
  102. })
  103. wx.hideLoading();
  104. })
  105. },
  106. fail(res) {
  107. wx.hideLoading();
  108. wx.showToast({
  109. title: '照片上传失败,请重试',
  110. icon: 'none'
  111. })
  112. },
  113. // complete() {
  114. // wx.hideLoading();
  115. // }
  116. });
  117. },
  118. //查看照片
  119. ViewImage(e) {
  120. wx.previewImage({
  121. urls: this.data.pictureVOList,
  122. current: e.currentTarget.dataset.url
  123. });
  124. },
  125. //删除照片
  126. DelImg(e) {
  127. wx.showModal({
  128. title: '提示',
  129. content: '确定删除?',
  130. cancelText: '取消',
  131. confirmText: '确定',
  132. success: res => {
  133. if (res.confirm) {
  134. this.data.pictureVOList.splice(e.currentTarget.dataset.index, 1);
  135. this.setData({
  136. pictureVOList: this.data.pictureVOList,
  137. })
  138. }
  139. }
  140. })
  141. },
  142. //选择视频
  143. ChooseVideo() {
  144. var that = this;
  145. wx.chooseMedia({
  146. mediaType: ['video'],
  147. sizeType: ['compressed'],
  148. sourceType: ['album', 'camera'], //从相册选择
  149. maxDuration: 15,
  150. success: (res) => {
  151. wx.showLoading({
  152. title: '视频上传中',
  153. mask: true
  154. })
  155. upload_video(res.tempFiles[0]).then((video) => {
  156. wx.showToast({
  157. title: '视频上传成功',
  158. })
  159. let data = {
  160. url: video.url
  161. }
  162. this.setData({
  163. video: data
  164. })
  165. wx.hideLoading();
  166. })
  167. },
  168. // complete() {
  169. // wx.hideLoading();
  170. // }
  171. });
  172. },
  173. //删除视频
  174. DelVideo() {
  175. wx.showModal({
  176. title: '提示',
  177. content: '确定删除?',
  178. cancelText: '取消',
  179. confirmText: '确定',
  180. success: res => {
  181. if (res.confirm) {
  182. this.setData({
  183. video: {},
  184. })
  185. }
  186. }
  187. })
  188. },
  189. /**
  190. * 生命周期函数--监听页面加载
  191. */
  192. onLoad(options) {
  193. if (options) {
  194. this.setData({
  195. adminId: parseInt(options.adminId)
  196. })
  197. }
  198. this.setData({
  199. userInfo: wx.getStorageSync('userInfo')
  200. })
  201. },
  202. /**
  203. * 生命周期函数--监听页面初次渲染完成
  204. */
  205. onReady() {
  206. },
  207. /**
  208. * 生命周期函数--监听页面显示
  209. */
  210. onShow() {
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide() {
  216. },
  217. /**
  218. * 生命周期函数--监听页面卸载
  219. */
  220. onUnload() {
  221. },
  222. /**
  223. * 页面相关事件处理函数--监听用户下拉动作
  224. */
  225. onPullDownRefresh() {
  226. },
  227. /**
  228. * 页面上拉触底事件的处理函数
  229. */
  230. onReachBottom() {
  231. },
  232. /**
  233. * 用户点击右上角分享
  234. */
  235. onShareAppMessage() {
  236. }
  237. })