微信小程序扫描二维码的内容,作为参数跳转填入到下一个页面input框

scan.wxml

<view class="container">
	<view class='imagesize'>
		<image class='img' bindtap='getScancode' src="{{back}}"></image>
	</view>
	<view style="display: flex;justify-content: center;">请扫描卡号</view>
	<!-- <view wx:if="{{result !=''}}">
		<view>扫码的内容:{{result}}</view>
	</view> -->
	<navigator url="/pages/card/card" hover-class="changestyle">
		<view class='imagesizehand'>
			<image src="{{hand}}"></image>
		</view>
		<view style="display: flex;justify-content: center;">手动输入卡号</view>
	</navigator>
</view>

scan.js

//index.js
//获取应用实例
const app = getApp()

Page({
	data: {
		back: "../../images/scanning.png",
		hand: "../../images/hand.png",
		result: ''
	},

	onLoad: function() {
	},
	getScancode: function() {
		var _this = this;
		// 允许从相机和相册扫码
		wx.scanCode({
			success: (res) => {
				var result = res.result;
				_this.setData({
					result: result,
				})

        //在回调函数里面,将获得的返回值,带到下一个界面里面去
       
        //三秒钟之后跳转到主界面
        setTimeout(function () {
          wx.navigateTo({
            url: '../card/card?result=' + result
          })
        }, 3000)

			}

      
		})
	}
})

card.wxml

<form catchsubmit="confirmPublish">
	<view class="search_arr">
		<input maxlength="15" placeholder="请输入卡号" value="{{deviceId}}" data-name="deviceId" bindblur="setInput"></input>
	</view>
	<button class='btn1' bindtap="bindViewTap" form-type="submit">绑定</button>
</form>

card.js

// pages/card/card.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		id: 1,
		deviceId: '',
	},

	//事件处理函数

	bindViewTap: function() {
		wx.navigateTo({
			url: '../cardsuccess/cardsuccess'
		})
		//三秒钟之后跳转到主界面
		setTimeout(function() {
			wx.switchTab({
				url: '../index/index'
			})
		}, 3000)
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
    console.log(options)
    // 生命周期函数--监听页面加载
    this.setData({
      deviceId: options.result,
  
    })
	},

	confirmPublish: function() {
		// if (!this.data.taskName) {
		//   this.setData({ errortip: true, errorMsg: '任务名不能为空' })
		//   setTimeout(() => {
		//     this.setData({ errortip: false, errorMsg: '' })
		//   }, 2000)
		//   return
		// }


		// const data = {}
		// data.id = this.data.id
		// data.deviceId = this.data.deviceId
		var params = {

			id: 1,
			deviceId: "12345678",
		}


		wx.request({
			url: 'http://192.xxx.4.103:8093/cs-applet/subscribe/bindingCard',
			method: 'PUT',
			data: params,
			dataType: "json",
			success: function(res) {
				// console.log(res)
				// if (res.data.code === "0001") {
				//   wx.showToast({
				//     title: res.data.msg,
				//     icon: 'none',
				//     duration: 2000
				//   })
				//   return;
				// }
				// wx.showToast({
				//   title: '添加成功',
				//   icon: 'success',
				//   duration: 2000
				// })
				// setTimeout(() => {
				//   wx.switchTab({
				//     url: "/pages/index/index?refresh=true",
				//   });
				// }, 1000);
			},
			fail: function(error) {
				wx.showToast({
					title: error.message || '保存失败'
				})
				console.log(error)
			}
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值