// render/goods/add.js Page({ /** * 页面的初始数据 */ data: { userId: 0, isClose: true, deviceName: '', //物品名称 code: '', //条码 buckutName: '', //仓库名 gps: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; wx.getStorage({ key: 'userInfo', success: function (res) { that.setData({ userId: res.data.uid }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, // 添加事件 addEvt: function (e) { var data = e.detail.value; var _wpmc = data.wp; var _tiaoma = data.tm; var _ckmc = data.ck; var _userId = this.data.userId; var _api = 'https://demo.markdream.com/tech/16wechat/phpapi/add.php'; wx.request({ url: _api, //仅为示例,并非真实的接口地址 data: { tiaoma: _tiaoma, devicename: _wpmc, adduserid: _userId, depotname: _ckmc }, header: { 'content-type': 'application/json' // 默认值 }, success: function (res) { if (res.data.code == 0) { //添加成功 wx.showToast({ title: '添加成功', icon: 'success', duration: 2000 }) } else { wx.showToast({ title: '添加失败', icon: 'none', duration: 2000 }) } } }) console.log(_wpmc); }, //扫一扫 openScaner: function () { wx.scanCode({ success: (res) => { this.setData({ scanCode: res.result }) } }) }, // 监听物品名称输入的内容 wpEvt: function (e) { var _wpmc = e.detail.value; this.setData({ deviceName: _wpmc }) this.checkIsClose(); }, // 监听条码 tmEvt: function (e) { var _tm = e.detail.value; this.setData({ code: _tm }) this.checkIsClose(); }, // 监听仓库 ckEvt: function (e) { var _ck = e.detail.value; this.setData({ buckutName: _ck }) this.checkIsClose(); }, // 监听GPS gpsEvt: function (e) { this.setData({ gps: e.detail.value }) this.checkIsClose(); }, // 专门用来判断是否允许点击添加按钮 checkIsClose: function () { var _deviceName = this.data.deviceName; var _code = this.data.code; var _buckutName = this.data.buckutName; var _gps = this.data.gps; if (_deviceName != '' && _code != '' && _buckutName != '' && _gps != '') { this.setData({ isClose: false }) } else { this.setData({ isClose: true }) } } })