12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- const APP = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- //表单错误信息
- openNumError: null,
- deviceNameError: null,
- deviceNum: '',//设备码,扫码复写表单
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- },
- /**
- * 扫码
- */
- scanCode() {
- const that = this;
- wx.scanCode({
- success(res) {
- that.setData({
- deviceNum: res.result
- })
- },
- fail: function () {
- console.log("调用摄像头失败")
- }
- })
- },
- /**
- * 表单提交
- */
- submit(form) {
- //校验表单
- if (!this.checkForm(form)) return;
- const params = {
- openNum: form.detail.value.openNum,
- deviceName: form.detail.value.deviceName
- };
- APP.Post(APP.Url.bind, params).then(res => {
- APP.Modal.tips("绑定成功!");
- }).catch(res => {
- console.log(res)
- APP.Modal.tips("绑定失败!")
- })
- },
- /**
- * 校验表单输入
- */
- checkForm(form) {
- let result = true;
- const openNum = form.detail.value.openNum;
- const deviceName = form.detail.value.deviceName;
- if (openNum == null || openNum == "") {
- result = false;
- this.setData({
- openNumError: "请输入设备码"
- })
- } else {
- this.setData({
- openNumError: ""
- })
- }
- if (deviceName == null || deviceName == "") {
- result = false;
- this.setData({
- deviceNameError: "请输入设备名称"
- })
- } else {
- this.setData({
- deviceNameError: ""
- })
- }
- return result;
- }
- })
|