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.

94 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
3 years ago
​
​
​
​
​
​
3 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. },
  45. data () {
  46. return {
  47. options: []
  48. }
  49. },
  50. created () {
  51. this.initOption()
  52. },
  53. methods: {
  54. dictDefaultValue(){
  55. // 当value值不存在 并且查询的下拉框存在默认值列,将value赋值为默认
  56. if (!this.value && this.options.length > 0){
  57. let find = this.options.find(item=>item.isDefault === 'Y');
  58. if (find && find.status === 'Y'){
  59. this.$emit("change",find.dictValue);
  60. }
  61. }
  62. },
  63. //初始化options
  64. async initOption () {
  65. // 组合查询条件
  66. let params = {
  67. site:this.useSite?this.$store.state.user.site:"*",
  68. dictType:this.dictType,
  69. dictTypeList: this.dictTypeList
  70. }
  71. try {
  72. // 等待返回值
  73. let {data} = await selectDictDataList(params);
  74. // 参数赋值
  75. if (data && data.code === 0){
  76. this.options = data.rows;
  77. if (this.options.length === 0){
  78. this.$emit("change",'')
  79. }
  80. }
  81. if (this.useDefaultValue){
  82. this.dictDefaultValue();
  83. }
  84. }catch (e) {
  85. return Promise.reject(e)
  86. }
  87. },
  88. // el-select @change事件,修改父组件值
  89. changeDictData(val){
  90. this.$emit('change',val)
  91. }
  92. }
  93. }
  94. </script>