马宇豪
2025-05-14 c533e456515a9af7fc4bca098f7cf48b9a660e21
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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 {
      // 云开发请求
      if(res.result.indexOf('SJ') >0){
        cloudApi.queryPost('hazmatList',{code: t.data.searchContent}).then(res=>{
          if(res.data.length>0){
              const hazmatId = cloudApi.changeKey(res.data[0]).id
              wx.cloud.callFunction({
                name: 'getHazmatFlow',
                data: {
                  hazmatId: hazmatId
                }
              }).then(res=>{
                if(res.result && Array.isArray(res.result.list) && res.result.list.length>0){
                  t.setData({
                    dataList: cloudApi.changeKey(res.result.list)
                  })
                }
              })
          }else {
            wx.showToast({
              title: '该二维码查询不到相关信息',
              icon: 'error',
              duration: 2000
            });
          }
        })
      }else{
        cloudApi.queryPost('productList',{code: t.data.searchContent}).then(res=>{
          if(res.data.length>0){
              const productId = cloudApi.changeKey(res.data[0]).id
              wx.cloud.callFunction({
                name: 'getProductFlow',
                data: {
                  productId: productId
                }
              }).then(res=>{
                if(res.result && Array.isArray(res.result.list) && res.result.list.length>0){
                  t.setData({
                    dataList: cloudApi.changeKey(res.result.list)
                  })
                }
              })
          }else {
            wx.showToast({
              title: '该二维码查询不到相关信息',
              icon: 'error',
              duration: 2000
            });
          }
        })
      }
      // 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))
    });
  }
});