index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import Select from 'ant-design-vue/es/select'
  2. import _ from 'lodash'
  3. import { getLookUpData, listLookUp } from '@/api/data'
  4. /**
  5. * loopUp 组件
  6. * params: code loopUp的code 值
  7. * event: change(选中的值, 选中的对象 )
  8. * ref: getOptionDatas 获取所有查询的
  9. */
  10. export default {
  11. name: 'VSelect',
  12. data () {
  13. return {
  14. dataList: [],
  15. placeholderText: ''
  16. }
  17. },
  18. props: Object.assign({}, Select.props, {
  19. code: {
  20. type: String,
  21. required: true
  22. },
  23. showType: {
  24. type: String,
  25. default: 'select'
  26. },
  27. isEnable: { // 是否只获取已启用的数据
  28. type: Boolean,
  29. default: false
  30. }
  31. }),
  32. created () {
  33. const _this = this
  34. // console.log(_this.code, '_this.code')
  35. getLookUpData({
  36. pageNo: 1,
  37. pageSize: 1000,
  38. lookupCode: _this.code,
  39. isEnable: _this.isEnable ? 1 : undefined
  40. }).then(res => {
  41. if (res.status == 200) {
  42. _this.dataList = res.data.list
  43. }
  44. })
  45. },
  46. methods: {
  47. /**
  48. * 获取当前所有的option 数据
  49. * @returns options data
  50. */
  51. getOptionDatas () {
  52. return _.cloneDeep(this.dataList)
  53. },
  54. // 根据code 获取名称
  55. getNameByCode (code) {
  56. const a = this.dataList.find(item => {
  57. return item.code == code
  58. })
  59. return a ? a.dispName : '-'
  60. },
  61. // 根据名称 获取code
  62. getCodeByName (dispName) {
  63. console.log(this.dataList)
  64. return this.datalist.find(item => item.dispName == dispName)
  65. }
  66. },
  67. render () {
  68. const props = {}
  69. Object.keys(Select.props).forEach(k => {
  70. this[k] && (props[k] = this[k])
  71. return props[k]
  72. })
  73. if (props.placeholder === undefined) {
  74. props.placeholder = this.placeholderText
  75. }
  76. const on = {
  77. change: obj => {
  78. this.$emit('input', obj)
  79. this.$emit('change', obj, _.find(this.dataList, ['code', obj]))
  80. }
  81. }
  82. if (this.showType === 'tabs') {
  83. return (
  84. <a-tabs vModel={props.value} {...{ props, on: on }}>
  85. {
  86. this.dataList.map(item => {
  87. return (<a-tab-pane tab={item.dispName} key={item.code}></a-tab-pane>)
  88. })
  89. }
  90. </a-tabs>
  91. )
  92. }
  93. return (
  94. <Select vModel={props.value} {...{ props, on: on }}>
  95. {
  96. this.dataList.map(item => {
  97. return (<a-select-option value={item.code} key={item.code}>{item['dispName']}</a-select-option>)
  98. })
  99. }
  100. </Select>
  101. )
  102. }
  103. }