import userServer from '@/api/subscription/user_server.js'
import planServer from '@/api/subscription/plan_server.js'

/**
 * 业务用户 / 套餐关联下拉：依赖后端 GET /biz_user/all、GET /biz_plan/all
 */
export default {
  data() {
    return {
      bizUserOptions: [],
      bizPlanOptions: [],
    }
  },
  methods: {
    async loadBizRelationOptions() {
      try {
        const [u, p] = await Promise.all([userServer.all(), planServer.all()])
        if (u && u.code === 0) {
          this.bizUserOptions = Array.isArray(u.data) ? u.data : []
        } else {
          this.bizUserOptions = []
        }
        if (p && p.code === 0) {
          this.bizPlanOptions = Array.isArray(p.data) ? p.data : []
        } else {
          this.bizPlanOptions = []
        }
      } catch (e) {
        this.bizUserOptions = []
        this.bizPlanOptions = []
      }
    },
    bizUserLabel(row) {
      if (!row || row.id == null) return ''
      const name = row.name || ''
      const mobile = row.mobile ? ` ${row.mobile}` : ''
      return `#${row.id} ${name}${mobile}`.trim()
    },
    bizPlanLabel(row) {
      if (!row || row.id == null) return ''
      const name = row.plan_name || row.plan_code || ''
      return `#${row.id} ${name}`.trim()
    },
  },
}
