v-select.vue 2.9 KB

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