| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- <template>
- <div class="user-page">
- <div class="user-title">
- <div class="title-l">
- <el-icon size="24" class="user-icon" color="#000000"><UserFilled /></el-icon>
- <span class="user-name">用户管理</span>
- <span class="title-line"></span>
- <span class="title-info">共 {{ totalVal }} 个用户,更新日期于 {{ formattedStartDate }}</span>
- </div>
- <div class="title-r">
- <el-input
- size="large"
- v-model="searchVal"
- @change="handleChangeGruop"
- style="width: 200px"
- placeholder="搜索用户/手机号"
- :prefix-icon="Search"
- />
- <el-button class="ml-10" size="large" type="primary" plain @click="downloadTemplate"
- >下载模板</el-button
- >
- <!-- <el-button size="large" type="primary" @click="uploadData">上传订单</el-button> -->
- <el-upload
- v-model:file-list="fileList"
- class="upload-demo"
- :action="config.base_url + 'adm/import_lighten_card_offline'"
- multiple
- :data="{ farmId: currentFarmId }"
- :headers="uploadHeaders"
- :on-success="handleUploadMsg"
- :on-error="handleUploadMsg"
- :limit="1"
- >
- <el-button class="ml-10" size="large" type="primary">上传订单</el-button>
- </el-upload>
- <el-button class="ml-10" size="large" type="primary" plain @click="openGroupPopup">新建分组</el-button>
- <!-- <el-button size="large" type="primary" plain>批量发送</el-button> -->
- </div>
- </div>
- <div class="user-btn-group">
- <div class="btn-l">
- <el-button size="large" type="primary">优质用户</el-button>
- <el-button size="large" type="primary" plain>中等用户</el-button>
- <el-button size="large" type="primary" plain>普通用户</el-button>
- </div>
- <div class="select-group">
- <!-- <el-select v-model="cityVal" placeholder="选择省份" size="large" class="ml-10" style="width: 100px">
- <el-option v-for="item in cityOptions" :key="item.value" :label="item.label" :value="item.value" />
- </el-select> -->
- <el-select v-model="groupVal" @change="handleChangeGruop" placeholder="选择分组" size="large" class="ml-10" style="width: 120px">
- <el-option label="全部分组" value="-2" />
- <el-option v-for="(item, index) in groupOptions" :key="index" :label="item.groupName" :value="item.id" />
- </el-select>
- <el-select v-model="levelVal" @change="handleChangeGruop" placeholder="守护等级" size="large" class="ml-10" style="width: 120px">
- <el-option label="全部等级" value="-2" />
- <el-option v-for="(item, index) in levelOptions" :key="index" :label="item.name" :value="item.id" />
- </el-select>
- </div>
- </div>
- <div class="table-wrap">
- <el-table :data="tableData" style="width: 100%" @selection-change="handleTableSelect" height="100%">
- <el-table-column type="selection" width="55" />
- <el-table-column property="miniUserId" label="用户编码" width="120" />
- <el-table-column property="name" label="用户昵称">
- <template #default="scope">
- <div class="user-info">
- <!-- <el-avatar :size="24" src="https://birdseye-img-ali-cdn.sysuimars.com/birdseye-look-mini/91754/1750583672619.png" /> -->
- <el-avatar
- :size="24"
- :src="
- scope.row.icon || 'https://birdseye-img.sysuimars.com/dinggou-mini/defalut-icon.png'
- "
- />
- <span class="ml-10">{{ scope.row.name }}</span>
- </div>
- </template>
- </el-table-column>
- <el-table-column property="tel" label="联系电话" width="120" />
- <el-table-column property="address" label="具体住址" width="240" show-overflow-tooltip />
- <el-table-column label="守护等级">
- <template #default="scope">
- <span :class="['level-tag', 'level-' + scope.row.level?.id]">{{
- levelObj[scope.row.level?.id]
- }}</span>
- </template>
- </el-table-column>
- <el-table-column property="fosterCode" label="守护树编号">
- <template #default="scope">
- <span v-if="scope.row.fosterCode">{{ scope.row.fosterCode }}</span>
- <span v-else @click="toHomeBatch" class="wait-text">待分配</span>
- </template>
- </el-table-column>
- <el-table-column label="状态">
- <template #default="scope">
- <span :class="['status-text']">{{ scope.row.fosterStatus }}</span>
- </template>
- </el-table-column>
- <!-- <el-table-column label="日期" sortable>
- <template #default="scope">{{ scope.row.fosterDate }}</template>
- </el-table-column> -->
- <el-table-column property="groupName" label="分组" />
- <el-table-column label="操作" width="310">
- <template #default="scope">
- <div class="action-btn">
- <!-- <el-button type="primary" @click="handleMsg(scope.row)"
- ><el-icon class="el-icon--right"><Comment /></el-icon>发消息</el-button
- >
- <el-button type="primary" @click="handleMsg(scope.row)"
- ><el-icon><Briefcase /></el-icon>发礼物</el-button
- > -->
- <el-button type="warning" @click="clearUser(scope.row)"
- ><el-icon><DeleteFilled /></el-icon>清理</el-button
- >
- <el-button type="danger" @click="deleteUser(scope.row)"
- ><el-icon><Delete /></el-icon>删除</el-button
- >
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div class="pagination-wrap">
- <el-pagination
- v-model:current-page="currentPage"
- v-model:page-size="pageSize"
- :page-sizes="[10, 20, 50, 100]"
- layout="total, sizes, prev, pager, next"
- :total="totalVal"
- @size-change="handleSizeChange"
- @current-change="getTableData"
- />
- </div>
- <div class="put-btn" v-if="selectedRows.length">
- <div class="btn-r" @click="batchGroup">分配分组</div>
- <!-- <div class="btn-l ml-30">推送消息</div>
- <div class="btn-line"></div>
- <div class="btn-r">推送优惠券</div> -->
- </div>
- </div>
- <add-group ref="addGroupRef" @updateTableList="getTableData" @updateGroupList="getGroupList"></add-group>
- </template>
- <script setup>
- import { onMounted, ref } from "vue";
- import { Search } from "@element-plus/icons-vue";
- import config from "@/api/config.js";
- import { useStore } from "vuex";
- import { ElMessage, ElMessageBox } from "element-plus";
- import addGroup from "@/components/addGroup.vue";
- let store = useStore();
- import { useRouter } from "vue-router";
- import { dateFormat } from "@/utils/date_util";
- const router = useRouter();
- const currentFarmId = store.getters.userinfo.curFarmId
- const searchVal = ref(null);
- const levelObj = {
- 0: "平民",
- 1: "青铜守护",
- 2: "白银守护",
- 3: "赤金守护",
- 4: "星勋守护",
- };
- const tableData = ref([]);
- const selectedRows = ref([]);
- function handleTableSelect(selection) {
- selectedRows.value = selection;
- }
- const groupVal = ref('-2');
- const groupOptions = ref([]);
- const levelVal = ref('-2');
- const levelOptions = ref([]);
- const currentPage = ref(1);
- const pageSize = ref(20); // 每页显示20条数据
- const totalVal = ref(0);
- const startDate = new Date();
- // 格式化日期
- const formattedStartDate = dateFormat(startDate, "YY.mm.dd");
- onMounted(() => {
- getTableData();
- getGroupList();
- VE_API.manage_user
- .fetchLevelList({farmId: currentFarmId})
- .then(({ data }) => {
- levelOptions.value = data
- });
- });
- function getGroupList() {
- VE_API.manage_user
- .fetchGroupList({farmId: currentFarmId})
- .then(({ data }) => {
- groupOptions.value = data
- });
- }
- function handleChangeGruop(val) {
- currentPage.value = 1; // 重置页码
- getTableData()
- // 这里可以添加根据选择的分组进行数据过滤或其他操作
- }
- function handleSizeChange(newSize) {
- pageSize.value = newSize;
- currentPage.value = 1; // 重置页码
- getTableData();
- }
- function getTableData() {
- // 获取数据
- VE_API.manage_interface
- .fetchUserList({ farmId: currentFarmId, word: searchVal.value, level: (levelVal.value !== '-2') ? levelVal.value : null, groupId: (groupVal.value !== '-2') ? groupVal.value : null, page: currentPage.value - 1, limit: pageSize.value })
- .then(({ data, count }) => {
- tableData.value = data;
- totalVal.value = count;
- });
- }
- // 下载模板
- function downloadTemplate() {
- VE_API.manage_user
- .downloadTemplate()
- .then((response) => {
- const blob = new Blob([response], {
- type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
- });
- const link = document.createElement("a");
- link.href = window.URL.createObjectURL(blob);
- link.download = "用户数据模板.xlsx";
- link.click();
- })
- .catch((error) => {
- console.error("下载模板失败:", error);
- });
- }
- const fileList = ref([]);
- const uploadHeaders = {
- token: store.getters.token,
- };
- // 上传数据
- function handleUploadMsg(res) {
- ElMessage.success(res.msg);
- getTableData(); // 刷新表格数据
- }
- // 清理数据
- function clearUser(item) {
- ElMessageBox.confirm(`确认清理 ${item.name} 的绑定树和手机号码吗?`, "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- VE_API.manage_user.cleanBind({ miniUserId: item.miniUserId }).then(({ code }) => {
- if (code === 0) {
- ElMessage.success("清理成功");
- getTableData(); // 刷新表格数据
- }
- });
- }).catch(() => {});
- }
- // 删除数据
- function deleteUser(item) {
- ElMessageBox.confirm(`确认删除 ${item.name} 的守护权限吗?`, "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- VE_API.manage_user.deleteUser({ id: item.id }).then(({ code }) => {
- if (code === 0) {
- ElMessage.success("删除成功");
- getTableData(); // 刷新表格数据
- }
- });
- }).catch(() => {});
- }
- const addGroupRef = ref(null);
- // 新建分组
- function openGroupPopup() {
- addGroupRef.value.openClientPopup("add");
- }
- // 批量分配分组
- function batchGroup() {
- addGroupRef.value.openClientPopup("edit", selectedRows.value.map(item => item.tel));
- }
- // 去待分配
- function toHomeBatch() {
- router.push("/layout/home?acitveName=待分配")
- }
- </script>
- <style lang="scss" scoped>
- .user-page {
- padding: 41px 20px 0 20px;
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- .user-title {
- display: flex;
- align-items: center;
- justify-content: space-between;
- .title-l {
- display: flex;
- align-items: center;
- .user-name {
- font-family: "PangMenZhengDao";
- padding-left: 10px;
- font-size: 24px;
- color: #000000;
- }
- .title-line {
- display: inline-block;
- width: 1px;
- height: 12px;
- background: rgba(0, 0, 0, 0.5);
- margin: 0 15px;
- }
- .title-info {
- color: rgba(0, 0, 0, 0.5);
- font-size: 12px;
- }
- }
- .title-r {
- display: flex;
- align-items: center;
- ::v-deep {
- .el-upload-list {
- display: none;
- }
- }
- }
- }
- .ml-10 {
- margin-left: 10px;
- }
- .ml-30 {
- margin-left: 30px;
- }
- .user-btn-group {
- padding: 24px 0;
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .table-wrap {
- flex: 1;
- height: calc(100% - 44px - 88px - 70px);
- .action-btn {
- display: flex;
- align-items: center;
- }
- .user-info {
- display: flex;
- align-items: center;
- }
- .level-tag {
- font-size: 16px;
- line-height: 30px;
- padding: 0 10px;
- border-radius: 4px;
- }
- .level-0 {
- color: #03b2d5;
- background: rgba(3, 178, 213, 0.2);
- }
- .level-1 {
- color: #d88c4a;
- background: rgba(200, 156, 117, 0.2);
- }
- .level-2 {
- color: #6293c1;
- background: rgba(115, 193, 255, 0.2);
- }
- .level-3 {
- color: #b18c0d;
- background: rgba(243, 191, 48, 0.2);
- }
- .level-4 {
- color: #bd6fe8;
- background: rgba(236, 125, 255, 0.2);
- }
- .status-text {
- color: #7d7d7d;
- }
- .status-1 {
- color: #ffaa00;
- }
- .status-2 {
- color: #2199f8;
- }
- .wait-text {
- cursor: pointer;
- color: #2199f8;
- text-decoration: underline;
- }
- }
- .pagination-wrap {
- padding: 16px 0;
- display: flex;
- justify-content: end;
- }
- .put-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- bottom: 10px;
- .btn-l {
- padding: 12px 44px;
- background: #f0ac37;
- border-radius: 4px;
- font-size: 16px;
- color: #fff;
- cursor: pointer;
- }
- .btn-r {
- margin-left: 30px;
- padding: 12px 36px;
- background: #2199f8;
- border-radius: 4px;
- font-size: 16px;
- color: #fff;
- cursor: pointer;
- }
- }
- }
- </style>
|