allocateType.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { allocateTypeTreeList } from '@/api/allocateType'
  2. const AllocateType = {
  3. template: `
  4. <a-cascader
  5. :value="defaultVal"
  6. :allowClear="allowClear"
  7. :change-on-select="changeOnSelect"
  8. @change="handleChange"
  9. :options="list"
  10. expand-trigger="hover"
  11. :placeholder="placeholder"
  12. :id="id"
  13. :fieldNames="{ label: 'name', value: 'allocateTypeSn', children: 'sonList' }"/>
  14. `,
  15. props: {
  16. value: {
  17. type: Array,
  18. defatut: function(){
  19. return []
  20. }
  21. },
  22. id: {
  23. type: String,
  24. default: ''
  25. },
  26. placeholder:{
  27. type: String,
  28. default: '请选择'
  29. },
  30. changeOnSelect:{
  31. type: Boolean,
  32. default: false
  33. },
  34. allowClear:{
  35. type: Boolean,
  36. default: true
  37. },
  38. level:{
  39. type: [String,Number],
  40. default: ''
  41. }
  42. },
  43. data() {
  44. return {
  45. defaultVal: this.value,
  46. list: []
  47. };
  48. },
  49. mounted() {
  50. this.getProductBrand()
  51. },
  52. watch: {
  53. value(newValue, oldValue) {
  54. this.defaultVal = newValue
  55. }
  56. },
  57. methods: {
  58. filterOption (input, option) {
  59. return (
  60. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  61. )
  62. },
  63. handleChange(value,opts) {
  64. this.defaultVal = value;
  65. this.$emit('input', value);
  66. this.$emit('change', value,opts);
  67. },
  68. // 调拨类型
  69. getProductBrand () {
  70. allocateTypeTreeList({}).then(res => {
  71. if (res.status == 200) {
  72. if(this.level){
  73. this.list = this.getBylevel(res.data)
  74. }else{
  75. this.list = res.data
  76. }
  77. } else {
  78. this.list = []
  79. }
  80. })
  81. },
  82. getBylevel(data){
  83. const ret = []
  84. // 显示一级分类
  85. if(this.level == 1){
  86. data.map(item => {
  87. if(item.sonList){
  88. delete item.sonList
  89. }
  90. })
  91. }
  92. // 显示二级分类
  93. if(this.level == 2){
  94. data.map(item => {
  95. if(item.sonList){
  96. item.sonList.map(cd => {
  97. if(cd.sonList){
  98. delete cd.sonList
  99. }
  100. })
  101. }
  102. })
  103. }
  104. return data
  105. }
  106. },
  107. };
  108. export default AllocateType