takeBill.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {
  2. uploadFile
  3. } from "../../utils/upload"
  4. Page({
  5. data: {
  6. avatar: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/avatar-icon.jpg?sign=f5c66c94d189436f82353eb48cb01f08&t=1634538864",
  7. cameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera-icon.png?sign=11a65871a2800cd04ecaa8991687fccd&t=1634607415",
  8. newCameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera.png?sign=ad0fe8bead6a46cb20f45f792d4bed67&t=1645502416",
  9. userName: "",
  10. phone: "",
  11. shipName: "",
  12. shipMmsi: "",
  13. authModal: false,
  14. modalText: "位置"
  15. },
  16. test() {
  17. const ctx = wx.createCameraContext()
  18. ctx.takePhoto({
  19. quality: 'high',
  20. success: (res) => {
  21. let src = res.tempImagePath
  22. wx.navigateTo({
  23. url: `/pages/takeBill/canvas/canvas?src=${src}`,
  24. })
  25. // wx.getImageInfo({
  26. // src,
  27. // success: e => {
  28. // console.log(e)
  29. // }
  30. // })
  31. }
  32. })
  33. },
  34. goBack() {
  35. // wx.redirectTo({
  36. // url: '/pages/takePhoto/takePhoto',
  37. // })
  38. wx.navigateBack()
  39. },
  40. takePhotoAction: function () {
  41. const ctx = wx.createCameraContext()
  42. ctx.takePhoto({
  43. quality: 'high',
  44. success: (res) => {
  45. console.log(res)
  46. let src = res.tempImagePath
  47. wx.compressImage({
  48. src,
  49. quality: 80, // 压缩质量
  50. success: async e => {
  51. console.log("图片压缩成功!", e)
  52. wx.hideLoading({
  53. success: (res) => {},
  54. })
  55. if (wx.getStorageSync('userName')) {
  56. wx.showLoading({
  57. title: '正在上传...',
  58. })
  59. let postData = {
  60. type: 0,
  61. userId: wx.getStorageSync('userId'),
  62. }
  63. postData.location = ''
  64. let res = await uploadFile(e.tempFilePath, postData)
  65. console.log("上传结束", res)
  66. if (res.status == 0) {
  67. wx.showToast({
  68. title: res.msg
  69. })
  70. wx.setStorageSync('shareImageUrl', res.result.viewUrl)
  71. console.log(wx.getStorageSync('shareImageUrl'))
  72. wx.downloadFile({
  73. url: res.result.viewUrl,
  74. success: e => {
  75. console.log("下载调用!", e)
  76. wx.setStorageSync('cacheImage', e.tempFilePath)
  77. wx.redirectTo({
  78. url: '/pages/takeBill/success/success',
  79. })
  80. },
  81. fail: e => {
  82. console.log("失败3", e)
  83. }
  84. })
  85. } else {
  86. wx.showToast({
  87. title: res.msg
  88. })
  89. }
  90. } else {
  91. // 新用户图片
  92. console.log("新用户图片", e)
  93. wx.setStorageSync('type', 1)
  94. wx.setStorageSync('file', e.tempFilePath)
  95. wx.redirectTo({
  96. url: `/pages/newCachePage/newCachePage`,
  97. })
  98. }
  99. },
  100. fail: e => {
  101. console.log("失败2", e)
  102. }
  103. })
  104. }
  105. })
  106. },
  107. onLoad() {
  108. let userName = wx.getStorageSync('userName')
  109. let userId = wx.getStorageSync('userId')
  110. let phone = wx.getStorageSync('phone')
  111. let shipId = wx.getStorageSync('shipId')
  112. this.setData({
  113. userName,
  114. phone,
  115. userId,
  116. shipId
  117. })
  118. }
  119. })