index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. _this.$emit("loadDataFinish",_this.dataList)
  45. })
  46. },
  47. methods: {
  48. /**
  49. * 获取当前所有的option 数据
  50. * @returns options data
  51. */
  52. getOptionDatas () {
  53. return _.cloneDeep(this.dataList)
  54. },
  55. // 根据code 获取名称
  56. getNameByCode (code) {
  57. const a = this.dataList.find(item => {
  58. return item.code == code
  59. })
  60. return a ? a.dispName : '-'
  61. },
  62. // 根据名称 获取code
  63. getCodeByName (dispName) {
  64. console.log(this.dataList)
  65. return this.datalist.find(item => item.dispName == dispName)
  66. }
  67. },
  68. render () {
  69. const props = {}
  70. Object.keys(Select.props).forEach(k => {
  71. this[k] && (props[k] = this[k])
  72. return props[k]
  73. })
  74. if (props.placeholder === undefined) {
  75. props.placeholder = this.placeholderText
  76. }
  77. const on = {
  78. change: obj => {
  79. this.$emit('input', obj)
  80. this.$emit('change', obj, _.find(this.dataList, ['code', obj]))
  81. }
  82. }
  83. const radioOn = {
  84. change: obj => {
  85. this.$emit('input', obj.target.value)
  86. this.$emit('change', obj.target.value, _.find(this.dataList, ['code', obj.target.value]))
  87. }
  88. }
  89. if(this.showType === 'radio'){
  90. return (
  91. <a-radio-group vModel={props.value} {...{ props, on: radioOn }} >,
  92. {
  93. this.dataList.map(item => {
  94. return (<a-radio value={item.code} key={item.code}>{item['dispName']}</a-radio>)
  95. })
  96. }
  97. </a-radio-group>
  98. )
  99. }
  100. if (this.showType === 'tabs') {
  101. return (
  102. <a-tabs vModel={props.value} {...{ props, on: on }}>
  103. {
  104. this.dataList.map(item => {
  105. return (<a-tab-pane tab={item.dispName} key={item.code}></a-tab-pane>)
  106. })
  107. }
  108. </a-tabs>
  109. )
  110. }
  111. return (
  112. <Select vModel={props.value} {...{ props, on: on }}>
  113. {
  114. this.dataList.map(item => {
  115. return (<a-select-option value={item.code} key={item.code}>{item['dispName']}</a-select-option>)
  116. })
  117. }
  118. </Select>
  119. )
  120. }
  121. }