band.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. band_code:"",
  13. band_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. Object.assign( info, res)
  55. this.setData({info,showcamara})
  56. })
  57. },
  58. saveBandInfo: function( e ){
  59. let info = this.data.info;
  60. let {band_code,band_name} = e.detail.value;
  61. util.http( '/maker/addMakerBand', {band_code,band_name}, (err,res)=>{
  62. if( err!= 0 ) return;
  63. Object.assign( info, res);
  64. app.setMakerInfo( info )
  65. util.showSuccess("保存成功")
  66. })
  67. },
  68. chooseImg: function () {
  69. var that = this
  70. wx.chooseImage({
  71. count: 1,
  72. sizeType: ['compressed'],
  73. sourceType: ['album'],
  74. success: function (res) {
  75. util.uploadFile( res.tempFilePaths[0], that.identify )
  76. }
  77. })
  78. },
  79. takePhoto() {
  80. var that = this
  81. var ctx = this.data.ctx
  82. that.setData({ hidden: false })
  83. ctx.takePhoto({
  84. quality: 'low',
  85. success: (res) => {
  86. var tempImagePath = res.tempImagePath
  87. util.uploadFile( tempImagePath, that.identify )
  88. },
  89. fail: function (res) {
  90. cosole.log('take error', res)
  91. that.setData({ hidden: true })
  92. app.showMsg('拍照失败')
  93. }
  94. })
  95. },
  96. goBack() {
  97. wx.navigateBack({
  98. delta: 1
  99. })
  100. }
  101. })