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, 'x'),
|
obj_name: 'data',
|
arr_field: 'PN,ID,Images',
|
exec_type: 'x'
|
}
|
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt('', 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}
|
dropdownMatchSelectWidth={false}
|
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
|