|
|
@@ -15,6 +15,48 @@
|
|
|
<el-option label="女" :value="2" />
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="用户类型">
|
|
|
+ <el-select v-model="queryForm.userType" placeholder="全部" clearable style="width:120px">
|
|
|
+ <el-option
|
|
|
+ v-for="item in userCategoryOptions"
|
|
|
+ :key="item.code"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.code"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="省">
|
|
|
+ <el-select-v2
|
|
|
+ v-model="queryForm.provinceCode"
|
|
|
+ :options="provinceList"
|
|
|
+ placeholder="全部"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ style="width:160px"
|
|
|
+ @change="onQueryProvinceChange"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="市">
|
|
|
+ <el-select-v2
|
|
|
+ v-model="queryForm.cityCode"
|
|
|
+ :options="queryCityList"
|
|
|
+ placeholder="全部"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ style="width:200px"
|
|
|
+ @change="onQueryCityChange"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="区/县">
|
|
|
+ <el-select-v2
|
|
|
+ v-model="queryForm.districtCode"
|
|
|
+ :options="queryDistrictList"
|
|
|
+ placeholder="全部"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ style="width:240px"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="注册时间">
|
|
|
<el-date-picker
|
|
|
v-model="queryForm.dateRange"
|
|
|
@@ -86,6 +128,26 @@
|
|
|
<template #default="{ row }">{{ row.age != null ? row.age + '岁' : '-' }}</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column prop="phone" label="手机号" width="130" />
|
|
|
+ <el-table-column prop="userType" label="用户类型" width="95" align="center">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-tag :type="userTypeTagType(row.userType)" size="small" v-if="row.userType">
|
|
|
+ {{ userTypeText(row.userType) }}
|
|
|
+ </el-tag>
|
|
|
+ <span v-else>-</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="所在地区" min-width="180">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <span v-if="row.provinceCode">{{ formatRegion(row) }}</span>
|
|
|
+ <span v-else class="text-gray">-</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="address" label="详细地址" min-width="160" show-overflow-tooltip>
|
|
|
+ <template #default="{ row }">
|
|
|
+ <span v-if="row.address">{{ row.address }}</span>
|
|
|
+ <span v-else class="text-gray">-</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
<el-table-column prop="deviceCodes" label="设备编号" min-width="140">
|
|
|
<template #default="{ row }">
|
|
|
<span v-if="row.deviceCodes">{{ row.deviceCodes }}</span>
|
|
|
@@ -168,6 +230,36 @@
|
|
|
<el-input v-model="formData.phone" placeholder="请输入手机号" maxlength="11" :disabled="!!formData.id" />
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="用户类型" prop="userType">
|
|
|
+ <el-select v-model="formData.userType" placeholder="请选择用户类型" style="width:100%">
|
|
|
+ <el-option
|
|
|
+ v-for="item in userCategoryOptions"
|
|
|
+ :key="item.code"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.code"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="所在地区" prop="regionCodes">
|
|
|
+ <el-cascader
|
|
|
+ v-model="formData.regionCodes"
|
|
|
+ :options="regionOptions"
|
|
|
+ :props="regionCascaderProps"
|
|
|
+ placeholder="请选择省/市/区"
|
|
|
+ clearable
|
|
|
+ filterable
|
|
|
+ style="width:100%"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="详细地址" prop="address">
|
|
|
+ <el-input v-model="formData.address" placeholder="请输入详细地址" maxlength="200" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="肩宽(cm)" prop="shoulderWidth">
|
|
|
<el-input-number v-model="formData.shoulderWidth" :min="0" :precision="1" style="width:100%" />
|
|
|
@@ -257,6 +349,7 @@ import { ref, reactive, onMounted, computed, watch } from 'vue'
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
import { Search, Refresh, Plus, Delete } from '@element-plus/icons-vue'
|
|
|
+import { regionData, codeToText } from 'element-china-area-data'
|
|
|
import ExcelExport from '@/components/ExcelExport.vue'
|
|
|
import ExcelImport from '@/components/ExcelImport.vue'
|
|
|
import {
|
|
|
@@ -268,6 +361,7 @@ import {
|
|
|
batchImportProfile,
|
|
|
generateUserAcupoint
|
|
|
} from '@/api/user'
|
|
|
+import { getUserCategoryList } from '@/api/userCategory'
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
@@ -276,6 +370,10 @@ const queryForm = reactive({
|
|
|
keyword: '',
|
|
|
deviceCode: '',
|
|
|
gender: null,
|
|
|
+ userType: null,
|
|
|
+ provinceCode: '',
|
|
|
+ cityCode: '',
|
|
|
+ districtCode: '',
|
|
|
dateRange: null,
|
|
|
acupointStatus: null,
|
|
|
pageNum: 1,
|
|
|
@@ -294,6 +392,9 @@ const exportHeaders = [
|
|
|
{ label: '性别', prop: 'genderText' },
|
|
|
{ label: '年龄', prop: 'age' },
|
|
|
{ label: '手机号', prop: 'phone' },
|
|
|
+ { label: '用户类型', prop: 'userTypeLabel' },
|
|
|
+ { label: '所在地区', prop: 'regionText' },
|
|
|
+ { label: '详细地址', prop: 'address' },
|
|
|
{ label: '设备编号', prop: 'deviceCodes' },
|
|
|
{ label: '肩宽(cm)', prop: 'shoulderWidth' },
|
|
|
{ label: '身长(cm)', prop: 'bodyHeight' },
|
|
|
@@ -304,6 +405,119 @@ const exportHeaders = [
|
|
|
{ label: '注册时间', prop: 'createTime' }
|
|
|
]
|
|
|
|
|
|
+// 中国三级行政区划数据(省/市/区)
|
|
|
+const regionOptions = regionData
|
|
|
+const regionCascaderProps = { value: 'value', label: 'label', children: 'children' }
|
|
|
+
|
|
|
+// 查询区域:省列表、联动的市/区列表
|
|
|
+const provinceList = computed(() => regionData.map(p => ({ value: p.value, label: p.label })))
|
|
|
+
|
|
|
+// 预计算“全国所有市”与“全国所有区”(模块级常量,仅计算一次),
|
|
|
+// 避免清空上级时 computed 重复重建上千条数组导致卡顿
|
|
|
+const ALL_CITIES = []
|
|
|
+const ALL_DISTRICTS = []
|
|
|
+regionData.forEach(p => {
|
|
|
+ ;(p.children || []).forEach(c => {
|
|
|
+ ALL_CITIES.push({ value: c.value, label: `${p.label} / ${c.label}` })
|
|
|
+ ;(c.children || []).forEach(d => {
|
|
|
+ ALL_DISTRICTS.push({ value: d.value, label: `${p.label} / ${c.label} / ${d.label}` })
|
|
|
+ })
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+/** 市列表:选了省则返回该省市;未选省则返回全国所有市(加上省名以便识别) */
|
|
|
+const queryCityList = computed(() => {
|
|
|
+ if (queryForm.provinceCode) {
|
|
|
+ const prov = regionData.find(p => p.value === queryForm.provinceCode)
|
|
|
+ return (prov?.children || []).map(c => ({ value: c.value, label: c.label }))
|
|
|
+ }
|
|
|
+ return ALL_CITIES
|
|
|
+})
|
|
|
+
|
|
|
+/** 区/县列表:选了市则返回该市下区;只选省返回该省下区;都未选返回全国区(带上上级以便识别) */
|
|
|
+const queryDistrictList = computed(() => {
|
|
|
+ if (queryForm.cityCode) {
|
|
|
+ for (const p of regionData) {
|
|
|
+ const city = (p.children || []).find(c => c.value === queryForm.cityCode)
|
|
|
+ if (city) {
|
|
|
+ return (city.children || []).map(d => ({ value: d.value, label: d.label }))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ if (queryForm.provinceCode) {
|
|
|
+ const prov = regionData.find(p => p.value === queryForm.provinceCode)
|
|
|
+ const all = []
|
|
|
+ ;(prov?.children || []).forEach(c => {
|
|
|
+ (c.children || []).forEach(d => {
|
|
|
+ all.push({ value: d.value, label: `${c.label} / ${d.label}` })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ return all
|
|
|
+ }
|
|
|
+ return ALL_DISTRICTS
|
|
|
+})
|
|
|
+
|
|
|
+/** 选了省:如果已选的市/区不属于该省则清空 */
|
|
|
+function onQueryProvinceChange(val) {
|
|
|
+ if (!val) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const prov = regionData.find(p => p.value === val)
|
|
|
+ const cities = prov?.children || []
|
|
|
+ if (queryForm.cityCode && !cities.find(c => c.value === queryForm.cityCode)) {
|
|
|
+ queryForm.cityCode = ''
|
|
|
+ queryForm.districtCode = ''
|
|
|
+ } else if (queryForm.districtCode) {
|
|
|
+ const city = cities.find(c => c.value === queryForm.cityCode)
|
|
|
+ if (city && !(city.children || []).find(d => d.value === queryForm.districtCode)) {
|
|
|
+ queryForm.districtCode = ''
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/** 选了市:如果已选的区不属于该市则清空 */
|
|
|
+function onQueryCityChange(val) {
|
|
|
+ if (!val) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for (const p of regionData) {
|
|
|
+ const city = (p.children || []).find(c => c.value === val)
|
|
|
+ if (city) {
|
|
|
+ if (queryForm.districtCode && !(city.children || []).find(d => d.value === queryForm.districtCode)) {
|
|
|
+ queryForm.districtCode = ''
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/** 用户类别选项(从后台 user_category 动态加载) */
|
|
|
+const userCategoryOptions = ref([])
|
|
|
+
|
|
|
+/** 用户类型文本(优先从动态加载的类别表查) */
|
|
|
+function userTypeText(type) {
|
|
|
+ if (type == null) return '-'
|
|
|
+ const item = userCategoryOptions.value.find(c => c.code === type)
|
|
|
+ return item ? item.name : '-'
|
|
|
+}
|
|
|
+
|
|
|
+/** 用户类型标签颜色(优先使用后台配置的 tagType) */
|
|
|
+function userTypeTagType(type) {
|
|
|
+ if (type == null) return 'info'
|
|
|
+ const item = userCategoryOptions.value.find(c => c.code === type)
|
|
|
+ return item?.tagType || 'primary'
|
|
|
+}
|
|
|
+
|
|
|
+/** 根据行政区划编码还原为 “省/市/区” 文本 */
|
|
|
+function formatRegion(row) {
|
|
|
+ const parts = [row.provinceCode, row.cityCode, row.districtCode]
|
|
|
+ .filter(c => !!c)
|
|
|
+ .map(c => codeToText[c] || '')
|
|
|
+ .filter(t => !!t)
|
|
|
+ return parts.join(' / ')
|
|
|
+}
|
|
|
+
|
|
|
async function loadData() {
|
|
|
loading.value = true
|
|
|
try {
|
|
|
@@ -311,6 +525,10 @@ async function loadData() {
|
|
|
keyword: queryForm.keyword || undefined,
|
|
|
deviceCode: queryForm.deviceCode || undefined,
|
|
|
gender: queryForm.gender,
|
|
|
+ userType: queryForm.userType,
|
|
|
+ provinceCode: queryForm.provinceCode || undefined,
|
|
|
+ cityCode: queryForm.cityCode || undefined,
|
|
|
+ districtCode: queryForm.districtCode || undefined,
|
|
|
startTime: queryForm.dateRange?.[0] || undefined,
|
|
|
endTime: queryForm.dateRange?.[1] || undefined,
|
|
|
acupointStatus: queryForm.acupointStatus,
|
|
|
@@ -322,6 +540,8 @@ async function loadData() {
|
|
|
const records = (res.data?.records || []).map(r => ({
|
|
|
...r,
|
|
|
genderText: r.gender === 1 ? '男' : r.gender === 2 ? '女' : '-',
|
|
|
+ userTypeLabel: userTypeText(r.userType),
|
|
|
+ regionText: formatRegion(r),
|
|
|
acupointText: r.acupointTableId ? '已生成' : '未生成'
|
|
|
}))
|
|
|
tableData.value = records
|
|
|
@@ -340,6 +560,10 @@ function handleReset() {
|
|
|
queryForm.keyword = ''
|
|
|
queryForm.deviceCode = ''
|
|
|
queryForm.gender = null
|
|
|
+ queryForm.userType = null
|
|
|
+ queryForm.provinceCode = ''
|
|
|
+ queryForm.cityCode = ''
|
|
|
+ queryForm.districtCode = ''
|
|
|
queryForm.dateRange = null
|
|
|
queryForm.acupointStatus = null
|
|
|
queryForm.pageNum = 1
|
|
|
@@ -362,6 +586,9 @@ const formData = reactive({
|
|
|
gender: null,
|
|
|
age: null,
|
|
|
phone: '',
|
|
|
+ userType: 1,
|
|
|
+ regionCodes: [],
|
|
|
+ address: '',
|
|
|
shoulderWidth: null,
|
|
|
bodyHeight: null,
|
|
|
spineLength: null,
|
|
|
@@ -446,6 +673,7 @@ const formRules = {
|
|
|
function handleAdd() {
|
|
|
Object.assign(formData, {
|
|
|
id: null, name: '', gender: null, age: null, phone: '',
|
|
|
+ userType: 1, regionCodes: [], address: '',
|
|
|
shoulderWidth: null, bodyHeight: null, spineLength: null, height: null, weight: null,
|
|
|
fingerWidth1: null, fingerWidth15: null, fingerWidth3: null
|
|
|
})
|
|
|
@@ -460,6 +688,9 @@ function handleEdit(row) {
|
|
|
gender: row.gender,
|
|
|
age: row.age,
|
|
|
phone: row.phone,
|
|
|
+ userType: row.userType ?? 1,
|
|
|
+ regionCodes: [row.provinceCode, row.cityCode, row.districtCode].filter(c => !!c),
|
|
|
+ address: row.address || '',
|
|
|
shoulderWidth: row.shoulderWidth,
|
|
|
bodyHeight: row.bodyHeight,
|
|
|
spineLength: row.spineLength,
|
|
|
@@ -484,10 +715,18 @@ async function handleSubmit() {
|
|
|
await formRef.value.validate()
|
|
|
submitLoading.value = true
|
|
|
try {
|
|
|
+ const codes = formData.regionCodes || []
|
|
|
+ const payload = {
|
|
|
+ ...formData,
|
|
|
+ provinceCode: codes[0] || null,
|
|
|
+ cityCode: codes[1] || null,
|
|
|
+ districtCode: codes[2] || null
|
|
|
+ }
|
|
|
+ delete payload.regionCodes
|
|
|
if (formData.id) {
|
|
|
- await updateProfile({ ...formData })
|
|
|
+ await updateProfile(payload)
|
|
|
} else {
|
|
|
- await addProfile({ ...formData })
|
|
|
+ await addProfile(payload)
|
|
|
}
|
|
|
ElMessage.success('操作成功')
|
|
|
dialogVisible.value = false
|
|
|
@@ -557,7 +796,19 @@ async function handleGenerateAcupoint() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-onMounted(loadData)
|
|
|
+async function loadUserCategories() {
|
|
|
+ try {
|
|
|
+ const res = await getUserCategoryList()
|
|
|
+ userCategoryOptions.value = res.data || []
|
|
|
+ } catch (e) {
|
|
|
+ userCategoryOptions.value = []
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ loadUserCategories()
|
|
|
+ loadData()
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|