v-select.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <picker @change="toChange" :value="index" :range="datalist" range-key="dispName">
  3. <view style="display: flex;align-items: center;">
  4. <u-input class="form-input" type="select" style="width: 100%;" :clearable="clearable" @clear="clearInput" :input-align="inputAlign" v-model="selected" :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. clearable:{
  36. type: [Boolean, String],
  37. default: false
  38. },
  39. placeholder: {
  40. type: String,
  41. default: ''
  42. },
  43. size: [String],
  44. inputAlign:{
  45. type: String,
  46. default: 'left'
  47. }
  48. },
  49. computed: {
  50. getVal () {
  51. return this.value
  52. },
  53. getPlaceholderText () {
  54. let _this = this
  55. console.log(_this.lookUp,'_this.lookUp')
  56. for (let i = 0; i < _this.lookUp.length; i++) {
  57. if (_this.lookUp[i].code == _this.code) {
  58. if (this.placeholder === '') _this.placeholderText = _this.lookUp[i].name
  59. break
  60. }
  61. }
  62. return _this.placeholderText
  63. }
  64. },
  65. created () {
  66. if (this.code) {
  67. if (this.placeholder) {
  68. this.placeholderText = this.placeholder
  69. }
  70. getLookUpDatas({
  71. lookupCode: this.code,pageNo:1,pageSize:1000
  72. }).then(result => {
  73. console.log(result, 'result')
  74. if (result && result.status + '' === '200') {
  75. let isDealerSupplierFlag = this.$store.state.vuex_userData.extInfo.dealerSupplierFlag //0 非省仓客户 1省仓客户
  76. if(isDealerSupplierFlag == 1){
  77. this.datalist = result.data.list
  78. }else{
  79. let list = result.data.list
  80. list = list.filter(item => item.dispName != '省级批发价')
  81. this.datalist = list
  82. }
  83. }
  84. })
  85. } else {
  86. // console.log('请确认传递类型')
  87. }
  88. // 获取所有数据字典
  89. this.lookUp = this.$store.state.vuex_allLookUp
  90. },
  91. methods: {
  92. getDataList (){
  93. return this.datalist
  94. },
  95. getOptionName (val) {
  96. return this.datalist.find((item) => {
  97. return item.code == val
  98. })
  99. },
  100. getCodeByName (dispName) {
  101. return this.datalist.find((item) => {
  102. return item.dispName == dispName
  103. })
  104. },
  105. resetVal(){
  106. this.selected = ''
  107. this.index = 0
  108. },
  109. // 赋值
  110. setVal(code){
  111. let index = this.datalist.findIndex(item=>{
  112. return item.code == code
  113. })
  114. console.log(this.datalist,code,index)
  115. this.index = index
  116. this.selected = this.datalist[index].dispName
  117. },
  118. toChange (e) {
  119. this.index = e.target.value
  120. this.selected = this.datalist[this.index].dispName
  121. this.$emit('itemChange', this.datalist[this.index].code)
  122. },
  123. clearInput(){
  124. this.$emit('clear','')
  125. }
  126. }
  127. }
  128. </script>
  129. <style scoped>
  130. </style>