index.js 3.4 KB

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