祖安之光
2025-08-07 41193d186d157937ba052e73dd04c12018e9ecab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const app = getApp();
const api = require('../../../utils/api');
const cloudApi = require('../../../utils/cloudApi')
Page({
  data: {
    page: 'pages/tabBar/current/current',
    statusBarHeight: '',
    searchContent: '',
    dataList: []
  },
 
  onLoad() {
    this.setData({
      statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']
    });
    wx.hideTabBar();
  },
 
  onShow() {
    // 可以在这里添加页面显示时的逻辑
  },
 
  onSearchInput(e) {
    this.setData({
      searchContent: e.detail.value
    });
  },
 
  scanCode() {
    const t = this;
    t.setData({
      dataList: [],
      searchContent: ''
    });
    
    wx.scanCode({
      autoZoom: false,
      scanType: ['qrCode'],
      success: function (res) {
        if(res && res.result) {
          if(res.result.indexOf('SJ') == -1 && res.result.indexOf('CP') == -1) {
            wx.showToast({
              title: '没有识别到正确的编码,请重新扫码',
              icon: 'error',
              duration: 2000
            });
            return;
          }
          t.setData({
            searchContent: res.result
          });
          t.getList()
          // api请求
          // api.getHazmatFlowByCode({code: res.result}).then(re => {
          //   if(re.code == 200) {
          //     t.setData({
          //       dataList: re.data ? re.data : []
          //     });
          //   } else {
          //     wx.showToast({
          //       title: re.message,
          //       icon: 'error',
          //       duration: 2000
          //     });
          //   }
          // });
        } else {
          wx.showToast({
            title: '该二维码已失效或不包含条码信息',
            icon: 'error',
            duration: 2000
          });
        }
      }
    });
  },
 
  getList() {
    const t = this;
    if(t.data.searchContent == '') {
      wx.showToast({
        title: '请输入二维码编号',
        icon: 'none'
      });
    } else {
      // api请求
      api.getHazmatFlowByCode({code: t.data.searchContent}).then(re => {
        if(re.code == 200) {
          t.setData({
            dataList: re.data ? re.data : []
          });
        } else {
          wx.showToast({
            title: re.message,
            icon: 'none'
          });
        }
      });
    }
  },
 
  toStudy(e) {
    const item = e.currentTarget.dataset.item;
    wx.setStorageSync("prevPage", '/pages/tabBar/current/current');
    wx.navigateTo({
      url: `/pages/tabBar/current/detail?bank=` + encodeURIComponent(JSON.stringify(item))
    });
  }
});