| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- <template>
- <view class="visit-container">
- <!-- 搜索栏 -->
- <view class="search-bar">
- <u-search
- v-model="searchKeyword"
- placeholder="搜索学生姓名、学号或企业"
- :show-action="false"
- @search="handleSearch"
- @custom="handleSearch"
- bg-color="#f6f6f6"
- height="72"
- shape="round"
- />
- </view>
- <!-- 筛选条件 -->
- <view class="filter-bar" v-if="showFilter">
- <view class="filter-item">
- <u-input
- v-model="queryParams.visitorName"
- placeholder="走访人姓名"
- border="surround"
- clearable
- />
- </view>
- <view class="filter-item">
- <view @click="showStatusPicker = true">
- <u-input
- v-model="statusText"
- placeholder="选择走访状态"
- readonly
- border="surround"
- suffix-icon="arrow-down"
- />
- </view>
- </view>
- <view class="filter-item">
- <view @click="showDatePicker = true">
- <u-input
- v-model="dateRangeText"
- placeholder="选择走访日期"
- readonly
- border="surround"
- suffix-icon="calendar"
- />
- </view>
- </view>
- <view class="filter-actions">
- <u-button
- type="primary"
- size="small"
- @click="handleFilter"
- :loading="loading"
- >
- 筛选
- </u-button>
- <u-button
- type="default"
- size="small"
- @click="resetFilter"
- style="margin-left: 10rpx;"
- >
- 重置
- </u-button>
- </view>
- </view>
- <!-- 筛选按钮 -->
- <view class="action-bar">
- <u-button
- type="default"
- size="small"
- :icon="showFilter ? 'arrow-up' : 'arrow-down'"
- @click="showFilter = !showFilter"
- >
- {{ showFilter ? '收起筛选' : '展开筛选' }}
- </u-button>
- <u-button
- type="primary"
- size="small"
- icon="plus"
- @click="handleAdd"
- >
- 新增走访
- </u-button>
- </view>
- <!-- 走访记录列表 -->
- <view class="list-container">
- <view class="list-content" v-if="visitList.length > 0">
- <view
- class="visit-card"
- v-for="item in visitList"
- :key="item.visitId"
- @click="handleView(item)"
- >
- <!-- 学生信息 -->
- <view class="card-header">
- <view class="student-info">
- <text class="student-name">{{ item.studentName }}</text>
- <text class="student-no">{{ item.studentNo }}</text>
- </view>
- <view class="status-badge">
- <u-tag
- :text="item.statusName || item.status"
- :type="getStatusType(item.status)"
- size="mini"
- />
- </view>
- </view>
-
- <!-- 企业信息 -->
- <view class="card-row">
- <u-icon name="home" size="16" color="#909399" />
- <text class="info-text">{{ item.companyName || '-' }}</text>
- </view>
-
- <!-- 走访信息 -->
- <view class="card-row">
- <u-icon name="calendar" size="16" color="#909399" />
- <text class="info-text">{{ item.visitDate || '-' }}</text>
- <u-icon name="account" size="16" color="#909399" style="margin-left: 20rpx;" />
- <text class="info-text">{{ item.visitorName || '-' }}</text>
- </view>
-
- <!-- 班级专业信息 -->
- <view class="card-row">
- <u-icon name="bookmark" size="16" color="#909399" />
- <text class="info-text">{{ item.className || '-' }} / {{ item.majorName || '-' }}</text>
- </view>
-
- <!-- 操作按钮 -->
- <view class="card-actions">
- <u-button
- type="default"
- size="mini"
- @click.stop="handleEdit(item)"
- v-if="item.status === 'planned' || item.status === '0'"
- >
- 编辑
- </u-button>
- <u-button
- type="error"
- size="mini"
- @click.stop="handleDelete(item)"
- style="margin-left: 10rpx;"
- v-if="item.status === 'planned' || item.status === '0'"
- >
- 删除
- </u-button>
- </view>
- </view>
- </view>
-
- <!-- 空状态 -->
- <view class="empty-state" v-else-if="!loading">
- <u-empty
- mode="data"
- text="暂无走访记录"
- textColor="#c8c9cc"
- iconColor="#c8c9cc"
- />
- </view>
-
- <!-- 加载状态 -->
- <view class="loading-state" v-if="loading">
- <u-loading-icon mode="circle" />
- <text style="margin-left: 10rpx; color: #909399;">加载中...</text>
- </view>
- </view>
- <!-- 上拉加载更多 -->
- <view class="load-more" v-if="hasMore && visitList.length > 0">
- <u-loadmore
- :status="loadMoreStatus"
- @loadmore="loadMore"
- load-text="加载更多"
- loading-text="正在加载..."
- no-more-text="没有更多了"
- />
- </view>
- <!-- 状态选择器 -->
- <u-picker
- :show="showStatusPicker"
- :columns="statusOptions"
- :default-index="[currentStatusIndex]"
- @confirm="handleStatusConfirm"
- @cancel="showStatusPicker = false"
- />
- <!-- 日期范围选择器 -->
- <u-calendar
- :show="showDatePicker"
- mode="range"
- @confirm="handleDateConfirm"
- @close="showDatePicker = false"
- />
- </view>
- </template>
- <script>
- import { listVisit, delVisit, getVisitStatusDict } from '@/api/visit.js';
- export default {
- name: 'VisitList',
- data() {
- return {
- // 搜索和筛选
- searchKeyword: '',
- showFilter: false,
- queryParams: {
- pageNum: 1,
- pageSize: 10,
- studentKeyword: '',
- companyName: '',
- visitorName: '',
- status: '',
- beginVisitDate: '',
- endVisitDate: ''
- },
-
- // 列表数据
- visitList: [],
- total: 0,
- loading: false,
- hasMore: true,
- loadMoreStatus: 'loadmore',
-
- // 状态选择
- showStatusPicker: false,
- statusOptions: [],
- currentStatusIndex: -1,
- statusText: '',
- statusDict: [],
-
- // 日期选择
- showDatePicker: false,
- dateRangeText: '',
- selectedDateRange: []
- };
- },
-
- onLoad() {
- this.initPage();
- },
-
- onPullDownRefresh() {
- this.refreshList();
- },
-
- onReachBottom() {
- if (this.hasMore && this.loadMoreStatus === 'loadmore') {
- this.loadMore();
- }
- },
-
- methods: {
- // 初始化页面
- async initPage() {
- await this.loadStatusDict();
- this.getList();
- },
-
- // 加载状态字典
- async loadStatusDict() {
- try {
- const response = await getVisitStatusDict();
- if (response.code === 200 && response.data) {
- this.statusDict = response.data;
- this.statusOptions = [
- [
- { text: '全部状态', value: '' },
- ...response.data.map(item => ({
- text: item.dictLabel,
- value: item.dictValue
- }))
- ]
- ];
- }
- } catch (error) {
- console.error('加载状态字典失败:', error);
- // 设置默认状态选项
- this.statusOptions = [[
- { text: '全部状态', value: '' },
- { text: '计划中', value: 'planned' },
- { text: '已完成', value: 'completed' },
- { text: '已取消', value: 'cancelled' }
- ]];
- }
- },
-
- // 获取列表数据
- async getList(isLoadMore = false) {
- if (this.loading) return;
-
- this.loading = true;
- if (!isLoadMore) {
- this.loadMoreStatus = 'loadmore';
- } else {
- this.loadMoreStatus = 'loading';
- }
-
- try {
- const response = await listVisit(this.queryParams);
-
- if (response.code === 200) {
- // 后端返回的是TableDataInfo格式,直接包含rows和total字段
- const { rows, total } = response;
-
- if (isLoadMore) {
- this.visitList = [...this.visitList, ...rows || []];
- } else {
- this.visitList = rows || [];
- }
-
- this.total = total || 0;
-
- // 判断是否还有更多数据
- const currentTotal = this.visitList.length;
- this.hasMore = currentTotal < this.total;
-
- if (!this.hasMore) {
- this.loadMoreStatus = 'nomore';
- }
- } else {
- uni.showToast({ title: response.msg || '获取数据失败', icon: 'none' });
- }
- } catch (error) {
- console.error('获取走访记录列表失败:', error);
- uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
- } finally {
- this.loading = false;
- if (this.queryParams.pageNum === 1) {
- uni.stopPullDownRefresh();
- }
- }
- },
-
- // 刷新列表
- refreshList() {
- this.queryParams.pageNum = 1;
- this.getList();
- },
-
- // 加载更多
- loadMore() {
- if (this.hasMore && !this.loading) {
- this.queryParams.pageNum++;
- this.getList(true);
- }
- },
-
- // 搜索
- handleSearch() {
- this.queryParams.studentKeyword = this.searchKeyword;
- this.refreshList();
- },
-
- // 筛选
- handleFilter() {
- this.refreshList();
- },
-
- // 重置筛选
- resetFilter() {
- this.queryParams = {
- ...this.queryParams,
- studentKeyword: this.searchKeyword,
- companyName: '',
- visitorName: '',
- status: '',
- beginVisitDate: '',
- endVisitDate: ''
- };
- this.statusText = '';
- this.dateRangeText = '';
- this.selectedDateRange = [];
- this.currentStatusIndex = -1;
- this.refreshList();
- },
-
- // 状态选择确认
- handleStatusConfirm(value) {
- const selected = value.value[0];
- this.queryParams.status = selected.value;
- this.statusText = selected.text;
- this.currentStatusIndex = value.index[0];
- this.showStatusPicker = false;
- },
-
- // 日期选择确认
- handleDateConfirm(value) {
- this.selectedDateRange = value;
- if (value && value.length === 2) {
- this.queryParams.beginVisitDate = value[0];
- this.queryParams.endVisitDate = value[1];
- this.dateRangeText = `${value[0]} ~ ${value[1]}`;
- } else {
- this.queryParams.beginVisitDate = '';
- this.queryParams.endVisitDate = '';
- this.dateRangeText = '';
- }
- this.showDatePicker = false;
- },
-
- // 获取状态类型
- getStatusType(status) {
- switch (status) {
- case 'planned':
- case '0':
- return 'primary';
- case 'completed':
- case '1':
- return 'success';
- case 'cancelled':
- case '2':
- return 'error';
- default:
- return 'default';
- }
- },
-
- // 查看详情
- handleView(item) {
- uni.navigateTo({
- url: `/pages/visit/detail?id=${item.visitId}`
- });
- },
-
- // 新增走访
- handleAdd() {
- uni.navigateTo({
- url: '/pages/visit/add'
- });
- },
-
- // 编辑走访
- handleEdit(item) {
- uni.navigateTo({
- url: `/pages/visit/edit?id=${item.visitId}`
- });
- },
-
- // 删除走访
- handleDelete(item) {
- uni.showModal({
- title: '确认删除',
- content: `确定要删除${item.studentName}的走访记录吗?`,
- success: async (res) => {
- if (res.confirm) {
- await this.deleteVisit(item.visitId);
- }
- }
- });
- },
-
- // 执行删除
- async deleteVisit(id) {
- try {
- uni.showLoading({ title: '删除中...' });
- const response = await delVisit(id);
-
- if (response.code === 200) {
- uni.showToast({ title: '删除成功', icon: 'success' });
- this.refreshList();
- } else {
- uni.showToast({ title: response.msg || '删除失败', icon: 'none' });
- }
- } catch (error) {
- console.error('删除走访记录失败:', error);
- uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
- } finally {
- uni.hideLoading();
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .visit-container {
- min-height: 100vh;
- background-color: #f8f8f8;
- }
- .search-bar {
- padding: 20rpx;
- background: #ffffff;
- }
- .filter-bar {
- background: #ffffff;
- padding: 0 20rpx 20rpx;
- border-bottom: 1rpx solid #ebeef5;
-
- .filter-item {
- margin-bottom: 20rpx;
- }
-
- .filter-actions {
- display: flex;
- justify-content: flex-end;
- gap: 10rpx;
- }
- }
- .action-bar {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 20rpx;
- background: #ffffff;
- border-bottom: 1rpx solid #ebeef5;
- }
- .list-container {
- padding: 20rpx;
- }
- .visit-card {
- background: #ffffff;
- border-radius: 12rpx;
- padding: 24rpx;
- margin-bottom: 20rpx;
- box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
-
- .card-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 16rpx;
-
- .student-info {
- .student-name {
- font-size: 32rpx;
- font-weight: 600;
- color: #303133;
- margin-right: 16rpx;
- }
-
- .student-no {
- font-size: 26rpx;
- color: #909399;
- }
- }
- }
-
- .card-row {
- display: flex;
- align-items: center;
- margin-bottom: 12rpx;
-
- .info-text {
- font-size: 28rpx;
- color: #606266;
- margin-left: 8rpx;
- }
-
- &:last-of-type {
- margin-bottom: 16rpx;
- }
- }
-
- .card-actions {
- display: flex;
- justify-content: flex-end;
- gap: 10rpx;
- padding-top: 16rpx;
- border-top: 1rpx solid #ebeef5;
- }
- }
- .empty-state {
- padding: 80rpx 20rpx;
- text-align: center;
- }
- .loading-state {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 40rpx;
- }
- .load-more {
- padding: 20rpx;
- }
- </style>
|