king
2023-08-23 547e5fe219ee7bee309ecd67db74bc8df66b5433
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
import React, {Component} from 'react'
import { Select, notification } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import { queryPrintSql } from '@/utils/option.js'
 
class MKSelect extends Component {
  constructor(props) {
    super(props)
    
    this.state = {
      options: window.GLOB.printTemps || []
    }
  }
 
  componentDidMount () {
    if (!window.GLOB.printTemps) {
      this.getPrintTemp()
    }
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  getPrintTemp = () => {
    let param = {
      func: 'sPC_Get_SelectedList',
      LText: Utils.formatOptions(queryPrintSql),
      obj_name: 'data',
      arr_field: 'PN,ID,Images'
    }
 
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
 
    Api.getCloudConfig(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      }
 
      let temps = (res.data || []).map(temp => {
        return {
          value: temp.ID,
          text: temp.PN
        }
      })
      window.GLOB.printTemps = temps
 
      this.setState({options: temps})
    })
  }
 
  selectChange = (val) => {
    this.props.onChange(val)
  }
 
  render() {
    const { value } = this.props
    const { options } = this.state
 
    return (
      <Select
        showSearch
        allowClear
        value={value}
        filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
        onSelect={this.selectChange}
        onChange={(val) => val === undefined && this.selectChange('')}
      >
        {options.map(option =>
          <Select.Option key={option.value} value={option.value}>{option.text}</Select.Option>
        )}
      </Select>
    )
  }
}
 
export default MKSelect