allocateType.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { allocateTypeTreeList } from '@/api/allocateType'
  2. const AllocateType = {
  3. template: `
  4. <a-cascader
  5. :value="defaultVal"
  6. 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. level:{
  35. type: [String,Number],
  36. default: ''
  37. }
  38. },
  39. data() {
  40. return {
  41. defaultVal: this.value,
  42. list: []
  43. };
  44. },
  45. mounted() {
  46. this.getProductBrand()
  47. },
  48. watch: {
  49. value(newValue, oldValue) {
  50. this.defaultVal = newValue
  51. }
  52. },
  53. methods: {
  54. filterOption (input, option) {
  55. return (
  56. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  57. )
  58. },
  59. handleChange(value,opts) {
  60. this.defaultVal = value;
  61. this.$emit('input', value);
  62. this.$emit('change', value,opts);
  63. },
  64. // 调拨类型
  65. getProductBrand () {
  66. allocateTypeTreeList({}).then(res => {
  67. if (res.status == 200) {
  68. if(this.level){
  69. this.list = this.getBylevel(res.data)
  70. }else{
  71. this.list = res.data
  72. }
  73. } else {
  74. this.list = []
  75. }
  76. })
  77. },
  78. getBylevel(data){
  79. const ret = []
  80. // 显示一级分类
  81. if(this.level == 1){
  82. data.map(item => {
  83. if(item.sonList){
  84. delete item.sonList
  85. }
  86. })
  87. }
  88. // 显示二级分类
  89. if(this.level == 2){
  90. data.map(item => {
  91. if(item.sonList){
  92. item.sonList.map(cd => {
  93. if(cd.sonList){
  94. delete cd.sonList
  95. }
  96. })
  97. }
  98. })
  99. }
  100. return data
  101. }
  102. },
  103. };
  104. export default AllocateType