123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- const app = getApp();
- const util = require("../../../util/util.js")
- Page({
- data: {
- StatusBar: app.globalData.StatusBar,
- CustomBar: app.globalData.CustomBar,
- ctx: false,
- hidden: true,
- showcamara: false,
- type:'card',
- info:{
- band_code:"",
- band_name:""
- }
- },
- onLoad: function (options) {
- let info = this.data.info;
- app.getMakerInfo( res =>{
- Object.assign( info, res )
- this.setData( {info})
- })
- },
- onReady: function (res) {
- var ctx = wx.createCameraContext('myCamera')
- this.setData({ ctx: ctx })
- },
- previewImage: function (e) {
- var current = e.target.dataset.src;
- wx.previewImage({
- current: current,
- urls: [current]
- })
- } ,
- takeBand(){
- this.setData( {showcamara:true, type:'band'})
- },
- previewImage: function (e) {
- var current = e.target.dataset.src;
- wx.previewImage({
- current: current,
- urls: [current]
- })
- },
- identify( err, {url} ){
- if( err !=0 || !url ) {
- util.showMsg("图片上传失败")
- return
- }
- let info = this.data.info
- let method='/maker/addMakerBand';
- let showcamara= false
- util.http( method, {url}, (err,res)=>{
- if( err!= 0 ) return;
- Object.assign( info, res)
- this.setData({info,showcamara})
- })
- },
- saveBandInfo: function( e ){
- let info = this.data.info;
- let {band_code,band_name} = e.detail.value;
- util.http( '/maker/addMakerBand', {band_code,band_name}, (err,res)=>{
- if( err!= 0 ) return;
- Object.assign( info, res);
- app.setMakerInfo( info )
- util.showSuccess("保存成功")
- })
- },
- chooseImg: function () {
- var that = this
- wx.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album'],
- success: function (res) {
- util.uploadFile( res.tempFilePaths[0], that.identify )
- }
- })
- },
- takePhoto() {
- var that = this
- var ctx = this.data.ctx
- that.setData({ hidden: false })
- ctx.takePhoto({
- quality: 'low',
- success: (res) => {
- var tempImagePath = res.tempImagePath
- util.uploadFile( tempImagePath, that.identify )
- },
- fail: function (res) {
- cosole.log('take error', res)
- that.setData({ hidden: true })
- app.showMsg('拍照失败')
- }
- })
- },
- goBack() {
- wx.navigateBack({
- delta: 1
- })
- }
- })
|