index.js 5.2 KB

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