tableSelect.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <a-select
  3. @change="changeSelected"
  4. :value="val===''?undefined:val"
  5. @blur="$emit('blur')"
  6. @focus="$emit('focus')"
  7. >
  8. <a-select-option
  9. v-for="option in options"
  10. :key="`${keystr}-${option.key}`"
  11. :placeholder="placeholder"
  12. :disabled="!!disableds.find(val=>val===option.key)"
  13. :class="{'bg-blue-300':option.value===val}"
  14. >
  15. {{option.text}}
  16. </a-select-option>
  17. </a-select>
  18. </template>
  19. <script>
  20. export default {
  21. name: "tableSelect",
  22. props: {
  23. options:{
  24. default:[]
  25. },
  26. value: {
  27. default: ''
  28. },
  29. keystr: {
  30. default: 'default-key'
  31. },
  32. placeholder:{
  33. default: ''
  34. },
  35. disableds:{
  36. default: function (){return []}
  37. }
  38. },
  39. beforeMount() {
  40. if(this.value){
  41. this.val = this.keystr+'-'+this.value;
  42. }else{
  43. this.val = null;
  44. }
  45. },
  46. watch:{
  47. value(newVal){
  48. // console.log(newVal)
  49. // console.log('11111111')
  50. if(!newVal){
  51. this.val = newVal;
  52. }else{
  53. this.val = this.keystr+'-'+newVal;
  54. }
  55. }
  56. },
  57. data(){
  58. return {
  59. val:null,
  60. }
  61. },
  62. methods: {
  63. changeSelected(str){
  64. this.val = str;
  65. str = str.replace(this.keystr+'-','');
  66. let rawData = this.options.find((item)=>item.key === str);
  67. console.log(str)
  68. console.log(rawData)
  69. this.$emit('input',str);
  70. this.$emit('change',str);
  71. this.$emit('raw',rawData);
  72. }
  73. }
  74. }
  75. </script>
  76. <style scoped>
  77. </style>