attribute.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div>
  3. <Select
  4. v-if="!value.id"
  5. :value="value[data.keyword]"
  6. :placeholder="data.props.placeholder"
  7. :filterable="data.props.filterable || false"
  8. :clearable="data.props.clearable || false"
  9. :multiple="data.props.multiple || false"
  10. :not-found-text="option[data.keyword].loading || '无匹配数据'"
  11. transfer
  12. @on-change="onChange"
  13. @on-open-change="onOpenChange">
  14. <Option
  15. v-for="(item, index) in option[data.keyword].list"
  16. :key="index"
  17. :value="item.value">{{item.label}}</Option>
  18. </Select>
  19. <error :text="error[data.keyword]" />
  20. </div>
  21. </template>
  22. <script>
  23. import allActions from '@/actions'
  24. export default {
  25. props: ['data', 'value', 'option', 'error'],
  26. data () {
  27. return {
  28. attribute_category_id: '',
  29. attribute_item: [],
  30. }
  31. },
  32. methods: {
  33. onChange (e) {
  34. this.getAttributeList(e)
  35. },
  36. onOpenChange (open) {
  37. if (!open) return
  38. const currentOption = this.option[this.data.keyword]
  39. this.$hub.$emit(this.data.hub, {
  40. type: 'option',
  41. payload: {
  42. type: currentOption.type || 'sync',
  43. keyword: currentOption.keyword || this.data.keyword,
  44. },
  45. })
  46. },
  47. async getAttributeList (v) {
  48. const res = await allActions.getAttributesDetail({ attribute_category_id: v })
  49. const patternData = []
  50. const parameterData = []
  51. res.forEach(i => {
  52. if (!i.attribute_type) {
  53. i.list = i.input_list.split(',')
  54. i.selected = []
  55. patternData.push(i)
  56. } else {
  57. i.list = i.input_list.split(',')
  58. i.text = ''
  59. i.selected = ''
  60. parameterData.push(i)
  61. }
  62. })
  63. this.$hub.$emit(this.data.hub, {
  64. type: 'value',
  65. payload: Object.assign(this.value, {
  66. attribute_category_id: v,
  67. patternData,
  68. parameterData,
  69. }),
  70. })
  71. },
  72. },
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. </style>