export default {
  props: {
    value: {
      type: [Object, Array, String, Number],
      required: false,
    },
    title: {
      type: String,
      default: '基础数据选择',
    },
    multiple: {
      type: Boolean,
      default: false,
    },
    clearable: {
      type: Boolean,
      default: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    placeholder: {
      type: String,
      default: '',
    },
    maxTagCount: {
      type: Number,
    },
    tableKey: {
      type: String,
      default: () => 'id',
    },
    treeKey: {
      type: String,
      default: () => 'id',
    },
    searchPlaceholder: {
      type: String,
      default: '',
    },
    tableName: {
      type: String,
      required: true
    },
    /**
     * 组织机构权限类型，默认访问权限
     */
    authType: {
      type: String,
      default: 'ACCESS',
    },
    /**
     * 版本日期， 格式 9999-12-31
     */
    versionDate: {
      type: String,
      default: '',
    },
    modalWidth: {
      type: [Number, String],
      default: 970,
    },
    inputLabel: {
      type: String,
      default: 'name',
      validator: (value) => {
        return value === 'code' || value === 'name' || value === 'codeName'
      },
    },
    isLeaf: {
      type: Boolean,
      default: false
    },
    filterFormular: {
      type: String,
      default: ''
    },
    filterFormularSP: {
      type: String,
      default: ''
    },
    billdefineName: {
      type: String,
      default: ''
    },
    billId: {
      type: String,
      default: ''
    },
    isFilter: {
      type: Boolean,
      default: false
    },
    bill: {
      type: Object,
      default: () => { }
    },
    rowIndex: {
      type: Number,
      default: -1
    },
    isCode: {
      type: Boolean,
      default: false
    },
    isObject: {
      type: Boolean,
      
      default: false
    },
    tableStyle: {
      type: Boolean,
      default: false
    },
    groupTableName: {
      type: Object,
      default: () => ({
        tableName:'',
        groupFieldName:'',
        define:''
      })
    },
    structtype: {
      type: Number,
      default: -1
    },
    treeTableName: {
      type: String,
      default: ''
    },
    hideSelected: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    isOrg() {
      return this.tableName === 'MD_ORG'
    },
  },
  methods: {
    async getOrg(param) {
      let result = await GMS.$http
        .post('/org/data/list', param)
        .then((res) => {
          const { rows, rs } = res.data
          return rows
        })
        .catch((err) => {
          console.error('获取组织机构失败：' + JSON.stringify(err))
          console.log('error', err)
        })
      return result
    },
    getBaseData(postData, urlParam, isInit = false) {
      let url = ''
      let postParam = {}
      if (this.isFilter && !isInit) {
        let newParam = {}
        if (this.bill && this.bill.getBuillData) {
          delete postData.expression
          delete postData['BI-SYNTAX']

          const getParamBill = () => {
            let bill = this.bill.getBuillData && this.bill.getBuillData()
            if (bill&&bill.id) {
              bill.id = this.billId
            }
            return bill
          }

          newParam = {
            baseDataDto: postData,
            filterFormular: this.filterFormularSP,
            billdefineName: this.billdefineName,
            billId: this.billId,
            bill: getParamBill(),
            rowIndex: this.rowIndex
          }
        }
        url = urlParam || `/rbcfunc/baseData/list`
        if (urlParam) {
          postParam = JSON.parse(JSON.stringify(postData))
        } else {
          postParam = JSON.parse(JSON.stringify(newParam))
        }
      } else {
        url = urlParam || `/baseData/data/list`
        postParam = JSON.parse(JSON.stringify(postData))
      }

      return GMS.$http
        .post(url, JSON.stringify(postParam), {
          headers: {
            post: {
              'Content-Type': 'application/json',
            },
          },
        })

    },

  }
}


