securityCheck.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/securityCheck/securityCheck.js
  2. import {
  3. postApi
  4. } from "../../apis/api"
  5. import {
  6. apiUrl
  7. } from "../../apis/apiConfig"
  8. import {
  9. isImage
  10. } from "../../utils/utils"
  11. Page({
  12. data: {
  13. list: [],
  14. loginStatus: wx.getStorageSync('userId')
  15. },
  16. async login() {
  17. if (!wx.getStorageSync('openId')) return
  18. let res1 = await postApi("/user/wx/openId/login", {
  19. openId: wx.getStorageSync('openId')
  20. })
  21. if (res1.data.status == 0) {
  22. let data = {
  23. ...res1.data.result.userInfo,
  24. ...res1.data.result.shipInfo,
  25. }
  26. Object.keys(data).forEach(function (key) {
  27. wx.setStorageSync(key, data[key])
  28. })
  29. this.setData({
  30. loginStatus: true
  31. })
  32. this.getList()
  33. } else {
  34. wx.switchTab({
  35. url: '/pages/takePhoto/takePhoto',
  36. })
  37. }
  38. },
  39. async getList() {
  40. if (!wx.getStorageSync('userId')) {
  41. wx.showToast({
  42. title: '尚未登录',
  43. icon: 'error'
  44. })
  45. return
  46. }
  47. let {
  48. data
  49. } = await postApi('/security/check/list', {
  50. userId: wx.getStorageSync('userId'),
  51. shipId: wx.getStorageSync('shipId')
  52. })
  53. wx.stopPullDownRefresh()
  54. if (data.status == 0) {
  55. for (let i of data.result) {
  56. i.isImage = isImage(i.fileKey)
  57. }
  58. this.setData({
  59. list: data.result
  60. })
  61. } else {
  62. this.setData({
  63. list: []
  64. })
  65. }
  66. },
  67. uploadMedia(e) {
  68. let {
  69. id: itemId
  70. } = e.currentTarget.dataset
  71. wx.showLoading({
  72. title: '高精度定位中...'
  73. })
  74. wx.getLocation({
  75. type: 'gcj02',
  76. isHighAccuracy: true,
  77. success: e => {
  78. let {
  79. latitude,
  80. longitude
  81. } = e
  82. wx.chooseMedia({
  83. count: 1,
  84. mediaType: ['image', 'video'],
  85. sourceType: ['album', 'camera'],
  86. sizeType: ['original', 'compressed'],
  87. success: e => {
  88. console.log("获取媒体成功!", e)
  89. let filePath = e.tempFiles[0].tempFilePath
  90. wx.showLoading({
  91. title: '正在上传...'
  92. })
  93. wx.uploadFile({
  94. url: `${apiUrl}/security/check/upload/file`,
  95. filePath,
  96. name: 'file',
  97. formData: {
  98. itemId,
  99. userId: wx.getStorageSync('userId'),
  100. location: `${longitude},${latitude}`
  101. },
  102. success: async e => {
  103. let data = JSON.parse(e.data)
  104. if (data.status == 0) {
  105. this.getList()
  106. wx.showToast({
  107. title: data.msg,
  108. duration: 1500
  109. })
  110. } else {
  111. wx.showToast({
  112. title: data.msg,
  113. icon: "error",
  114. duration: 2000
  115. })
  116. }
  117. },
  118. fail: err => {
  119. wx.showToast({
  120. title: data.msg,
  121. icon: "error",
  122. duration: 2000
  123. })
  124. }
  125. })
  126. },
  127. fail: e => {
  128. console.log("失败1", e)
  129. }
  130. })
  131. },
  132. fail: e => {
  133. this.setData({
  134. authModal: true,
  135. modalText: "位置信息"
  136. })
  137. },
  138. complete: e => {
  139. wx.hideLoading({
  140. success: (res) => {},
  141. })
  142. }
  143. })
  144. },
  145. onPullDownRefresh() {
  146. this.getList()
  147. },
  148. onShow() {
  149. this.setData({
  150. loginStatus: wx.getStorageSync('userId')
  151. })
  152. },
  153. onLoad(options) {
  154. this.getList()
  155. },
  156. })