plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div>
  3. <el-select v-bind="$attrs" v-on="$listeners" :value="value" style="width: 100%" @change="changeDictData">
  4. <el-option v-for="(item, index) in options"
  5. :key="index" :label="item.dictLabel"
  6. :value="item.dictValue"
  7. :disabled="item.status === 'N' || disabledOptionsValue.includes(item.dictValue)">
  8. <slot :label="item.dictLabel" :value="item.dictValue"></slot>
  9. </el-option>
  10. </el-select>
  11. </div>
  12. </template>
  13. <script>
  14. import {selectDictDataList} from "../../../api/dict";
  15. export default {
  16. name:'dictDataSelect',
  17. model:{
  18. prop:'value',
  19. event:'change'
  20. },
  21. props:{
  22. dictType: {
  23. type: String,
  24. },
  25. dictTypeList:{
  26. type:Array,
  27. default:()=>[],
  28. },
  29. value:{
  30. required: true,
  31. },
  32. useDefaultValue:{
  33. type:Boolean,
  34. default:true,
  35. },
  36. useSite:{
  37. type:Boolean,
  38. default:true,
  39. },
  40. disabledOptionsValue:{
  41. type:Array,
  42. default:()=>[],
  43. },
  44. site:{
  45. type:String,
  46. default:undefined,
  47. }
  48. },
  49. data () {
  50. return {
  51. options: []
  52. }
  53. },
  54. created () {
  55. this.initOption()
  56. },
  57. methods: {
  58. dictDefaultValue(){
  59. // 当value值不存在 并且查询的下拉框存在默认值列,将value赋值为默认
  60. if (!this.value && this.options.length > 0){
  61. let find = this.options.find(item=>item.isDefault === 'Y');
  62. if (find && find.status === 'Y'){
  63. this.$emit("change",find.dictValue);
  64. }
  65. }
  66. },
  67. //初始化options
  68. async initOption () {
  69. // 组合查询条件
  70. let params = {
  71. site:this.useSite?this.$store.state.user.site:"*",
  72. dictType:this.dictType,
  73. dictTypeList: this.dictTypeList
  74. }
  75. if (this.site){
  76. params.site = this.site
  77. }
  78. try {
  79. // 等待返回值
  80. let {data} = await selectDictDataList(params);
  81. // 参数赋值
  82. if (data && data.code === 0){
  83. this.options = data.rows;
  84. if (this.options.length === 0){
  85. this.$emit("change",'')
  86. }
  87. }
  88. if (this.useDefaultValue){
  89. this.dictDefaultValue();
  90. }
  91. }catch (e) {
  92. return Promise.reject(e)
  93. }
  94. },
  95. // el-select @change事件,修改父组件值
  96. changeDictData(val){
  97. this.$emit('change',val)
  98. }
  99. }
  100. }
  101. </script>