v-select.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <picker @change="toChange" :value="index" :range="datalist" range-key="dispName">
  3. <view style="display: flex;align-items: center;">
  4. <input class="form-input" :disabled="disabled" style="width: 100%;" v-model="selected" placeholder-style="color:#C0C4CC" :placeholder="getPlaceholderText" />
  5. </view>
  6. </picker>
  7. </template>
  8. <script>
  9. import { getLookUpDatas, listLookUp } from '@/api/data'
  10. export default {
  11. name: 'v-select',
  12. data () {
  13. return {
  14. selected: '',
  15. datalist: [],
  16. placeholderText: '请选择',
  17. lookUp: [],
  18. index: 0
  19. }
  20. },
  21. props: {
  22. disabled: {
  23. type: [Boolean, String],
  24. default: false
  25. },
  26. multiple: {
  27. type: [Boolean, String],
  28. default: false
  29. },
  30. value: [String, Number, Array],
  31. code: {
  32. type: String,
  33. required: true
  34. },
  35. placeholder: {
  36. type: String,
  37. default: ''
  38. },
  39. size: [String]
  40. },
  41. computed: {
  42. getVal () {
  43. return this.value
  44. },
  45. getPlaceholderText () {
  46. let _this = this
  47. console.log(_this.lookUp,'_this.lookUp')
  48. for (let i = 0; i < _this.lookUp.length; i++) {
  49. if (_this.lookUp[i].code == _this.code) {
  50. if (this.placeholder === '') _this.placeholderText = _this.lookUp[i].name
  51. break
  52. }
  53. }
  54. return _this.placeholderText
  55. }
  56. },
  57. created () {
  58. if (this.code) {
  59. if (this.placeholder) {
  60. this.placeholderText = this.placeholder
  61. }
  62. getLookUpDatas({
  63. lookupCode: this.code,pageNo:1,pageSize:1000
  64. }).then(result => {
  65. console.log(result, 'result')
  66. if (result && result.status + '' === '200') {
  67. this.datalist = result.data.list
  68. }
  69. })
  70. } else {
  71. // console.log('请确认传递类型')
  72. }
  73. // 获取所有数据字典
  74. this.lookUp = this.$store.state.vuex_allLookUp
  75. },
  76. methods: {
  77. getDataList (){
  78. return this.datalist
  79. },
  80. getOptionName (val) {
  81. return this.datalist.find((item) => {
  82. return item.code == val
  83. })
  84. },
  85. getCodeByName (dispName) {
  86. return this.datalist.find((item) => {
  87. return item.dispName == dispName
  88. })
  89. },
  90. resetVal(){
  91. this.selected = ''
  92. this.index = 0
  93. },
  94. // 赋值
  95. setVal(code){
  96. let index = this.datalist.findIndex(item=>{
  97. return item.code == code
  98. })
  99. console.log(this.datalist,code,index)
  100. this.index = index
  101. this.selected = this.datalist[index].dispName
  102. },
  103. toChange (e) {
  104. this.index = e.target.value
  105. this.selected = this.datalist[this.index].dispName
  106. this.$emit('itemChange', this.datalist[this.index].code)
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped>
  112. </style>