productBrand.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { productBrandQuery } from '@/api/productBrand'
  2. const ProductBrand = {
  3. template: `
  4. <a-select
  5. :placeholder="placeholder"
  6. :id="id"
  7. allowClear
  8. :value="defaultVal"
  9. :showSearch="true"
  10. :disabled="disabled"
  11. @change="handleChange"
  12. option-filter-prop="children"
  13. :filter-option="filterOption">
  14. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  15. </a-select>
  16. `,
  17. props: {
  18. value: {
  19. type: String,
  20. defatut: ''
  21. },
  22. id: {
  23. type: String,
  24. default: ''
  25. },
  26. placeholder:{
  27. type: String,
  28. default: '请选择产品品牌'
  29. },
  30. brandType: {
  31. type: String,
  32. default: ''
  33. },
  34. disabled: {
  35. type: Boolean,
  36. default: false
  37. }
  38. },
  39. data() {
  40. return {
  41. defaultVal: this.value,
  42. productBrandList: []
  43. };
  44. },
  45. mounted() {
  46. const a = this.$store.state.app.productBrandAllList
  47. // 有缓存
  48. if(a){
  49. this.setBrandData(a||[])
  50. }else{
  51. this.getProductBrand()
  52. }
  53. },
  54. watch: {
  55. value(newValue, oldValue) {
  56. this.defaultVal = newValue
  57. },
  58. brandType(newValue,oldValue){
  59. this.handleChange(undefined)
  60. const a = this.$store.state.app.productBrandAllList
  61. // 有缓存
  62. if(a){
  63. this.setBrandData(a||[])
  64. }else{
  65. this.getProductBrand()
  66. }
  67. }
  68. },
  69. methods: {
  70. filterOption (input, option) {
  71. return (
  72. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  73. )
  74. },
  75. handleChange(value) {
  76. this.defaultVal = value;
  77. const row = this.productBrandList.find(item => item.brandSn == value)
  78. this.$emit('input', value);
  79. this.$emit('change', value, this.id, row);
  80. },
  81. setBrandData(data){
  82. // brandType: 1 自主品牌 2 代理品牌
  83. if(this.brandType!=''){
  84. this.productBrandList = data.filter(item => item.brandType == this.brandType)
  85. }else{
  86. this.productBrandList = data
  87. }
  88. },
  89. // 产品品牌列表,
  90. getProductBrand () {
  91. productBrandQuery({}).then(res => {
  92. let ret = []
  93. if (res.status == 200) {
  94. ret = res.data
  95. } else {
  96. ret = []
  97. }
  98. // 缓存数据
  99. this.$store.state.app.productBrandAllList = ret
  100. this.setBrandData(ret)
  101. })
  102. },
  103. },
  104. };
  105. export default ProductBrand