123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { allocateTypeTreeList } from '@/api/allocateType'
- const AllocateType = {
- template: `
- <a-cascader
- :value="defaultVal"
- allowClear
- :change-on-select="changeOnSelect"
- @change="handleChange"
- :options="list"
- expand-trigger="hover"
- :placeholder="placeholder"
- :id="id"
- :fieldNames="{ label: 'name', value: 'allocateTypeSn', children: 'sonList' }"/>
- `,
- props: {
- value: {
- type: Array,
- defatut: function(){
- return []
- }
- },
- id: {
- type: String,
- default: ''
- },
- placeholder:{
- type: String,
- default: '请选择'
- },
- changeOnSelect:{
- type: Boolean,
- default: false
- },
- level:{
- type: [String,Number],
- default: ''
- }
- },
- data() {
- return {
- defaultVal: this.value,
- list: []
- };
- },
- mounted() {
- this.getProductBrand()
- },
- watch: {
- value(newValue, oldValue) {
- this.defaultVal = newValue
- }
- },
- methods: {
- filterOption (input, option) {
- return (
- option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
- )
- },
- handleChange(value,opts) {
- this.defaultVal = value;
- this.$emit('input', value);
- this.$emit('change', value,opts);
- },
- // 调拨类型
- getProductBrand () {
- allocateTypeTreeList({}).then(res => {
- if (res.status == 200) {
- if(this.level){
- this.list = this.getBylevel(res.data)
- }else{
- this.list = res.data
- }
- } else {
- this.list = []
- }
- })
- },
- getBylevel(data){
- const ret = []
- // 显示一级分类
- if(this.level == 1){
- data.map(item => {
- if(item.sonList){
- delete item.sonList
- }
- })
- }
- // 显示二级分类
- if(this.level == 2){
- data.map(item => {
- if(item.sonList){
- item.sonList.map(cd => {
- if(cd.sonList){
- delete cd.sonList
- }
- })
- }
- })
- }
- return data
- }
- },
- };
- export default AllocateType
|