v-select.vue 2.7 KB

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