band.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const app = getApp();
  2. const util = require("../../../util/util.js")
  3. Page({
  4. data: {
  5. StatusBar: app.globalData.StatusBar,
  6. CustomBar: app.globalData.CustomBar,
  7. ctx: false,
  8. hidden: true,
  9. showcamara: false,
  10. type:'card',
  11. info:{
  12. card_code:"",
  13. name:""
  14. }
  15. },
  16. onLoad: function (options) {
  17. let info = this.data.info;
  18. app.getMakerInfo( res =>{
  19. Object.assign( info, res )
  20. this.setData( {info })
  21. })
  22. },
  23. onReady: function (res) {
  24. var ctx = wx.createCameraContext('myCamera')
  25. this.setData({ ctx: ctx })
  26. },
  27. previewImage: function (e) {
  28. var current = e.target.dataset.src;
  29. wx.previewImage({
  30. current: current,
  31. urls: [current]
  32. })
  33. } ,
  34. takeBand(){
  35. this.setData( {showcamara:true, type:'band'})
  36. },
  37. previewImage: function (e) {
  38. var current = e.target.dataset.src;
  39. wx.previewImage({
  40. current: current,
  41. urls: [current]
  42. })
  43. },
  44. identify( err, {url} ){
  45. if( err !=0 || !url ) {
  46. util.showMsg("图片上传失败")
  47. return
  48. }
  49. let info = this.data.info
  50. let method='/maker/addMakerBand';
  51. let showcamara= false
  52. util.http( method, {url}, (err,res)=>{
  53. if( err!= 0 ) return;
  54. console.log("http",err, res)
  55. Object.assign( info, res)
  56. this.setData({info,showcamara})
  57. })
  58. },
  59. chooseImg: function () {
  60. var that = this
  61. wx.chooseImage({
  62. count: 1,
  63. sizeType: ['compressed'],
  64. sourceType: ['album'],
  65. success: function (res) {
  66. util.uploadFile( res.tempFilePaths[0], that.identify )
  67. }
  68. })
  69. },
  70. takePhoto() {
  71. var that = this
  72. var ctx = this.data.ctx
  73. that.setData({ hidden: false })
  74. ctx.takePhoto({
  75. quality: 'low',
  76. success: (res) => {
  77. var tempImagePath = res.tempImagePath
  78. util.uploadFile( tempImagePath, that.identify )
  79. },
  80. fail: function (res) {
  81. cosole.log('take error', res)
  82. that.setData({ hidden: true })
  83. app.showMsg('拍照失败')
  84. }
  85. })
  86. },
  87. goBack() {
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. }
  92. })