cachePage.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/cachePage/cachePage.js
  2. import cloudApi from "../../apis/cloudApi"
  3. import {
  4. postApi
  5. } from "../../apis/api"
  6. import {
  7. uploadFile
  8. } from "../../utils/upload"
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. type: "",
  15. file: "",
  16. latitude: "",
  17. longitude: "",
  18. shipName: "",
  19. shipMmsi: "",
  20. agreeModal: false,
  21. agreeText: false
  22. },
  23. goBack() {
  24. wx.redirectTo({
  25. url: '/pages/index/index',
  26. })
  27. },
  28. checkout() {
  29. if (!this.data.shipName) {
  30. wx.showToast({
  31. title: '请输入船名!',
  32. icon: "error"
  33. })
  34. return
  35. }
  36. if (!this.data.shipMmsi) {
  37. wx.showToast({
  38. title: '请输入MMSI!',
  39. icon: "error"
  40. })
  41. return
  42. }
  43. return true
  44. },
  45. agree() {
  46. this.setData({
  47. agreeText: false,
  48. })
  49. },
  50. showAgeeeText() {
  51. this.setData({
  52. agreeText: true
  53. })
  54. },
  55. hideAgreeText() {
  56. this.setData({
  57. agreeText: false
  58. })
  59. },
  60. hideAgreeModal() {
  61. this.setData({
  62. agreeModal: false
  63. })
  64. },
  65. showAgreeModal() {
  66. // if (!this.checkout()) return
  67. this.setData({
  68. agreeModal: true
  69. })
  70. },
  71. async getPhoneNumber(e) {
  72. if (e.detail.errMsg == "getPhoneNumber:ok") {
  73. wx.showLoading({
  74. title: '正在登录...',
  75. })
  76. let session_key = wx.getStorageSync('session_key')
  77. let {
  78. result
  79. } = await cloudApi("getWxPhoneNumber", {
  80. ...e.detail,
  81. session_key
  82. })
  83. let {
  84. phone,
  85. } = result
  86. let {
  87. shipName,
  88. shipMmsi
  89. } = this.data
  90. console.log(phone,
  91. shipName,
  92. shipMmsi, )
  93. let res = await uploadFile(wx.getStorageSync('file'), {
  94. openId: wx.getStorageSync('openId'),
  95. phone,
  96. shipName,
  97. shipMmsi,
  98. type: wx.getStorageSync('type'),
  99. location: `${this.data.longitude},${this.data.latitude}`
  100. }, 1)
  101. wx.setStorageSync('shareImageUrl', res.result.mediaInfo.viewUrl)
  102. if (res.status == 0) {
  103. let {
  104. shipInfo,
  105. userInfo
  106. } = res.result
  107. let data = {
  108. ...shipInfo,
  109. ...userInfo
  110. }
  111. Object.keys(data).forEach(function (key) {
  112. wx.setStorageSync(key, data[key])
  113. })
  114. wx.showToast({
  115. title: res.msg,
  116. })
  117. wx.redirectTo({
  118. url: '/pages/takePhoto/takePhoto',
  119. })
  120. } else {
  121. wx.showToast({
  122. title: res.msg,
  123. icon: "error"
  124. })
  125. }
  126. } else {
  127. wx.showToast({
  128. title: '请授权以登录',
  129. icon: "error"
  130. })
  131. }
  132. },
  133. /**
  134. * 生命周期函数--监听页面加载
  135. */
  136. onLoad: function (options) {
  137. this.setData({
  138. type: wx.getStorageSync('type'),
  139. file: wx.getStorageSync('file'),
  140. latitude: wx.getStorageSync('latitude'),
  141. longitude: wx.getStorageSync('longitude')
  142. })
  143. },
  144. onShareAppMessage: function () {
  145. }
  146. })