|
|
@@ -353,12 +353,14 @@ export default {
|
|
|
getMembershipStats(),
|
|
|
this._request('/api/admin/membership/overview')
|
|
|
])
|
|
|
- if (statsRes.data && statsRes.data.code === 200) {
|
|
|
- const s = statsRes.data.data
|
|
|
+ // getMembershipStats 走 request 拦截器,返回 {code, message, data}
|
|
|
+ if (statsRes.code === 200 && statsRes.data) {
|
|
|
+ const s = statsRes.data
|
|
|
this.statCards[0].value = s.freeCount || 0
|
|
|
this.statCards[1].value = s.familyCount || 0
|
|
|
this.statCards[2].value = s.providerCount || 0
|
|
|
}
|
|
|
+ // _request 是裸 axios,需通过 res.data.code 解包
|
|
|
if (overviewRes.data && overviewRes.data.code === 200) {
|
|
|
const o = overviewRes.data.data || {}
|
|
|
this.statCards[3].value = o.newFamilyThisMonth || 0
|
|
|
@@ -373,9 +375,10 @@ export default {
|
|
|
async loadLevels() {
|
|
|
this.levelsLoading = true
|
|
|
try {
|
|
|
+ // listMembershipLevels 走 request 拦截器,返回已解包的 {code, message, data},data 即等级数组
|
|
|
const res = await listMembershipLevels()
|
|
|
- if (res.data && res.data.code === 200) {
|
|
|
- const list = res.data.data || []
|
|
|
+ if (res.code === 200) {
|
|
|
+ const list = res.data || []
|
|
|
this.levels = Array.isArray(list) ? list.filter(function(l) { return l && typeof l === 'object' }) : []
|
|
|
}
|
|
|
} catch (e) {
|
|
|
@@ -397,7 +400,6 @@ export default {
|
|
|
const records = (res.data.data && res.data.data.records) || []
|
|
|
this.upgradeRecords = Array.isArray(records) ? records.filter(function(r) { return r && typeof r === 'object' }) : []
|
|
|
this.recordsTotal = res.data.data.total || 0
|
|
|
- await this.resolveUserNames(this.upgradeRecords, 'userId')
|
|
|
}
|
|
|
} catch (e) {
|
|
|
this.$message.error('加载升级记录失败')
|
|
|
@@ -448,12 +450,12 @@ export default {
|
|
|
this.editSubmitting = true
|
|
|
try {
|
|
|
const res = await updateMembershipLevel(this.editForm)
|
|
|
- if (res.data && res.data.code === 200) {
|
|
|
- this.$message && this.$message.success && this.$message.success(res.data.data || '更新成功')
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.$message && this.$message.success && this.$message.success(res.data || '更新成功')
|
|
|
this.editVisible = false
|
|
|
this.loadLevels()
|
|
|
} else {
|
|
|
- this.$message && this.$message.error && this.$message.error((res.data && res.data.message) || '更新失败')
|
|
|
+ this.$message && this.$message.error && this.$message.error(res.message || '更新失败')
|
|
|
}
|
|
|
} catch (e) {
|
|
|
this.$message && this.$message.error && this.$message.error('更新失败')
|
|
|
@@ -462,31 +464,6 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- resolveUserNames(items, idField) {
|
|
|
- if (!items || items.length === 0) return Promise.resolve()
|
|
|
- var ids = []
|
|
|
- items.forEach(function(item) {
|
|
|
- if (item[idField] && ids.indexOf(item[idField]) === -1) ids.push(item[idField])
|
|
|
- })
|
|
|
- var nameMap = {}
|
|
|
- return Promise.all(ids.map(function(id) {
|
|
|
- return searchUsers({ keyword: String(id) })
|
|
|
- .then(function(res) {
|
|
|
- if (res.data && res.data.length > 0) {
|
|
|
- var u = res.data[0]
|
|
|
- nameMap[id] = u.nickname || u.realName || ('用户' + id)
|
|
|
- } else {
|
|
|
- nameMap[id] = ('用户' + id)
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(function() { nameMap[id] = ('用户' + id) })
|
|
|
- })).then(function() {
|
|
|
- items.forEach(function(item) {
|
|
|
- item.userName = nameMap[item[idField]] || ('用户' + item[idField])
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
async handleMaintainSearch() {
|
|
|
const kw = (this.maintainSearch || '').trim()
|
|
|
if (!kw) {
|
|
|
@@ -532,13 +509,13 @@ export default {
|
|
|
if (refStr === '0') payload.referrerId = ''
|
|
|
else if (refStr !== '') payload.referrerId = refStr
|
|
|
const res = await updateMembershipUser(payload)
|
|
|
- if (res.data && res.data.code === 200) {
|
|
|
- this.$message && this.$message.success && this.$message.success(res.data.data || '更新成功')
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.$message && this.$message.success && this.$message.success(res.data || '更新成功')
|
|
|
this.maintainVisible = false
|
|
|
this.handleMaintainSearch()
|
|
|
this.refreshAll()
|
|
|
} else {
|
|
|
- this.$message && this.$message.error && this.$message.error(res.data && res.data.message || '更新失败')
|
|
|
+ this.$message && this.$message.error && this.$message.error(res.message || '更新失败')
|
|
|
}
|
|
|
} catch (e) {
|
|
|
this.$message && this.$message.error && this.$message.error('更新失败')
|