band.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. identify( err, {url} ){
  38. if( err !=0 || !url ) {
  39. util.showMsg("图片上传失败")
  40. return
  41. }
  42. let info = this.data.info
  43. let method='/maker/addMakerBand';
  44. let showcamara= false
  45. util.http( method, {url}, (err,res)=>{
  46. if( err!= 0 ) return;
  47. console.log("http",err, res)
  48. Object.assign( info, res)
  49. this.setData({info,showcamara})
  50. })
  51. },
  52. chooseImg: function () {
  53. var that = this
  54. wx.chooseImage({
  55. count: 1,
  56. sizeType: ['compressed'],
  57. sourceType: ['album'],
  58. success: function (res) {
  59. util.uploadFile( res.tempFilePaths[0], that.identify )
  60. }
  61. })
  62. },
  63. takePhoto() {
  64. var that = this
  65. var ctx = this.data.ctx
  66. that.setData({ hidden: false })
  67. ctx.takePhoto({
  68. quality: 'low',
  69. success: (res) => {
  70. var tempImagePath = res.tempImagePath
  71. util.uploadFile( tempImagePath, that.identify )
  72. },
  73. fail: function (res) {
  74. cosole.log('take error', res)
  75. that.setData({ hidden: true })
  76. app.showMsg('拍照失败')
  77. }
  78. })
  79. },
  80. goBack() {
  81. wx.navigateBack({
  82. delta: 1
  83. })
  84. }
  85. })