index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Promise.all([listLookUp({ code: '' }), getLookUpData({
  32. pageNo: 1,
  33. pageSize: 1000,
  34. lookupCode: _this.code
  35. })]).then(results => {
  36. const _all = results[0]
  37. const _data = results[1]
  38. if (_all.status + '' === '200' && _data.status + '' === '200') {
  39. _this.dataList = _data.data.list
  40. const a = _.find(_all.data, ['code', _this.code])
  41. // console.log(a)
  42. _this.placeholderText = '请选择' + (a != undefined ? a.name : '')
  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('change', obj, _.find(this.dataList, ['code', obj]))
  79. this.$emit('input', 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. }