// pages/handover/handover.js //样本交接 const request = require('../../utils/http') import drawQrcode from '../../utils/weapp.qrcode.esm.js' // var app = getApp(); Page({ /** * 页面的初始数据 */ data: { date: '', start: '', end: '', logisticsCodeList: [], //物流单列表 sampleList: [], //样本列表 showDialog: false }, //刷新按钮 refresh() { this.selTranLogistics() }, bindDateChange(e) { this.setData({ date: e.detail.value }) }, //查询物流单列表 selTranLogistics() { var reqData = { startTime: this.data.date, pageNum: 1, pageSize: 100 } request.post(`/batch/selectTranLogistics`, reqData).then(res => { // console.log(JSON.stringify(res)); // this.data.logisticsCodeList = res.data.data if (res.data.data.length == 0) { wx.showToast({ title: '无数据', icon: 'error' }) } else { this.setData({ logisticsCodeList: res.data.data }) } }) }, //查询物流单下的样本列表 selSampleList(e) { var reqData = { 'logisticsNo': e.target.dataset.id } request.post(`/logistics/selectTranLogistics`, reqData).then(res => { console.log(res.data.data); this.setData({ sampleList: res.data.data, // sampleCount: res.data.data.length }) }) //生成二维码 this.drawQrImg(e.target.dataset.id) }, drawQrImg(text) { var _this = this; const query = wx.createSelectorQuery() query.select('#myQrcode') .fields({ node: true, size: true }) .exec((res) => { var canvas = res[0].node // 调用方法drawQrcode生成二维码 drawQrcode({ canvas: canvas, canvasId: 'myQrcode', width: 100, padding: 0, background: '#ffffff', foreground: '#000000', text: text, }) // 获取临时路径 wx.canvasToTempFilePath({ canvasId: 'myQrcode', canvas: canvas, x: 0, y: 0, width: 100, height: 100, destWidth: 100, destHeight: 100, success(res) { console.log('二维码临时路径:', res.tempFilePath) _this.toggleDialog() }, fail(res) { console.error(res) } }) }) }, //控制二维码弹窗 toggleDialog() { this.setData({ showDialog: !this.data.showDialog }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let now = new Date(); //获取时间 let year = now.getFullYear(); //获取当前年 let month = now.getMonth() + 1; //获取当前月份 var tempDate = '' + year + '-' + (Array(2).join(0) + month).slice(-2) + '-' + (Array(2).join(0) + now.getDate()).slice(-2); this.setData({ end: tempDate }) //当前的时间 this.setData({ date: tempDate }) this.selTranLogistics() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })