index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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: true
  30. },
  31. notIn: {
  32. type: Array,
  33. default: function(){
  34. return []
  35. }
  36. }
  37. }),
  38. created () {
  39. const _this = this
  40. // console.log(_this.code, '_this.code')
  41. getLookUpData({
  42. pageNo: 1,
  43. pageSize: 1000,
  44. lookupCode: _this.code,
  45. isEnable: _this.isEnable ? 1 : undefined
  46. }).then(res => {
  47. if (res.status == 200) {
  48. _this.dataList = res.data.list.filter(item => _this.notIn.indexOf(item.code)<0)
  49. }
  50. })
  51. },
  52. methods: {
  53. /**
  54. * 获取当前所有的option 数据
  55. * @returns options data
  56. */
  57. getOptionDatas () {
  58. return _.cloneDeep(this.dataList)
  59. },
  60. // 根据code 获取名称
  61. getNameByCode (code) {
  62. const a = this.dataList.find(item => {
  63. return item.code == code
  64. })
  65. return a ? a.dispName : '-'
  66. },
  67. // 根据名称 获取code
  68. getCodeByName (dispName) {
  69. console.log(this.dataList)
  70. return this.datalist.find(item => item.dispName == dispName)
  71. }
  72. },
  73. render () {
  74. const props = {}
  75. Object.keys(Select.props).forEach(k => {
  76. this[k] && (props[k] = this[k])
  77. return props[k]
  78. })
  79. if (props.placeholder === undefined) {
  80. props.placeholder = this.placeholderText
  81. }
  82. const on = {
  83. change: obj => {
  84. this.$emit('input', obj)
  85. this.$emit('change', obj, _.find(this.dataList, ['code', obj]))
  86. }
  87. }
  88. const radioOn = {
  89. change: obj => {
  90. this.$emit('input', obj.target.value)
  91. this.$emit('change', obj.target.value, _.find(this.dataList, ['code', obj.target.value]))
  92. }
  93. }
  94. if(this.showType === 'radio'){
  95. return (
  96. <a-radio-group vModel={props.value} {...{ props, on: radioOn }} >
  97. {
  98. this.dataList.map(item => {
  99. return (<a-radio value={item.code} key={item.code}>{item['dispName']}</a-radio>)
  100. })
  101. }
  102. </a-radio-group>
  103. )
  104. }
  105. if (this.showType === 'tabs') {
  106. return (
  107. <a-tabs vModel={props.value} {...{ props, on: on }}>
  108. {
  109. this.dataList.map(item => {
  110. return (<a-tab-pane tab={item.dispName} key={item.code}></a-tab-pane>)
  111. })
  112. }
  113. </a-tabs>
  114. )
  115. }
  116. return (
  117. <Select vModel={props.value} {...{ props, on: on }}>
  118. {
  119. this.dataList.map(item => {
  120. return (<a-select-option value={item.code} key={item.code}>{item['dispName']}</a-select-option>)
  121. })
  122. }
  123. </Select>
  124. )
  125. }
  126. }