takeBill.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. takePhotoAction: function () {
  17. const ctx = wx.createCameraContext()
  18. ctx.takePhoto({
  19. quality: 'high',
  20. success: (res) => {
  21. console.log(res)
  22. let src = res.tempImagePath
  23. wx.compressImage({
  24. src,
  25. quality: 80, // 压缩质量
  26. success: async e => {
  27. console.log("图片压缩成功!", e)
  28. wx.hideLoading({
  29. success: (res) => {},
  30. })
  31. if (wx.getStorageSync('userName')) {
  32. wx.showLoading({
  33. title: '正在上传...',
  34. })
  35. let postData = {
  36. type: 0,
  37. userId: wx.getStorageSync('userId'),
  38. }
  39. postData.location = ''
  40. let res = await uploadFile(e.tempFilePath, postData)
  41. console.log("上传结束", res)
  42. if (res.status == 0) {
  43. wx.showToast({
  44. title: res.msg
  45. })
  46. wx.setStorageSync('shareImageUrl', res.result.viewUrl)
  47. console.log(wx.getStorageSync('shareImageUrl'))
  48. wx.downloadFile({
  49. url: res.result.viewUrl,
  50. success: e => {
  51. console.log("下载调用!", e)
  52. wx.setStorageSync('cacheImage', e.tempFilePath)
  53. wx.redirectTo({
  54. url: '/pages/takeBill/success/success',
  55. })
  56. },
  57. fail: e => {
  58. console.log("失败3", e)
  59. }
  60. })
  61. } else {
  62. wx.showToast({
  63. title: res.msg
  64. })
  65. }
  66. } else {
  67. // 新用户图片
  68. console.log("新用户图片", e)
  69. wx.setStorageSync('type', 1)
  70. wx.setStorageSync('file', e.tempFilePath)
  71. wx.redirectTo({
  72. url: `/pages/newCachePage/newCachePage`,
  73. })
  74. }
  75. },
  76. fail: e => {
  77. console.log("失败2", e)
  78. }
  79. })
  80. }
  81. })
  82. },
  83. onLoad() {
  84. let userName = wx.getStorageSync('userName')
  85. let userId = wx.getStorageSync('userId')
  86. let phone = wx.getStorageSync('phone')
  87. let shipId = wx.getStorageSync('shipId')
  88. this.setData({
  89. userName,
  90. phone,
  91. userId,
  92. shipId
  93. })
  94. }
  95. })