index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. }),
  28. created () {
  29. const _this = this
  30. // console.log(_this.code, '_this.code')
  31. getLookUpData({
  32. pageNo: 1,
  33. pageSize: 1000,
  34. lookupCode: _this.code
  35. }).then(res => {
  36. if (res.status == 200) {
  37. _this.dataList = res.data.list
  38. }
  39. })
  40. },
  41. methods: {
  42. /**
  43. * 获取当前所有的option 数据
  44. * @returns options data
  45. */
  46. getOptionDatas () {
  47. return _.cloneDeep(this.dataList)
  48. },
  49. // 根据code 获取名称
  50. getNameByCode (code) {
  51. const a = this.dataList.find(item => {
  52. return item.code == code
  53. })
  54. return a ? a.dispName : '-'
  55. },
  56. // 根据名称 获取code
  57. getCodeByName (dispName) {
  58. console.log(this.dataList)
  59. return this.datalist.find(item => item.dispName == dispName)
  60. }
  61. },
  62. render () {
  63. const props = {}
  64. Object.keys(Select.props).forEach(k => {
  65. this[k] && (props[k] = this[k])
  66. return props[k]
  67. })
  68. if (props.placeholder === undefined) {
  69. props.placeholder = this.placeholderText
  70. }
  71. const on = {
  72. change: obj => {
  73. this.$emit('input', obj)
  74. this.$emit('change', obj, _.find(this.dataList, ['code', obj]))
  75. }
  76. }
  77. if (this.showType === 'tabs') {
  78. return (
  79. <a-tabs vModel={props.value} {...{ props, on: on }}>
  80. {
  81. this.dataList.map(item => {
  82. return (<a-tab-pane tab={item.dispName} key={item.code}></a-tab-pane>)
  83. })
  84. }
  85. </a-tabs>
  86. )
  87. }
  88. return (
  89. <Select vModel={props.value} {...{ props, on: on }}>
  90. {
  91. this.dataList.map(item => {
  92. return (<a-select-option value={item.code} key={item.code}>{item['dispName']}</a-select-option>)
  93. })
  94. }
  95. </Select>
  96. )
  97. }
  98. }