// pages/create/create.js const App = getApp(); Page({ /** * 页面的初始数据 */ data: { aState:false, wState:false, qState:false, naState:false, noState:false, alcode:"", wxcode:"", qqcode:"", name:"", node:"", openid:"" }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ navH: App.globalData.navHeight }) this.data.openid=wx.getStorageSync("openId"); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, getAlCode: function() { let that = this; wx.scanCode({ success:function(res){ that.data.alcode=res.result; that.setData({ aState:true }) wx.showToast({ title: "扫描成功", duration: 1000, mask: true, icon: "success" }) }, fail:function(err){ console.error(err); wx.showModal({ title: "警告", content: "扫描失败", showCancel: false, confirmText: "继续" }) } }); }, getWxCode: function() { let that = this; wx.scanCode({ success: function (res) { that.data.wxcode = res.result; that.setData({ wState: true }) wx.showToast({ title: "扫描成功", duration: 100, mask: true, icon: "success" }) }, fail: function (err) { console.error(err); wx.showModal({ title: "警告", content: "扫描失败", showCancel: false, confirmText: "继续" }) } }); }, getQqCode: function() { let that = this; wx.scanCode({ success: function (res) { that.data.qqcode = res.result; that.setData({ qState: true }) wx.showToast({ title: "扫描成功", duration: 100, mask: true, icon: "success" }) }, fail: function (err) { console.error(err); wx.showModal({ title: "警告", content: "扫描失败", showCancel: false, confirmText: "继续" }) } }); }, inputName: function (e) { this.setData({ name:e.detail.value }) if(e.detail.value){ this.setData({ naState: true }) }else{ this.setData({ naState: false }) } console.log('填写姓名为', this.data.name); }, inputNode: function (e) { this.data.node = e.detail.value; if (e.detail.value) { this.setData({ noState: true }) } else { this.setData({ noState: false }) } console.log('填写备注为', this.data.node); }, confirm:function(){ var that =this; wx.showModal({ title: '提示', content: '提交后不可更改,要不要再看看?', cancelText:'再看看', confirmText:'确认提交', success(res) { if (res.confirm) { that.create(); } else if (res.cancel) { console.log('用户点击取消') } } }) }, create: function() { let ast=this.data.aState; let ws=this.data.wState; let qs=this.data.qState; let as=this.data.naState; var that=this; if(((ast&&ws)||(ast&&qs)||(ws&&qs))&&as){//至少有两个二维码且填写了姓名 wx.request({ url: 'https://powerrain.cn/qrcode/api/add.php', data: { alpay:that.data.alcode, wxpay:that.data.wxcode, qqpay:encodeURIComponent(that.data.qqcode), name:that.data.name, node:that.data.node, open:that.data.openid }, success: function (res) { //如果成功就会返回id if (res.data["LAST_INSERT_ID()"]) { let createInfo = { //将id和名字存起来下一个界面生成二维码用。 'id': res.data["LAST_INSERT_ID()"], 'name':that.data.name, 'aState':that.data.aState, 'wState':that.data.wState, 'qState':that.data.qState, } console.log(createInfo); wx.setStorageSync('createInfo', createInfo); //更新已经制作完成的二维码 wx.request({ url: 'https://powerrain.cn/qrcode/api/wxselect.php', data: { openId: that.data.openid }, success: function (infoRes) { //如果该id未合并过二维码,此处为[](空数组) console.log(infoRes); if (infoRes.data.length != 0) { wx.setStorageSync('qrinfo', infoRes.data); //将已经存在的二维码存放起来,然后下一个界面做成卡片。 wx.redirectTo({ url: '../show/show' }) } else { wx.showModal({ title: "警告", content: "获取最新列表失败", showCancel: false, confirmText: "重试" }) } } }) } else { wx.showModal({ title: "警告", content: "生成失败", showCancel: false, confirmText: "重试" }) } } }) }else{ wx.showToast({ title: '请检查输入内容', icon: 'none', duration: 2000, mask:true }) } }, })