import { post } from '@/utils/http'
export default {
  data() {
    return {
      managerOptions: [],
      statusOptions: []
    }
  },
  async created() {
    this.statusOptions = this.$store.state.dictionaries && this.$store.state.dictionaries.ObjStatus ? this.$store.state.dictionaries.ObjStatus.default : await this.$utils.getDicListByCode('ObjStatus')
    this.managerOptions = await this.initManagerOptions()
  },
  methods: {
    async initManagerOptions() {
      const params = {
        'pageFrom': 1,
        'pageSize': 1000,
        'searchItems': {
          'items': [
            {
              'fieldName': 'dxContextId',
              'operator': 'EQ',
              'value': this.$route.query.dxContextId
            }
          ],
          'operator': 'AND'
        },
        'openProps': [
          {
            'name': 'dxContextTeamMembers',
            'pageFrom': 1,
            'pageSize': 1000,
            'openProps': [
              {
                'name': 'userVO',
                'pageFrom': 1,
                'pageSize': 1000
              }
            ]
          }
        ]
      }

      return await post('/DxContextTeam/find/recursion', params).then(res => {
        let data = []
        const arr = []
        res.items.content && res.items.content.forEach(r => {
          data = data.concat(r.dxContextTeamMembers)
        })
        data.forEach(row => {
          const findItem = arr.find(x => x.key === row.userVO.id)
          !findItem && arr.push({ key: row.userVO.id, label: row.userVO.name })
        })
        return arr
      })
    }
  }
}