index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import Select from 'ant-design-vue/es/select'
  2. /**
  3. * loopUp 组件
  4. * params: code loopUp的code 值
  5. * event: change(选中的值, 选中的对象 )
  6. */
  7. export default {
  8. name: 'VSelect',
  9. data () {
  10. return {
  11. dataList: [],
  12. placeholderText: ''
  13. }
  14. },
  15. props: Object.assign({}, Select.props, {
  16. code: {
  17. type: String,
  18. required: true
  19. },
  20. showType: {
  21. type: String,
  22. default: 'select'
  23. },
  24. isEnable: { // 是否只获取已启用的数据
  25. type: Boolean,
  26. default: true
  27. },
  28. notIn: {
  29. type: Array,
  30. default: function () {
  31. return []
  32. }
  33. }
  34. }),
  35. watch: {
  36. notIn (newVal, oldVal) {
  37. this.getDataList()
  38. }
  39. },
  40. created () {
  41. this.getDataList()
  42. },
  43. methods: {
  44. getDataList () {
  45. const _this = this
  46. const allLookup = JSON.parse(sessionStorage.getItem('allLookup'))
  47. const data = allLookup.find(item => item.code == _this.code)
  48. // 判断是否是省仓用户
  49. _this.dataList = _this.$store.state.user.dealerSupplierFlag == '1' ? data.itemList : data.itemList.filter(item => item.dispName != '省级批发价')
  50. // 判断是否不显示指定选项
  51. if (_this.notIn) {
  52. _this.dataList = _this.dataList.filter(item => _this.notIn.indexOf(item.code) < 0)
  53. }
  54. setTimeout(() => {
  55. _this.$emit('loadDataFinish', _this.dataList)
  56. }, 100)
  57. },
  58. // 根据code 获取名称
  59. getNameByCode (code) {
  60. const a = this.dataList.find(item => {
  61. return item.code == code
  62. })
  63. return a ? a.dispName : '-'
  64. },
  65. // 根据名称 获取item
  66. getCodeByName (dispName) {
  67. return this.datalist.find(item => item.dispName == dispName)
  68. }
  69. },
  70. render () {
  71. const props = {}
  72. Object.keys(Select.props).forEach(k => {
  73. this[k] && (props[k] = this[k])
  74. return props[k]
  75. })
  76. if (props.placeholder === undefined) {
  77. props.placeholder = this.placeholderText
  78. }
  79. const on = {
  80. change: obj => {
  81. this.$emit('input', obj)
  82. this.$emit('change', obj, _.find(this.dataList, ['code', obj]))
  83. }
  84. }
  85. const radioOn = {
  86. change: obj => {
  87. this.$emit('input', obj.target.value)
  88. this.$emit('change', obj.target.value, _.find(this.dataList, ['code', obj.target.value]))
  89. }
  90. }
  91. if (this.showType === 'radio') {
  92. return (
  93. <a-radio-group vModel={props.value} {...{ props, on: radioOn }} >
  94. {
  95. this.dataList.map(item => {
  96. return (<a-radio value={item.code} key={item.code}>{item['dispName']}</a-radio>)
  97. })
  98. }
  99. </a-radio-group>
  100. )
  101. }
  102. if (this.showType === 'tabs') {
  103. return (
  104. <a-tabs vModel={props.value} {...{ props, on: on }}>
  105. {
  106. this.dataList.map(item => {
  107. return (<a-tab-pane tab={item.dispName} key={item.code}></a-tab-pane>)
  108. })
  109. }
  110. </a-tabs>
  111. )
  112. }
  113. return (
  114. <Select vModel={props.value} {...{ props, on: on }}>
  115. {
  116. this.dataList.map(item => {
  117. return (<a-select-option value={item.code} id={item.code} key={item.code}>{item['dispName']}</a-select-option>)
  118. })
  119. }
  120. </Select>
  121. )
  122. }
  123. }